Skip to content

Commit

Permalink
Merge pull request #517 from nipunayf/fix-module-names
Browse files Browse the repository at this point in the history
Get module names directly from the module class rather than the semantic model
  • Loading branch information
nipunayf authored Dec 10, 2024
2 parents 717db29 + e58adbe commit 46675bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import io.ballerina.compiler.api.ModuleID;
import io.ballerina.compiler.api.SemanticModel;
import io.ballerina.compiler.api.symbols.Documentation;
import io.ballerina.compiler.api.symbols.FunctionSymbol;
import io.ballerina.compiler.api.symbols.ModuleSymbol;
Expand All @@ -36,6 +35,7 @@
import io.ballerina.flowmodelgenerator.core.model.Metadata;
import io.ballerina.flowmodelgenerator.core.model.NodeKind;
import io.ballerina.flowmodelgenerator.core.utils.CommonUtils;
import io.ballerina.projects.Module;
import io.ballerina.tools.text.LineRange;
import org.ballerinalang.langserver.common.utils.PositionUtil;

Expand All @@ -54,14 +54,14 @@
public class FunctionGenerator {

private final Gson gson;
private final SemanticModel semanticModel;
private final Module module;
private final Category.Builder rootBuilder;

private static final String INCLUDE_AVAILABLE_FUNCTIONS_FLAG = "includeAvailableFunctions";

public FunctionGenerator(SemanticModel semanticModel) {
public FunctionGenerator(Module module) {
gson = new Gson();
this.semanticModel = semanticModel;
this.module = module;
this.rootBuilder = new Category.Builder(null);
}

Expand All @@ -84,7 +84,7 @@ public JsonArray getFunctions(Map<String, String> queryMap, LineRange position)
}

private void buildProjectNodes(Map<String, String> queryMap, LineRange position) {
List<Symbol> functionSymbols = semanticModel.moduleSymbols().stream()
List<Symbol> functionSymbols = module.getCompilation().getSemanticModel().moduleSymbols().stream()
.filter(symbol -> symbol.kind().equals(SymbolKind.FUNCTION)).toList();
Category.Builder projectBuilder = rootBuilder.stepIn(Category.Name.CURRENT_INTEGRATION);

Expand Down Expand Up @@ -131,10 +131,14 @@ private void buildProjectNodes(Map<String, String> queryMap, LineRange position)

private void buildLibraryFunctions(Map<String, String> queryMap) {
// Obtain the imported module names
List<String> moduleNames = semanticModel.moduleSymbols().stream()
.filter(symbol -> symbol.kind().equals(SymbolKind.MODULE))
.flatMap(symbol -> symbol.getName().stream())
List<String> moduleNames = module.moduleDependencies().stream()
.map(moduleDependency -> moduleDependency.descriptor().name().packageName().value())
.toList();
// TODO: Use this method when https://github.com/ballerina-platform/ballerina-lang/issues/43695 is fixed
// List<String> moduleNames = semanticModel.moduleSymbols().stream()
// .filter(symbol -> symbol.kind().equals(SymbolKind.MODULE))
// .flatMap(symbol -> symbol.getName().stream())
// .toList();

// Build the imported library functions if exists
DatabaseManager dbManager = DatabaseManager.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ public CompletableFuture<FlowModelAvailableNodesResponse> getFunctions(FlowModel
try {
Path filePath = Path.of(request.filePath());
this.workspaceManager.loadProject(filePath);
Optional<SemanticModel> semanticModel = this.workspaceManager.semanticModel(filePath);
Optional<Document> document = this.workspaceManager.document(filePath);
if (semanticModel.isEmpty() || document.isEmpty()) {
Optional<Module> module = workspaceManager.module(filePath);
if (module.isEmpty() || document.isEmpty()) {
return response;
}
FunctionGenerator connectorGenerator = new FunctionGenerator(semanticModel.get());
FunctionGenerator connectorGenerator = new FunctionGenerator(module.get());
response.setCategories(connectorGenerator.getFunctions(request.queryMap(), request.position()));
} catch (Throwable e) {
response.setError(e);
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
org.gradle.caching=true
group=org.ballerinalang
version=2.1.0-SNAPSHOT
ballerinaLangVersion=2201.11.0-20241128-181300-fcbcfda6
version=2.0.0-SNAPSHOT
ballerinaLangVersion=2201.11.0-20241204-102100-fc33b755

ballerinaGradlePluginVersion=2.2.6
checkStyleToolVersion=10.12.1
Expand Down

0 comments on commit 46675bc

Please sign in to comment.