Search in sources :

Example 6 with BAttachedFunction

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction 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

BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)6 BAttachedFunction (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction)5 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)2 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)2 BStructType (org.wso2.ballerinalang.compiler.semantics.model.types.BStructType)2 BStructField (org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField)2 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 ArrayList (java.util.ArrayList)1 SymbolInfo (org.ballerinalang.langserver.completions.SymbolInfo)1 CompletionItem (org.eclipse.lsp4j.CompletionItem)1 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)1 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)1 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 AttachedFunctionInfo (org.wso2.ballerinalang.programfile.AttachedFunctionInfo)1 StructFieldInfo (org.wso2.ballerinalang.programfile.StructFieldInfo)1 StructInfo (org.wso2.ballerinalang.programfile.StructInfo)1 DefaultValueAttributeInfo (org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo)1 ParamDefaultValueAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo)1