Search in sources :

Example 36 with SymbolInformation

use of org.eclipse.lsp4j.SymbolInformation 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)

Example 37 with SymbolInformation

use of org.eclipse.lsp4j.SymbolInformation in project sts4 by spring-projects.

the class SpringIndexerHarness method getSymbolsInFile.

public List<TestSymbolInfo> getSymbolsInFile(String docURI) throws Exception {
    List<? extends SymbolInformation> symbols = indexer.getSymbols(docURI);
    if (symbols != null) {
        symbols = new ArrayList<>(symbols);
        Collections.sort(symbols, SYMBOL_COMPARATOR);
        TextDocument doc = new TextDocument(docURI, LanguageId.JAVA, 1, IOUtils.toString(new URI(docURI)));
        ImmutableList.Builder<TestSymbolInfo> symbolInfos = ImmutableList.builder();
        for (SymbolInformation s : symbols) {
            int start = doc.toOffset(s.getLocation().getRange().getStart());
            int end = doc.toOffset(s.getLocation().getRange().getEnd());
            symbolInfos.add(new TestSymbolInfo(doc.textBetween(start, end), s.getName()));
        }
        return symbolInfos.build();
    }
    return ImmutableList.of();
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) ImmutableList(com.google.common.collect.ImmutableList) URI(java.net.URI) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Example 38 with SymbolInformation

use of org.eclipse.lsp4j.SymbolInformation in project sts4 by spring-projects.

the class LiveAppURLSymbolProvider method getSymbols.

public List<? extends SymbolInformation> getSymbols(String query) {
    System.out.println(query);
    List<SymbolInformation> result = new ArrayList<>();
    try {
        SpringBootApp[] runningApps = runningAppProvider.getAllRunningSpringApps().toArray(new SpringBootApp[0]);
        for (SpringBootApp app : runningApps) {
            try {
                String host = app.getHost();
                String port = app.getPort();
                Stream<String> urls = app.getRequestMappings().stream().flatMap(rm -> Arrays.stream(rm.getSplitPath())).map(path -> UrlUtil.createUrl(host, port, path));
                urls.forEach(url -> result.add(new SymbolInformation(url, SymbolKind.Method, new Location(url, new Range(new Position(0, 0), new Position(0, 1))))));
            } catch (Exception e) {
                Log.log(e);
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return result;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) RunningAppProvider(org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) Log(org.springframework.ide.vscode.commons.util.Log) SymbolKind(org.eclipse.lsp4j.SymbolKind) SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Location(org.eclipse.lsp4j.Location) Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range) ArrayList(java.util.ArrayList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Position(org.eclipse.lsp4j.Position) ArrayList(java.util.ArrayList) Range(org.eclipse.lsp4j.Range) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location)

Example 39 with SymbolInformation

use of org.eclipse.lsp4j.SymbolInformation in project sts4 by spring-projects.

the class BeansSymbolProvider method getSymbols.

@Override
public Collection<EnhancedSymbolInformation> getSymbols(Annotation node, ITypeBinding annotationType, Collection<ITypeBinding> metaAnnotations, TextDocument doc) {
    if (isMethodAbstract(node))
        return null;
    ImmutableList.Builder<EnhancedSymbolInformation> symbols = ImmutableList.builder();
    boolean isFunction = isFunctionBean(node);
    String beanType = getBeanType(node);
    for (Tuple2<String, DocumentRegion> nameAndRegion : getBeanNames(node, doc)) {
        try {
            symbols.add(new EnhancedSymbolInformation(new SymbolInformation(beanLabel(isFunction, nameAndRegion.getT1(), beanType, "@Bean"), SymbolKind.Interface, new Location(doc.getUri(), doc.toRange(nameAndRegion.getT2()))), null));
        } catch (BadLocationException e) {
            Log.log(e);
        }
    }
    return symbols.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) Location(org.eclipse.lsp4j.Location)

Example 40 with SymbolInformation

use of org.eclipse.lsp4j.SymbolInformation in project sts4 by spring-projects.

the class TypeBasedYamlSymbolHandler method createSymbol.

protected SymbolInformation createSymbol(TextDocument doc, Node node, YType type) throws BadLocationException {
    DocumentRegion region = NodeUtil.region(doc, node);
    Location location = new Location(doc.getUri(), doc.toRange(region.getStart(), region.getLength()));
    SymbolInformation symbol = new SymbolInformation();
    symbol.setName(region.toString());
    symbol.setKind(symbolKind(type));
    symbol.setLocation(location);
    symbol.setContainerName(containerName(type));
    return symbol;
}
Also used : DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location)

Aggregations

SymbolInformation (org.eclipse.lsp4j.SymbolInformation)54 Location (org.eclipse.lsp4j.Location)24 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)11 List (java.util.List)10 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)10 SymbolKind (org.eclipse.lsp4j.SymbolKind)9 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)8 ImmutableList (com.google.common.collect.ImmutableList)7 EnhancedSymbolInformation (org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation)7 URI (java.net.URI)6 Path (java.nio.file.Path)6 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)6 Range (org.eclipse.lsp4j.Range)5 Paths (java.nio.file.Paths)4 Arrays (java.util.Arrays)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Map (java.util.Map)4 Optional (java.util.Optional)4