Search in sources :

Example 1 with SymbolFindingVisitor

use of org.ballerinalang.langserver.symbols.SymbolFindingVisitor in project ballerina by ballerina-lang.

the class BallerinaTextDocumentService method documentSymbol.

@Override
public CompletableFuture<List<? extends SymbolInformation>> documentSymbol(DocumentSymbolParams params) {
    String uri = params.getTextDocument().getUri();
    List<SymbolInformation> symbols = new ArrayList<>();
    TextDocumentServiceContext symbolsContext = new TextDocumentServiceContext();
    symbolsContext.put(DocumentServiceKeys.FILE_URI_KEY, uri);
    symbolsContext.put(DocumentServiceKeys.SYMBOL_LIST_KEY, symbols);
    BLangPackage bLangPackage = TextDocumentServiceUtil.getBLangPackage(symbolsContext, documentManager, false, LSCustomErrorStrategy.class, false).get(0);
    symbolsContext.put(DocumentServiceKeys.CURRENT_PACKAGE_NAME_KEY, bLangPackage.symbol.getName().getValue());
    Optional<BLangCompilationUnit> documentCUnit = bLangPackage.getCompilationUnits().stream().filter(cUnit -> (uri.endsWith(cUnit.getName()))).findFirst();
    documentCUnit.ifPresent(cUnit -> {
        SymbolFindingVisitor visitor = new SymbolFindingVisitor(symbolsContext);
        cUnit.accept(visitor);
    });
    return CompletableFuture.supplyAsync(() -> symbols);
}
Also used : CommonUtil(org.ballerinalang.langserver.common.utils.CommonUtil) JsonObject(com.google.gson.JsonObject) RenameUtil(org.ballerinalang.langserver.rename.RenameUtil) HoverUtil(org.ballerinalang.langserver.hover.util.HoverUtil) DidChangeTextDocumentParams(org.eclipse.lsp4j.DidChangeTextDocumentParams) NodeContextKeys(org.ballerinalang.langserver.common.constants.NodeContextKeys) DidSaveTextDocumentParams(org.eclipse.lsp4j.DidSaveTextDocumentParams) TreeVisitor(org.ballerinalang.langserver.completions.TreeVisitor) LSDocument(org.ballerinalang.langserver.common.LSDocument) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) CodeLens(org.eclipse.lsp4j.CodeLens) Map(java.util.Map) Location(org.eclipse.lsp4j.Location) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) BLangCompilationUnit(org.wso2.ballerinalang.compiler.tree.BLangCompilationUnit) URI(java.net.URI) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams) RenameParams(org.eclipse.lsp4j.RenameParams) Path(java.nio.file.Path) SignatureTreeVisitor(org.ballerinalang.langserver.signature.SignatureTreeVisitor) ReferenceUtil(org.ballerinalang.langserver.references.util.ReferenceUtil) TextDocumentService(org.eclipse.lsp4j.services.TextDocumentService) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) DiagnosticListener(org.ballerinalang.util.diagnostic.DiagnosticListener) MarkedString(org.eclipse.lsp4j.MarkedString) DocumentOnTypeFormattingParams(org.eclipse.lsp4j.DocumentOnTypeFormattingParams) CompletionItem(org.eclipse.lsp4j.CompletionItem) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) List(java.util.List) Command(org.eclipse.lsp4j.Command) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) WorkspacePackageRepository(org.ballerinalang.langserver.workspace.repository.WorkspacePackageRepository) Optional(java.util.Optional) Debouncer(org.ballerinalang.langserver.util.Debouncer) WorkspaceDocumentManager(org.ballerinalang.langserver.workspace.WorkspaceDocumentManager) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) WorkspaceDocumentManagerImpl(org.ballerinalang.langserver.workspace.WorkspaceDocumentManagerImpl) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) DocumentRangeFormattingParams(org.eclipse.lsp4j.DocumentRangeFormattingParams) Hover(org.eclipse.lsp4j.Hover) Compiler(org.wso2.ballerinalang.compiler.Compiler) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) ArrayList(java.util.ArrayList) CommandUtil(org.ballerinalang.langserver.command.CommandUtil) SignatureHelpUtil(org.ballerinalang.langserver.signature.SignatureHelpUtil) PositionTreeVisitor(org.ballerinalang.langserver.common.position.PositionTreeVisitor) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) TextEdit(org.eclipse.lsp4j.TextEdit) PackageRepository(org.ballerinalang.repository.PackageRepository) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) Position(org.eclipse.lsp4j.Position) CompletionKeys(org.ballerinalang.langserver.completions.CompletionKeys) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) CompletionList(org.eclipse.lsp4j.CompletionList) SymbolFindingVisitor(org.ballerinalang.langserver.symbols.SymbolFindingVisitor) CompletionItemResolver(org.ballerinalang.langserver.completions.util.CompletionItemResolver) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) DocumentHighlight(org.eclipse.lsp4j.DocumentHighlight) DefinitionUtil(org.ballerinalang.langserver.definition.util.DefinitionUtil) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) LSCustomErrorStrategy(org.ballerinalang.langserver.common.LSCustomErrorStrategy) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Paths(java.nio.file.Paths) CompletionCustomErrorStrategy(org.ballerinalang.langserver.completions.CompletionCustomErrorStrategy) Collections(java.util.Collections) TopLevelResolver(org.ballerinalang.langserver.completions.resolvers.TopLevelResolver) TextDocumentFormatUtil(org.ballerinalang.langserver.format.TextDocumentFormatUtil) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) SymbolFindingVisitor(org.ballerinalang.langserver.symbols.SymbolFindingVisitor) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) ArrayList(java.util.ArrayList) MarkedString(org.eclipse.lsp4j.MarkedString) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) LSCustomErrorStrategy(org.ballerinalang.langserver.common.LSCustomErrorStrategy) BLangCompilationUnit(org.wso2.ballerinalang.compiler.tree.BLangCompilationUnit)

Aggregations

JsonObject (com.google.gson.JsonObject)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CommandUtil (org.ballerinalang.langserver.command.CommandUtil)1 LSCustomErrorStrategy (org.ballerinalang.langserver.common.LSCustomErrorStrategy)1 LSDocument (org.ballerinalang.langserver.common.LSDocument)1 NodeContextKeys (org.ballerinalang.langserver.common.constants.NodeContextKeys)1 PositionTreeVisitor (org.ballerinalang.langserver.common.position.PositionTreeVisitor)1 CommonUtil (org.ballerinalang.langserver.common.utils.CommonUtil)1 CompletionCustomErrorStrategy (org.ballerinalang.langserver.completions.CompletionCustomErrorStrategy)1 CompletionKeys (org.ballerinalang.langserver.completions.CompletionKeys)1 TreeVisitor (org.ballerinalang.langserver.completions.TreeVisitor)1