use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class CallableUnitBodyItemSorter method sortItems.
@Override
public void sortItems(TextDocumentServiceContext ctx, List<CompletionItem> completionItems) {
BLangNode previousNode = ctx.get(CompletionKeys.PREVIOUS_NODE_KEY);
TokenStream tokenStream = ctx.get(DocumentServiceKeys.TOKEN_STREAM_KEY);
if (ctx.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY) != null) {
int currentTokenStart = ctx.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY).getStart().getTokenIndex();
Token nextToken = tokenStream.get(currentTokenStart + 1);
int cursorLine = ctx.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
int cursorChar = ctx.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
if (nextToken.getChannel() != Token.DEFAULT_CHANNEL && (cursorLine > nextToken.getLine() - 1 || (cursorLine == nextToken.getLine() - 1 && cursorChar > nextToken.getCharPositionInLine()))) {
completionItems.clear();
return;
}
}
this.clearItemsIfWorkerExists(ctx, completionItems);
if (previousNode == null) {
this.populateWhenCursorBeforeOrAfterEp(completionItems);
} else if (previousNode instanceof BLangVariableDef) {
// } else
if (ctx.get(CompletionKeys.INVOCATION_STATEMENT_KEY) == null || !ctx.get(CompletionKeys.INVOCATION_STATEMENT_KEY)) {
CompletionItem workerItem = this.getWorkerSnippet();
workerItem.setSortText(Priority.PRIORITY160.toString());
completionItems.add(workerItem);
}
} else if (previousNode instanceof BLangWorker) {
completionItems.add(this.getWorkerSnippet());
}
this.setPriorities(completionItems);
}
use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class ConnectorContextItemSorter method sortItems.
@Override
public void sortItems(TextDocumentServiceContext ctx, List<CompletionItem> completionItems) {
BLangNode previousNode = ctx.get(CompletionKeys.PREVIOUS_NODE_KEY);
/*
Remove the statement type completion type. When the going through the parser
rule contexts such as typeNameContext, we add the statements as well.
Sorters are responsible for to the next level of such filtering.
*/
this.removeCompletionsByType(new ArrayList<>(Collections.singletonList(ItemResolverConstants.STATEMENT_TYPE)), completionItems);
if (previousNode == null) {
this.populateWhenCursorBeforeOrAfterEp(completionItems);
} else if (previousNode instanceof BLangVariableDef) {
// BType bLangType = ((BLangVariableDef) previousNode).var.type;
// if (bLangType instanceof BEndpointType) {
// this.populateWhenCursorBeforeOrAfterEp(completionItems);
// } else {
this.setPriorities(completionItems);
CompletionItem resItem = this.getActionSnippet();
resItem.setSortText(Priority.PRIORITY160.toString());
completionItems.add(resItem);
// }
} else if (previousNode instanceof BLangAction) {
completionItems.clear();
completionItems.add(this.getActionSnippet());
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class SignatureTreeVisitor method acceptNode.
// Private Methods
private void acceptNode(BLangNode node, SymbolEnv env) {
if (this.terminateVisitor) {
return;
}
SymbolEnv prevEnv = this.symbolEnv;
this.symbolEnv = env;
node.accept(this);
this.symbolEnv = prevEnv;
}
use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class SignatureTreeVisitor method visit.
@Override
public void visit(BLangPackage pkgNode) {
SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
// Then visit each top-level element sorted using the compilation unit
String fileName = documentServiceContext.get(DocumentServiceKeys.FILE_NAME_KEY);
BLangCompilationUnit compilationUnit = pkgNode.getCompilationUnits().stream().filter(bLangCompilationUnit -> bLangCompilationUnit.getName().equals(fileName)).findFirst().orElse(null);
List<TopLevelNode> topLevelNodes = compilationUnit.getTopLevelNodes();
if (!topLevelNodes.isEmpty()) {
topLevelNodes.forEach(topLevelNode -> acceptNode((BLangNode) topLevelNode, pkgEnv));
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class CompletionTestUtil method getCompletions.
/**
* Get the completions list.
*
* @param documentManager Document manager instance
* @param pos {@link TextDocumentPositionParams} position params
*/
public static List<CompletionItem> getCompletions(WorkspaceDocumentManagerImpl documentManager, TextDocumentPositionParams pos) {
List<CompletionItem> completions;
TextDocumentServiceContext completionContext = new TextDocumentServiceContext();
completionContext.put(DocumentServiceKeys.POSITION_KEY, pos);
completionContext.put(DocumentServiceKeys.FILE_URI_KEY, pos.getTextDocument().getUri());
BLangPackage bLangPackage = TextDocumentServiceUtil.getBLangPackage(completionContext, documentManager, false, CompletionCustomErrorStrategy.class, false).get(0);
completionContext.put(DocumentServiceKeys.CURRENT_PACKAGE_NAME_KEY, bLangPackage.symbol.getName().getValue());
// Visit the package to resolve the symbols
TreeVisitor treeVisitor = new TreeVisitor(completionContext);
bLangPackage.accept(treeVisitor);
BLangNode symbolEnvNode = completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY);
if (symbolEnvNode == null) {
completions = CompletionItemResolver.getResolverByClass(TopLevelResolver.class).resolveItems(completionContext);
} else {
completions = CompletionItemResolver.getResolverByClass(symbolEnvNode.getClass()).resolveItems(completionContext);
}
return completions;
}
Aggregations