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);
}
Aggregations