Search in sources :

Example 1 with DocumentSymbolParams

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

the class InFileSymbolsProvider method fetchFor.

@Override
public Collection<SymbolInformation> fetchFor(String query) throws Exception {
    DocumentSymbolParams params = new DocumentSymbolParams(new TextDocumentIdentifier(info.getFileUri().toString()));
    CompletableFuture<List<? extends SymbolInformation>> symbolsFuture = info.getLanguageClient().getTextDocumentService().documentSymbol(params);
    List<? extends SymbolInformation> symbols = symbolsFuture.get();
    return symbols == null ? ImmutableList.of() : ImmutableList.copyOf(symbols);
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Example 2 with DocumentSymbolParams

use of org.eclipse.lsp4j.DocumentSymbolParams in project eclipse.jdt.ls by eclipse.

the class DocumentSymbolHandlerTest method getSymbols.

private List<? extends SymbolInformation> getSymbols(String className) throws JavaModelException, UnsupportedEncodingException, InterruptedException, ExecutionException {
    String uri = ClassFileUtil.getURI(project, className);
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
    DocumentSymbolParams params = new DocumentSymbolParams();
    params.setTextDocument(identifier);
    List<? extends SymbolInformation> symbols = handler.documentSymbol(params, monitor);
    assertTrue(symbols.size() > 0);
    return symbols;
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams)

Example 3 with DocumentSymbolParams

use of org.eclipse.lsp4j.DocumentSymbolParams in project xtext-core by eclipse.

the class AbstractLanguageServerTest method testDocumentSymbol.

protected void testDocumentSymbol(final Procedure1<? super DocumentSymbolConfiguraiton> configurator) {
    try {
        @Extension final DocumentSymbolConfiguraiton configuration = new DocumentSymbolConfiguraiton();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String fileUri = this.initializeContext(configuration).getUri();
        TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
        DocumentSymbolParams _documentSymbolParams = new DocumentSymbolParams(_textDocumentIdentifier);
        final CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> symbolsFuture = this.languageServer.documentSymbol(_documentSymbolParams);
        final List<Either<SymbolInformation, DocumentSymbol>> symbols = symbolsFuture.get();
        Procedure1<? super List<Either<SymbolInformation, DocumentSymbol>>> _assertSymbols = configuration.getAssertSymbols();
        boolean _tripleNotEquals = (_assertSymbols != null);
        if (_tripleNotEquals) {
            configuration.getAssertSymbols().apply(symbols);
        } else {
            final Function1<Either<SymbolInformation, DocumentSymbol>, Object> _function = (Either<SymbolInformation, DocumentSymbol> it) -> {
                Object _xifexpression = null;
                if (this.hierarchicalDocumentSymbolSupport) {
                    _xifexpression = it.getRight();
                } else {
                    _xifexpression = it.getLeft();
                }
                return _xifexpression;
            };
            final List<Object> unwrappedSymbols = ListExtensions.<Either<SymbolInformation, DocumentSymbol>, Object>map(symbols, _function);
            final String actualSymbols = this.toExpectation(unwrappedSymbols);
            this.assertEquals(configuration.getExpectedSymbols(), actualSymbols);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Extension(org.eclipse.xtext.xbase.lib.Extension) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol)

Example 4 with DocumentSymbolParams

use of org.eclipse.lsp4j.DocumentSymbolParams 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 5 with DocumentSymbolParams

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

the class LanguageServerHarness method getDocumentSymbols.

public List<? extends SymbolInformation> getDocumentSymbols(TextDocumentInfo document) throws Exception {
    // TODO: if the server works properly this shouldn't be needed it should do that internally itself somehow.
    waitForReconcile();
    DocumentSymbolParams params = new DocumentSymbolParams(document.getId());
    return getServer().getTextDocumentService().documentSymbol(params).get();
}
Also used : DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams)

Aggregations

DocumentSymbolParams (org.eclipse.lsp4j.DocumentSymbolParams)5 List (java.util.List)3 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)3 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)3 CompletionList (org.eclipse.lsp4j.CompletionList)2 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)2 ImmutableList (com.google.common.collect.ImmutableList)1 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 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