use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.
the class GlobalScopeResolver method resolveItems.
@Override
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
ArrayList<CompletionItem> completionItems = new ArrayList<>();
ParserRuleContext parserRuleContext = completionContext.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY);
if (parserRuleContext == null) {
// If the parser rule context is null we don't have any errors. In this case we add the types
List<SymbolInfo> bTypeSymbolInfo = completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY).stream().filter(symbolInfo -> symbolInfo.getScopeEntry().symbol.type != null).collect(Collectors.toList());
this.populateCompletionItemList(bTypeSymbolInfo, completionItems);
} else {
return CompletionItemResolver.getResolverByClass(parserRuleContext.getClass()).resolveItems(completionContext);
}
return completionItems;
}
use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.
the class SignatureTreeVisitor method populateSymbols.
/**
* Populate the symbols.
* @param symbolEntries symbol entries
*/
private void populateSymbols(Map<Name, Scope.ScopeEntry> symbolEntries) {
// TODO: Populate only the visible functions
this.terminateVisitor = true;
String identifierAgainst = documentServiceContext.get(SignatureKeys.IDENTIFIER_AGAINST);
List<SymbolInfo> visibleSymbols = new ArrayList<>();
/*
During the first iteration we filter out the functions and if there is, the variable reference against which
the function is called.
*/
symbolEntries.forEach((k, v) -> {
if (v.symbol instanceof BInvokableSymbol && !(v.symbol instanceof BOperatorSymbol) && !v.symbol.getName().getValue().contains("<init>")) {
SymbolInfo symbolInfo = new SymbolInfo(k.getValue(), v);
visibleSymbols.add(symbolInfo);
} else if (v.symbol instanceof BVarSymbol && k.getValue().equals(identifierAgainst)) {
documentServiceContext.put(SignatureKeys.IDENTIFIER_TYPE, v.symbol.type.toString());
} else if (v.symbol instanceof BPackageSymbol && k.getValue().equals(identifierAgainst)) {
documentServiceContext.put(SignatureKeys.IDENTIFIER_PKGID, v.symbol.pkgID.toString());
documentServiceContext.put(SignatureKeys.IDENTIFIER_TYPE, v.symbol.type.toString());
visibleSymbols.addAll(this.getInvokableSymbolsInPackage((BPackageSymbol) v.symbol));
}
});
/*
In this iteration we filter out the functions either having a receiver or otherwise.
If the identifier against value is a valid value, then check whether the receiver type equals to identifier
type. If there is no identifier, filter out functions without the receiver
*/
List<SymbolInfo> filteredSymbols = new ArrayList<>();
visibleSymbols.forEach(symbolInfo -> {
BVarSymbol receiver = ((BInvokableSymbol) symbolInfo.getScopeEntry().symbol).receiverSymbol;
String[] nameTokens = symbolInfo.getSymbolName().split("\\.");
String funcNameFromSymbol = nameTokens[nameTokens.length - 1];
String functionName = documentServiceContext.get(SignatureKeys.CALLABLE_ITEM_NAME);
String identifierPkgName = documentServiceContext.get(SignatureKeys.IDENTIFIER_PKGID);
boolean onIdentifierTypePkg = "package".equals(documentServiceContext.get(SignatureKeys.IDENTIFIER_TYPE)) && symbolInfo.getScopeEntry().symbol.pkgID.toString().equals(identifierPkgName);
boolean onReceiverTypeMatchIdentifier = receiver != null && receiver.type.toString().equals(documentServiceContext.get(SignatureKeys.IDENTIFIER_TYPE));
boolean onIdentifierAgainstNull = (receiver == null && (identifierAgainst == null || identifierAgainst.equals("")));
if ((onIdentifierTypePkg || onReceiverTypeMatchIdentifier || onIdentifierAgainstNull) && funcNameFromSymbol.equals(functionName)) {
filteredSymbols.add(symbolInfo);
}
});
documentServiceContext.put(SignatureKeys.FILTERED_FUNCTIONS, filteredSymbols);
}
Aggregations