Search in sources :

Example 1 with SymbolInfo

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);
}
Also used : SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Example 2 with SymbolInfo

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);
}
Also used : SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Example 3 with SymbolInfo

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);
}
Also used : SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Example 4 with SymbolInfo

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;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BJSONType(org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType) ArrayList(java.util.ArrayList) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) CompletionItem(org.eclipse.lsp4j.CompletionItem) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with SymbolInfo

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;
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem) ArrayList(java.util.ArrayList) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Aggregations

SymbolInfo (org.ballerinalang.langserver.completions.SymbolInfo)22 ArrayList (java.util.ArrayList)12 CompletionItem (org.eclipse.lsp4j.CompletionItem)7 List (java.util.List)6 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)6 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)6 TokenStream (org.antlr.v4.runtime.TokenStream)5 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)5 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)5 Collectors (java.util.stream.Collectors)4 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)4 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)4 CompletionKeys (org.ballerinalang.langserver.completions.CompletionKeys)4 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)4 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)4 Token (org.antlr.v4.runtime.Token)3 ItemResolverConstants (org.ballerinalang.langserver.completions.util.ItemResolverConstants)3 PackageActionFunctionAndTypesFilter (org.ballerinalang.langserver.completions.util.filters.PackageActionFunctionAndTypesFilter)3 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)3 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)3