use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.
the class PackageActionFunctionAndTypesFilter method fillMapIterableOperation.
private void fillMapIterableOperation(BType bType, List<SymbolInfo> symbolInfoList) {
String params = getIterableOpLambdaParam(bType);
String lambdaSignature = Snippet.ITR_MAP.toString().replace(UtilSymbolKeys.ITR_OP_LAMBDA_PARAM_REPLACE_TOKEN, params);
SymbolInfo.IterableOperationSignature signature = new SymbolInfo.IterableOperationSignature(ItemResolverConstants.ITR_MAP_LABEL, lambdaSignature);
SymbolInfo forEachSymbolInfo = new SymbolInfo();
forEachSymbolInfo.setIterableOperation(true);
forEachSymbolInfo.setIterableOperationSignature(signature);
symbolInfoList.add(forEachSymbolInfo);
}
use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.
the class PackageActionFunctionAndTypesFilter method fillForeachIterableOperation.
private void fillForeachIterableOperation(BType bType, List<SymbolInfo> symbolInfoList) {
String params = getIterableOpLambdaParam(bType);
String lambdaSignature = Snippet.ITR_FOREACH.toString().replace(UtilSymbolKeys.ITR_OP_LAMBDA_PARAM_REPLACE_TOKEN, params);
SymbolInfo.IterableOperationSignature signature = new SymbolInfo.IterableOperationSignature(ItemResolverConstants.ITR_FOREACH_LABEL, lambdaSignature);
SymbolInfo forEachSymbolInfo = new SymbolInfo();
forEachSymbolInfo.setIterableOperation(true);
forEachSymbolInfo.setIterableOperationSignature(signature);
symbolInfoList.add(forEachSymbolInfo);
}
use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.
the class PackageActionFunctionAndTypesFilter method fillAverageIterableOperation.
private void fillAverageIterableOperation(List<SymbolInfo> symbolInfoList) {
String lambdaSignature = Snippet.ITR_AVERAGE.toString();
SymbolInfo.IterableOperationSignature signature = new SymbolInfo.IterableOperationSignature(ItemResolverConstants.ITR_AVERAGE_LABEL, lambdaSignature);
SymbolInfo forEachSymbolInfo = new SymbolInfo();
forEachSymbolInfo.setIterableOperation(true);
forEachSymbolInfo.setIterableOperationSignature(signature);
symbolInfoList.add(forEachSymbolInfo);
}
use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.
the class BLangMatchContextResolver method resolveItems.
@Override
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
ArrayList<CompletionItem> completionItems = new ArrayList<>();
BLangNode symbolEnvNode = completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY);
List<SymbolInfo> visibleSymbols = completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY);
if (!(symbolEnvNode instanceof BLangMatch)) {
return completionItems;
}
BLangMatch bLangMatch = (BLangMatch) symbolEnvNode;
if (bLangMatch.expr.type instanceof BUnionType) {
Set<BType> memberTypes = ((BUnionType) ((BLangSimpleVarRef) bLangMatch.expr).type).getMemberTypes();
memberTypes.forEach(bType -> {
completionItems.add(this.populateCompletionItem(bType.toString(), ItemResolverConstants.B_TYPE, bType.toString()));
});
} else if (bLangMatch.expr.type instanceof BJSONType) {
ArrayList<Integer> typeTagsList = new ArrayList<>(Arrays.asList(TypeTags.INT, TypeTags.FLOAT, TypeTags.BOOLEAN, TypeTags.STRING, TypeTags.NULL, TypeTags.JSON));
List<SymbolInfo> filteredBasicTypes = visibleSymbols.stream().filter(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
return bSymbol instanceof BTypeSymbol && typeTagsList.contains(bSymbol.getType().tag);
}).collect(Collectors.toList());
this.populateCompletionItemList(filteredBasicTypes, completionItems);
} else {
if (bLangMatch.expr.type instanceof BStructType) {
List<SymbolInfo> structSymbols = visibleSymbols.stream().filter(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
return bSymbol instanceof BStructSymbol && !bSymbol.getName().getValue().startsWith(UtilSymbolKeys.ANON_STRUCT_CHECKER);
}).collect(Collectors.toList());
this.populateCompletionItemList(structSymbols, completionItems);
}
}
return completionItems;
}
use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.
the class ParserRuleStatementContextResolver method resolveItems.
@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
ArrayList<CompletionItem> completionItems = new ArrayList<>();
ArrayList<SymbolInfo> filteredSymbols = new ArrayList<>();
if (isInvocationOrFieldAccess(completionContext)) {
filteredSymbols.addAll(SymbolFilters.getFilterByClass(PackageActionFunctionAndTypesFilter.class).filterItems(completionContext));
} else {
filteredSymbols.addAll(SymbolFilters.getFilterByClass(ConnectorInitExpressionItemFilter.class).filterItems(completionContext));
filteredSymbols.addAll(completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY));
completionItems.addAll(SymbolFilters.getFilterByClass(StatementTemplateFilter.class).filterItems(completionContext));
CompletionItem xmlns = new CompletionItem();
xmlns.setLabel(ItemResolverConstants.XMLNS);
xmlns.setInsertText(Snippet.NAMESPACE_DECLARATION.toString());
xmlns.setInsertTextFormat(InsertTextFormat.Snippet);
xmlns.setDetail(ItemResolverConstants.SNIPPET_TYPE);
completionItems.add(xmlns);
CompletionItem varKeyword = new CompletionItem();
varKeyword.setInsertText(Snippet.VAR_KEYWORD_SNIPPET.toString());
varKeyword.setLabel(ItemResolverConstants.VAR_KEYWORD);
varKeyword.setDetail(ItemResolverConstants.KEYWORD_TYPE);
completionItems.add(varKeyword);
}
this.populateCompletionItemList(filteredSymbols, completionItems);
// Now we need to sort the completion items and populate the completion items specific to the scope owner
// as an example, resource, action, function scopes are different from the if-else, while, and etc
Class itemSorter = completionContext.get(CompletionKeys.BLOCK_OWNER_KEY).getClass();
ItemSorters.getSorterByClass(itemSorter).sortItems(completionContext, completionItems);
return completionItems;
}
Aggregations