Skip to content

Commit

Permalink
Merge pull request #476 from nipunayf/fix-types-api
Browse files Browse the repository at this point in the history
Retrieve types for a project path
  • Loading branch information
hasithaa authored Nov 7, 2024
2 parents 9acdcf7 + 8765ed5 commit af711b3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.ballerina.flowmodelgenerator.extension.response.VisibleVariableTypesResponse;
import io.ballerina.projects.Document;
import io.ballerina.projects.Module;
import io.ballerina.projects.Project;
import io.ballerina.tools.text.LinePosition;
import io.ballerina.tools.text.LineRange;
import io.ballerina.tools.text.TextDocument;
Expand Down Expand Up @@ -111,13 +112,11 @@ public CompletableFuture<ExpressionEditorTypeResponse> types(VisibleVariableType
ExpressionEditorTypeResponse response = new ExpressionEditorTypeResponse();
try {
Path filePath = Path.of(request.filePath());
this.workspaceManager.loadProject(filePath);
Optional<SemanticModel> semanticModel = this.workspaceManager.semanticModel(filePath);
if (semanticModel.isEmpty()) {
return response;
}
Project project = this.workspaceManager.loadProject(filePath);
SemanticModel semanticModel = this.workspaceManager.semanticModel(filePath).orElseGet(
() -> project.currentPackage().getDefaultModule().getCompilation().getSemanticModel());

TypesGenerator typesGenerator = new TypesGenerator(semanticModel.get());
TypesGenerator typesGenerator = new TypesGenerator(semanticModel);
response.setTypes(typesGenerator.getTypes());
} catch (Throwable e) {
response.setError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void test(Path config) throws IOException {
Path configJsonPath = configDir.resolve(config);
TestConfig testConfig = gson.fromJson(Files.newBufferedReader(configJsonPath), TestConfig.class);

VisibleVariableTypeRequest request = new VisibleVariableTypeRequest(
sourceDir.resolve(testConfig.source()).toAbsolutePath().toString(), testConfig.position());
VisibleVariableTypeRequest request =
new VisibleVariableTypeRequest(getSourcePath(testConfig.source()), testConfig.position());
JsonObject response = getResponse(request);

JsonArray actualExpressionTypes = response.get("types").getAsJsonArray();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"description": "",
"source": "data_mapper",
"types": [
"Input",
"Output",
"Location",
"Address",
"Employee",
"Person",
"Admission",
"int",
"string",
"float",
"boolean",
"decimal",
"xml",
"error",
"function",
"future",
"typedesc",
"handle",
"stream",
"any",
"anydata",
"stream",
"never",
"readonly",
"json",
"byte"
]
}

0 comments on commit af711b3

Please sign in to comment.