Search in sources :

Example 1 with SignatureTreeVisitor

use of org.ballerinalang.langserver.signature.SignatureTreeVisitor in project ballerina by ballerina-lang.

the class BallerinaTextDocumentService method signatureHelp.

@Override
public CompletableFuture<SignatureHelp> signatureHelp(TextDocumentPositionParams position) {
    return CompletableFuture.supplyAsync(() -> {
        String uri = position.getTextDocument().getUri();
        String fileContent = this.documentManager.getFileContent(Paths.get(URI.create(uri)));
        TextDocumentServiceContext signatureContext = new TextDocumentServiceContext();
        SignatureHelpUtil.captureCallableItemInfo(position.getPosition(), fileContent, signatureContext);
        signatureContext.put(DocumentServiceKeys.POSITION_KEY, position);
        signatureContext.put(DocumentServiceKeys.FILE_URI_KEY, uri);
        SignatureHelp signatureHelp;
        try {
            BLangPackage bLangPackage = TextDocumentServiceUtil.getBLangPackage(signatureContext, documentManager, false, LSCustomErrorStrategy.class, false).get(0);
            signatureContext.put(DocumentServiceKeys.CURRENT_PACKAGE_NAME_KEY, bLangPackage.symbol.getName().getValue());
            SignatureTreeVisitor signatureTreeVisitor = new SignatureTreeVisitor(signatureContext);
            bLangPackage.accept(signatureTreeVisitor);
            signatureContext.put(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY, lSPackageCache);
            signatureHelp = SignatureHelpUtil.getFunctionSignatureHelp(signatureContext);
        } catch (Exception e) {
            signatureHelp = new SignatureHelp();
        }
        return signatureHelp;
    });
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) MarkedString(org.eclipse.lsp4j.MarkedString) LSCustomErrorStrategy(org.ballerinalang.langserver.common.LSCustomErrorStrategy) SignatureTreeVisitor(org.ballerinalang.langserver.signature.SignatureTreeVisitor)

Aggregations

LSCustomErrorStrategy (org.ballerinalang.langserver.common.LSCustomErrorStrategy)1 SignatureTreeVisitor (org.ballerinalang.langserver.signature.SignatureTreeVisitor)1 MarkedString (org.eclipse.lsp4j.MarkedString)1 SignatureHelp (org.eclipse.lsp4j.SignatureHelp)1 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)1