-
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 #474 from nipunayf/expression-editor-diagnostics
Introduce a new API to retrieve diagnostics for the inline expression editor
- Loading branch information
Showing
12 changed files
with
473 additions
and
0 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
34 changes: 34 additions & 0 deletions
34
...io/ballerina/flowmodelgenerator/extension/request/ExpressionEditorDiagnosticsRequest.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,34 @@ | ||
/* | ||
* 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 io.ballerina.tools.text.LinePosition; | ||
|
||
/** | ||
* Represents a request for diagnostics in the expression editor. | ||
* | ||
* @param filePath the path of the file | ||
* @param expression the value in the expression field | ||
* @param type the type of the expression | ||
* @param startLine the starting line position of the expression | ||
*/ | ||
public record ExpressionEditorDiagnosticsRequest(String filePath, String expression, String type, | ||
LinePosition startLine) { | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
.../ballerina/flowmodelgenerator/extension/response/ExpressionEditorDiagnosticsResponse.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,41 @@ | ||
/* | ||
* 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 org.eclipse.lsp4j.Diagnostic; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* This class represents the response containing diagnostics for the expression editor. | ||
* | ||
* @since 1.4.0 | ||
*/ | ||
public class ExpressionEditorDiagnosticsResponse extends AbstractFlowModelResponse { | ||
|
||
List<Diagnostic> diagnostics; | ||
|
||
public List<Diagnostic> diagnostics() { | ||
return diagnostics; | ||
} | ||
|
||
public void setDiagnostics(List<Diagnostic> diagnostics) { | ||
this.diagnostics = diagnostics; | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
.../test/java/io/ballerina/flowmodelgenerator/extension/ExpressionEditorDiagnosticsTest.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,94 @@ | ||
/* | ||
* 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.ExpressionEditorDiagnosticsRequest; | ||
import io.ballerina.tools.text.LinePosition; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.testng.Assert; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
/** | ||
* Tests for the expression editor diagnostics service. | ||
* | ||
* @since 1.4.0 | ||
*/ | ||
public class ExpressionEditorDiagnosticsTest extends AbstractLSTest { | ||
|
||
@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); | ||
|
||
ExpressionEditorDiagnosticsRequest request = | ||
new ExpressionEditorDiagnosticsRequest(getSourcePath(testConfig.filePath()), testConfig.expression(), | ||
testConfig.type(), testConfig.startLine()); | ||
JsonObject response = getResponse(request); | ||
|
||
List<Diagnostic> actualDiagnostics = gson.fromJson(response.get("diagnostics").getAsJsonArray(), | ||
new TypeToken<List<Diagnostic>>() { }.getType()); | ||
if (!assertArray("diagnostics", actualDiagnostics, testConfig.diagnostics())) { | ||
TestConfig updatedConfig = new TestConfig(testConfig.description(), testConfig.filePath(), | ||
testConfig.expression(), testConfig.startLine(), testConfig.type(), actualDiagnostics); | ||
updateConfig(configJsonPath, updatedConfig); | ||
Assert.fail(String.format("Failed test: '%s' (%s)", testConfig.description(), configJsonPath)); | ||
} | ||
} | ||
|
||
@DataProvider(name = "data-provider") | ||
@Override | ||
protected Object[] getConfigsList() { | ||
return new Object[]{ | ||
Path.of("single5.json") | ||
}; | ||
} | ||
|
||
@Override | ||
protected String getResourceDir() { | ||
return "diagnostics"; | ||
} | ||
|
||
@Override | ||
protected Class<? extends AbstractLSTest> clazz() { | ||
return ExpressionEditorDiagnosticsTest.class; | ||
} | ||
|
||
@Override | ||
protected String getApiName() { | ||
return "diagnostics"; | ||
} | ||
|
||
@Override | ||
protected String getServiceName() { | ||
return "expressionEditor"; | ||
} | ||
|
||
private record TestConfig(String description, String filePath, String expression, LinePosition startLine, | ||
String type, List<Diagnostic> diagnostics) { | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ules/flow-model-generator-ls-extension/src/test/resources/diagnostics/config/single1.json
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,29 @@ | ||
{ | ||
"description": "", | ||
"filePath": "source.bal", | ||
"expression": "self.classVar > localVar + 12", | ||
"startLine": { | ||
"line": 13, | ||
"offset": 8 | ||
}, | ||
"type": "boolean", | ||
"diagnostics": [ | ||
{ | ||
"range": { | ||
"start": { | ||
"line": 13, | ||
"character": 36 | ||
}, | ||
"end": { | ||
"line": 13, | ||
"character": 50 | ||
} | ||
}, | ||
"severity": "Error", | ||
"code": { | ||
"left": "BCE2070" | ||
}, | ||
"message": "operator '+' not defined for 'float' and 'int'" | ||
} | ||
] | ||
} |
Oops, something went wrong.