-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #480 from dulajdilshan/revamp-delete-api
Add LS API support for component deletion
- Loading branch information
Showing
20 changed files
with
674 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...c/main/java/io/ballerina/flowmodelgenerator/extension/request/ComponentDeleteRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.ballerina.flowmodelgenerator.extension.request; | ||
|
||
import com.google.gson.JsonElement; | ||
|
||
/** | ||
* Represents a request to delete a component. | ||
* | ||
* @param filePath file path of the source file | ||
* @param component component to delete | ||
* @since 1.4.0 | ||
*/ | ||
public record ComponentDeleteRequest(String filePath, JsonElement component) { | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...main/java/io/ballerina/flowmodelgenerator/extension/response/ComponentDeleteResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.ballerina.flowmodelgenerator.extension.response; | ||
|
||
import com.google.gson.JsonElement; | ||
|
||
/** | ||
* Represents the response for the deleteComponent API. | ||
* | ||
* @since 1.4.0 | ||
*/ | ||
public class ComponentDeleteResponse extends AbstractFlowModelResponse { | ||
|
||
private JsonElement textEdits; | ||
|
||
public void setTextEdits(JsonElement textEdits) { | ||
this.textEdits = textEdits; | ||
} | ||
|
||
public JsonElement textEdits() { | ||
return textEdits; | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
...xtension/src/test/java/io/ballerina/flowmodelgenerator/extension/DeleteComponentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.ballerina.flowmodelgenerator.extension; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.reflect.TypeToken; | ||
import io.ballerina.flowmodelgenerator.extension.request.ComponentDeleteRequest; | ||
import org.eclipse.lsp4j.TextEdit; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.Type; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Tests for the flow model source generator service. | ||
* | ||
* @since 1.4.0 | ||
*/ | ||
public class DeleteComponentTest extends AbstractLSTest { | ||
|
||
private static final Type textEditListType = new TypeToken<Map<String, List<TextEdit>>>() { | ||
}.getType(); | ||
|
||
@Override | ||
@Test(dataProvider = "data-provider") | ||
public void test(Path config) throws IOException { | ||
Path configJsonPath = configDir.resolve(config); | ||
TestConfig testConfig = gson.fromJson(Files.newBufferedReader(configJsonPath), TestConfig.class); | ||
|
||
String sourcePath = getSourcePath(testConfig.filePath()); | ||
ComponentDeleteRequest deleteRequest = new ComponentDeleteRequest(sourcePath, gson.toJsonTree(testConfig)); | ||
|
||
JsonObject deleteResponse = getResponse(deleteRequest).getAsJsonObject("textEdits"); | ||
Map<String, List<TextEdit>> actualTextEdits = gson.fromJson(deleteResponse, textEditListType); | ||
|
||
assertTextEdits(actualTextEdits, testConfig, configJsonPath); | ||
} | ||
|
||
private void assertTextEdits(Map<String, List<TextEdit>> actualTextEdits, | ||
TestConfig testConfig, Path configJsonPath) throws IOException { | ||
boolean assertFailure = false; | ||
Map<String, List<TextEdit>> newMap = new HashMap<>(); | ||
for (Map.Entry<String, List<TextEdit>> entry : actualTextEdits.entrySet()) { | ||
Path fullPath = Paths.get(entry.getKey()); | ||
String relativePath = sourceDir.relativize(fullPath).toString(); | ||
|
||
List<TextEdit> textEdits = testConfig.output().get(relativePath.replace("\\", "/")); | ||
if (textEdits == null) { | ||
log.info("No text edits found for the file: " + relativePath); | ||
assertFailure = true; | ||
} else if (!assertArray("text edits", entry.getValue(), textEdits)) { | ||
assertFailure = true; | ||
} | ||
|
||
newMap.put(relativePath, entry.getValue()); | ||
} | ||
|
||
if (assertFailure) { | ||
TestConfig updatedConfig = | ||
new TestConfig(testConfig.description(), testConfig.filePath(), testConfig.startLine(), | ||
testConfig.startColumn(), testConfig.endLine(), testConfig.endColumn(), newMap); | ||
// updateConfig(configJsonPath, updatedConfig); | ||
Assert.fail(String.format("Failed test: '%s' (%s)", testConfig.description(), configJsonPath)); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
protected String getResourceDir() { | ||
return "delete_component"; | ||
} | ||
|
||
@Override | ||
protected Class<? extends AbstractLSTest> clazz() { | ||
return DeleteComponentTest.class; | ||
} | ||
|
||
@Override | ||
protected String getApiName() { | ||
return "deleteComponent"; | ||
} | ||
|
||
/** | ||
* Represents the test configuration for the delete node test. | ||
* | ||
* @param description The description of the test. | ||
* @param filePath The path to the source file that contains the nodes to be deleted. | ||
* @param startLine The starting line number of the node to be deleted. | ||
* @param startColumn The starting column position of the node to be deleted. | ||
* @param endLine The ending line number of the node to be deleted. | ||
* @param endColumn The ending column position of the node to be deleted. | ||
* @param output The expected output. | ||
*/ | ||
private record TestConfig(String description, String filePath, | ||
int startLine, int startColumn, int endLine, int endColumn, | ||
Map<String, List<TextEdit>> output) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.