Search in sources :

Example 16 with SymbolInfo

use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.

the class PackageActionFunctionAndTypesFilter method fillSumIterableOperation.

private void fillSumIterableOperation(List<SymbolInfo> symbolInfoList) {
    String lambdaSignature = Snippet.ITR_SUM.toString();
    SymbolInfo.IterableOperationSignature signature = new SymbolInfo.IterableOperationSignature(ItemResolverConstants.ITR_SUM_LABEL, lambdaSignature);
    SymbolInfo forEachSymbolInfo = new SymbolInfo();
    forEachSymbolInfo.setIterableOperation(true);
    forEachSymbolInfo.setIterableOperationSignature(signature);
    symbolInfoList.add(forEachSymbolInfo);
}
Also used : SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Example 17 with SymbolInfo

use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.

the class PackageActionFunctionAndTypesFilter method fillFilterIterableOperation.

private void fillFilterIterableOperation(BType bType, List<SymbolInfo> symbolInfoList) {
    String params = getIterableOpLambdaParam(bType);
    String lambdaSignature = Snippet.ITR_FILTER.toString().replace(UtilSymbolKeys.ITR_OP_LAMBDA_PARAM_REPLACE_TOKEN, params);
    SymbolInfo.IterableOperationSignature signature = new SymbolInfo.IterableOperationSignature(ItemResolverConstants.ITR_FILTER_LABEL, lambdaSignature);
    SymbolInfo forEachSymbolInfo = new SymbolInfo();
    forEachSymbolInfo.setIterableOperation(true);
    forEachSymbolInfo.setIterableOperationSignature(signature);
    symbolInfoList.add(forEachSymbolInfo);
}
Also used : SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Example 18 with SymbolInfo

use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.

the class ParserRuleMatchStatementContextResolver method resolveItems.

@Override
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
    ArrayList<CompletionItem> completionItems = new ArrayList<>();
    int currentTokenIndex = completionContext.get(DocumentServiceKeys.TOKEN_INDEX_KEY);
    List<SymbolInfo> visibleSymbols = completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY);
    TokenStream tokenStream = completionContext.get(DocumentServiceKeys.TOKEN_STREAM_KEY);
    while (true) {
        if (currentTokenIndex < 0) {
            // Ideally should not come to this point
            return completionItems;
        }
        Token token = CommonUtil.getPreviousDefaultToken(tokenStream, currentTokenIndex);
        if (token.getText().equals(UtilSymbolKeys.MATCH_KEYWORD_KEY)) {
            currentTokenIndex = token.getTokenIndex();
            break;
        } else {
            currentTokenIndex = token.getTokenIndex();
        }
    }
    String identifierMatched = CommonUtil.getNextDefaultToken(tokenStream, currentTokenIndex).getText();
    SymbolInfo identifierSymbol = visibleSymbols.stream().filter(symbolInfo -> symbolInfo.getScopeEntry().symbol.getName().getValue().equals(identifierMatched)).findFirst().orElseGet(null);
    if (identifierSymbol == null) {
        return completionItems;
    } else if (identifierSymbol.getScopeEntry().symbol.type instanceof BUnionType) {
        Set<BType> memberTypes = ((BUnionType) identifierSymbol.getScopeEntry().symbol.type).getMemberTypes();
        memberTypes.forEach(bType -> {
            completionItems.add(this.populateCompletionItem(bType.toString(), ItemResolverConstants.B_TYPE, bType.toString()));
        });
    } else if (identifierSymbol.getScopeEntry().symbol.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 (identifierSymbol.getScopeEntry().symbol.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 : CommonUtil(org.ballerinalang.langserver.common.utils.CommonUtil) Arrays(java.util.Arrays) TextDocumentServiceContext(org.ballerinalang.langserver.TextDocumentServiceContext) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) TokenStream(org.antlr.v4.runtime.TokenStream) Token(org.antlr.v4.runtime.Token) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BJSONType(org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType) Set(java.util.Set) ItemResolverConstants(org.ballerinalang.langserver.completions.util.ItemResolverConstants) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CompletionItem(org.eclipse.lsp4j.CompletionItem) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) List(java.util.List) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) UtilSymbolKeys(org.ballerinalang.langserver.common.UtilSymbolKeys) CompletionKeys(org.ballerinalang.langserver.completions.CompletionKeys) AbstractItemResolver(org.ballerinalang.langserver.completions.resolvers.AbstractItemResolver) DocumentServiceKeys(org.ballerinalang.langserver.DocumentServiceKeys) TokenStream(org.antlr.v4.runtime.TokenStream) Set(java.util.Set) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BJSONType(org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType) ArrayList(java.util.ArrayList) Token(org.antlr.v4.runtime.Token) 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) CompletionItem(org.eclipse.lsp4j.CompletionItem) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with SymbolInfo

use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.

the class ParserRuleTypeNameContextResolver method filterEndpointContextSymbolInfo.

private static List<SymbolInfo> filterEndpointContextSymbolInfo(TextDocumentServiceContext context) {
    List<SymbolInfo> symbolInfos = context.get(CompletionKeys.VISIBLE_SYMBOLS_KEY);
    int currentTokenIndex = context.get(DocumentServiceKeys.TOKEN_INDEX_KEY) - 1;
    TokenStream tokenStream = context.get(DocumentServiceKeys.TOKEN_STREAM_KEY);
    Token packageAlias = CommonUtil.getPreviousDefaultToken(tokenStream, currentTokenIndex);
    Token constraintStart = CommonUtil.getPreviousDefaultToken(tokenStream, packageAlias.getTokenIndex() - 1);
    List<SymbolInfo> returnList = new ArrayList<>();
    if (!(constraintStart.getText().equals("<") || constraintStart.getText().equals("create"))) {
        PackageActionFunctionAndTypesFilter filter = new PackageActionFunctionAndTypesFilter();
        returnList.addAll(filter.filterItems(context));
    } else {
        SymbolInfo packageSymbolInfo = symbolInfos.stream().filter(item -> {
            Scope.ScopeEntry scopeEntry = item.getScopeEntry();
            return item.getSymbolName().equals(packageAlias.getText()) && scopeEntry.symbol instanceof BPackageSymbol;
        }).findFirst().orElse(null);
        if (packageSymbolInfo != null) {
            packageSymbolInfo.getScopeEntry().symbol.scope.entries.forEach((name, value) -> {
                if (value.symbol.kind != null && value.symbol.kind.toString().equals(CONNECTOR_KIND)) {
                    returnList.add(new SymbolInfo(name.toString(), value));
                }
            });
        }
    }
    return returnList;
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) TokenStream(org.antlr.v4.runtime.TokenStream) PackageActionFunctionAndTypesFilter(org.ballerinalang.langserver.completions.util.filters.PackageActionFunctionAndTypesFilter) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) ArrayList(java.util.ArrayList) Token(org.antlr.v4.runtime.Token) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Example 20 with SymbolInfo

use of org.ballerinalang.langserver.completions.SymbolInfo in project ballerina by ballerina-lang.

the class BLangEndpointContextResolver method resolveItems.

@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
    BLangNode bLangEndpoint = completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY);
    ArrayList<CompletionItem> completionItems = new ArrayList<>();
    ArrayList<SymbolInfo> configurationFields = new ArrayList<>();
    List<BStructSymbol.BAttachedFunction> attachedFunctions = new ArrayList<>();
    if (((BLangEndpoint) bLangEndpoint).type.tsymbol instanceof BStructSymbol) {
        attachedFunctions.addAll(((BStructSymbol) ((BLangEndpoint) bLangEndpoint).type.tsymbol).attachedFuncs);
    }
    BStructSymbol.BAttachedFunction initFunction = attachedFunctions.stream().filter(bAttachedFunction -> bAttachedFunction.funcName.getValue().equals(INIT)).findFirst().orElseGet(null);
    BVarSymbol configSymbol = initFunction.symbol.getParameters().get(0);
    BType configSymbolType = configSymbol.getType();
    if (configSymbolType instanceof BStructType) {
        ((BStructType) configSymbolType).getFields().forEach(bStructField -> configurationFields.add(new SymbolInfo(bStructField.getName().getValue(), new Scope.ScopeEntry(bStructField.symbol, null))));
    }
    this.populateCompletionItemList(configurationFields, completionItems);
    return completionItems;
}
Also used : BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) ArrayList(java.util.ArrayList) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) CompletionItem(org.eclipse.lsp4j.CompletionItem) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

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