use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.
the class ServiceScopeResolver method isWithinScopeAfterLastChildNode.
/**
* Check whether the given node is within the scope and located after the last child node.
* @param node Current Node to evaluate
* @param treeVisitor Operation Tree Visitor
* @param curLine line of the cursor
* @param curCol column of the cursor
* @return {@link Boolean} whether the last child node or not
*/
protected boolean isWithinScopeAfterLastChildNode(Node node, TreeVisitor treeVisitor, int curLine, int curCol) {
BLangService bLangService = (BLangService) treeVisitor.getBlockOwnerStack().peek();
List<BLangResource> resources = bLangService.resources;
List<BLangVariableDef> variableDefs = bLangService.vars;
int serviceEndLine = bLangService.pos.getEndLine();
int serviceEndCol = bLangService.pos.getEndColumn();
int nodeEndLine = node.getPosition().getEndLine();
int nodeEndCol = node.getPosition().getEndColumn();
boolean isLastChildNode;
if (resources.isEmpty()) {
isLastChildNode = variableDefs.indexOf(node) == (variableDefs.size() - 1);
} else {
isLastChildNode = resources.indexOf(node) == (resources.size() - 1);
}
boolean isWithinScope = (isLastChildNode && (curLine < serviceEndLine || (curLine == serviceEndLine && curCol < serviceEndCol)) && (nodeEndLine < curLine || (nodeEndLine == curLine && nodeEndCol < curCol)));
if (isWithinScope) {
treeVisitor.setPreviousNode((BLangNode) node);
}
return isWithinScope;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef 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.statements.BLangVariableDef 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());
}
}
Aggregations