Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ class FunctionSearchCommand extends SearchCommand {
private static final String FETCH_KEY = "functions";
private final List<String> moduleNames;
private final Document functionsDoc;
private final Document dataMappingsDoc;

public FunctionSearchCommand(Project project, LineRange position, Map<String, String> queryMap,
Document functionsDoc) {
Document functionsDoc, Document dataMappingsDoc) {
super(project, position, queryMap);

// Obtain the imported module names
Expand All @@ -98,6 +99,7 @@ public FunctionSearchCommand(Project project, LineRange position, Map<String, St
.map(moduleDependency -> moduleDependency.descriptor().name().packageName().value())
.toList();
this.functionsDoc = functionsDoc;
this.dataMappingsDoc = dataMappingsDoc;
// 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))
Expand Down Expand Up @@ -195,17 +197,26 @@ private void buildProjectNodes() {
List<Item> availableTools = new ArrayList<>();
for (Symbol symbol : functionSymbols) {
FunctionSymbol functionSymbol = (FunctionSymbol) symbol;
// Skip NP functions from functions.bal
if (functionsDoc != null
&& CommonUtils.isNaturalExpressionBodiedFunction(functionsDoc.syntaxTree(), functionSymbol)) {
// Skip NP functions
continue;
}
// Skip NP functions from data_mappings.bal
if (dataMappingsDoc != null
&& CommonUtils.isNaturalExpressionBodiedFunction(dataMappingsDoc.syntaxTree(), functionSymbol)) {
continue;
}

boolean isDataMappedFunction = false;
Optional<Location> location = symbol.getLocation();
if (location.isPresent()) {
isDataMappedFunction = location.get().lineRange().fileName().equals(DATA_MAPPER_FILE_NAME);
LineRange fnLineRange = location.get().lineRange();
// Check if function is in data_mappings.bal and is a data mapping function
if (fnLineRange.fileName().equals(DATA_MAPPER_FILE_NAME) && dataMappingsDoc != null) {
isDataMappedFunction = CommonUtils.isDataMappingFunction(
dataMappingsDoc.syntaxTree(), functionSymbol);
}
if (fnLineRange.fileName().equals(position.fileName()) &&
PositionUtil.isWithinLineRange(fnLineRange, position)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ public abstract class SearchCommand {

public static SearchCommand from(Kind kind, Project module, LineRange position, Map<String, String> queryMap,
Document functionsDoc) {
return from(kind, module, position, queryMap, functionsDoc, null);
}

public static SearchCommand from(Kind kind, Project module, LineRange position, Map<String, String> queryMap,
Document functionsDoc, Document dataMappingsDoc) {
return switch (kind) {
case FUNCTION -> new FunctionSearchCommand(module, position, queryMap, functionsDoc);
case FUNCTION -> new FunctionSearchCommand(module, position, queryMap, functionsDoc, dataMappingsDoc);
case CONNECTOR -> new ConnectorSearchCommand(module, position, queryMap);
case NP_FUNCTION -> new NPFunctionSearchCommand(module, position, queryMap, functionsDoc);
case TYPE -> new TypeSearchCommand(module, position, queryMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,10 @@ public CompletableFuture<FlowModelAvailableNodesResponse> search(SearchRequest r

Path projectPath = workspaceManager.projectRoot(filePath);
Optional<Document> functionsDoc = getDocumentFromFile(projectPath, "functions.bal");
Optional<Document> dataMappingsDoc = getDocumentFromFile(projectPath, "data_mappings.bal");

SearchCommand command = SearchCommand.from(searchKind, project, position, request.queryMap(),
functionsDoc.orElse(null));
functionsDoc.orElse(null), dataMappingsDoc.orElse(null));
response.setCategories(command.execute());
} catch (Throwable e) {
response.setError(e);
Expand Down
Loading
Loading