Search in sources :

Example 1 with BLangNode

use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.

the class BallerinaTextDocumentService method completion.

@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(TextDocumentPositionParams position) {
    return CompletableFuture.supplyAsync(() -> {
        List<CompletionItem> completions;
        TextDocumentServiceContext completionContext = new TextDocumentServiceContext();
        completionContext.put(DocumentServiceKeys.POSITION_KEY, position);
        completionContext.put(DocumentServiceKeys.FILE_URI_KEY, position.getTextDocument().getUri());
        completionContext.put(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY, lSPackageCache);
        try {
            BLangPackage bLangPackage = TextDocumentServiceUtil.getBLangPackage(completionContext, documentManager, false, CompletionCustomErrorStrategy.class, false).get(0);
            completionContext.put(DocumentServiceKeys.CURRENT_PACKAGE_NAME_KEY, bLangPackage.symbol.getName().getValue());
            completionContext.put(DocumentServiceKeys.CURRENT_BLANG_PACKAGE_CONTEXT_KEY, bLangPackage);
            // 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);
            }
        } catch (Exception | AssertionError e) {
            completions = new ArrayList<>();
        }
        return Either.forLeft(completions);
    });
}
Also used : TreeVisitor(org.ballerinalang.langserver.completions.TreeVisitor) SignatureTreeVisitor(org.ballerinalang.langserver.signature.SignatureTreeVisitor) PositionTreeVisitor(org.ballerinalang.langserver.common.position.PositionTreeVisitor) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) CompletionCustomErrorStrategy(org.ballerinalang.langserver.completions.CompletionCustomErrorStrategy) CompletionItem(org.eclipse.lsp4j.CompletionItem) ArrayList(java.util.ArrayList)

Example 2 with BLangNode

use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.

the class TaintAnalyzer method analyzeNode.

// Private
private <T extends BLangNode, U extends SymbolEnv> void analyzeNode(T t, U u) {
    SymbolEnv prevEnv = this.env;
    this.env = u;
    t.accept(this);
    this.env = prevEnv;
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 3 with BLangNode

use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.

the class CodeAnalyzer method analyzeNode.

private void analyzeNode(BLangNode node, SymbolEnv env) {
    SymbolEnv prevEnv = this.env;
    this.env = env;
    node.accept(this);
    this.env = prevEnv;
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 4 with BLangNode

use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.

the class SemanticAnalyzer method analyzeNode.

BType analyzeNode(BLangNode node, SymbolEnv env, BType expType, DiagnosticCode diagCode) {
    SymbolEnv prevEnv = this.env;
    BType preExpType = this.expType;
    DiagnosticCode preDiagCode = this.diagCode;
    // TODO Check the possibility of using a try/finally here
    this.env = env;
    this.expType = expType;
    this.diagCode = diagCode;
    node.accept(this);
    this.env = prevEnv;
    this.expType = preExpType;
    this.diagCode = preDiagCode;
    return resType;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode)

Example 5 with BLangNode

use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

// Visitor methods
public void visit(BLangPackage pkgNode) {
    if (pkgNode.completedPhases.contains(CompilerPhase.TYPE_CHECK)) {
        return;
    }
    SymbolEnv pkgEnv = this.symTable.pkgEnvMap.get(pkgNode.symbol);
    // Visit all the imported packages
    pkgNode.imports.forEach(importNode -> analyzeDef(importNode, pkgEnv));
    // Then visit each top-level element sorted using the compilation unit
    pkgNode.topLevelNodes.forEach(topLevelNode -> analyzeDef((BLangNode) topLevelNode, pkgEnv));
    analyzeDef(pkgNode.initFunction, pkgEnv);
    analyzeDef(pkgNode.startFunction, pkgEnv);
    analyzeDef(pkgNode.stopFunction, pkgEnv);
    pkgNode.completedPhases.add(CompilerPhase.TYPE_CHECK);
}
Also used : BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Aggregations

BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)17 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)13 ArrayList (java.util.ArrayList)7 CompletionItem (org.eclipse.lsp4j.CompletionItem)7 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)7 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)5 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)5 List (java.util.List)4 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)4 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)3 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)3 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)3 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)3 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Stack (java.util.Stack)2 Collectors (java.util.stream.Collectors)2 Token (org.antlr.v4.runtime.Token)2 TokenStream (org.antlr.v4.runtime.TokenStream)2