Search in sources :

Example 31 with SymbolInformation

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

the class DocumentSymbolService method createSymbol.

protected SymbolInformation createSymbol(EObject object) {
    String name = getSymbolName(object);
    if (name == null) {
        return null;
    }
    SymbolKind kind = getSymbolKind(object);
    if (kind == null) {
        return null;
    }
    Location location = getSymbolLocation(object);
    if (location == null) {
        return null;
    }
    SymbolInformation symbol = new SymbolInformation();
    symbol.setName(name);
    symbol.setKind(kind);
    symbol.setLocation(location);
    return symbol;
}
Also used : SymbolKind(org.eclipse.lsp4j.SymbolKind) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location)

Example 32 with SymbolInformation

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

the class DocumentSymbolService method createSymbol.

protected void createSymbol(IEObjectDescription description, IReferenceFinder.IResourceAccess resourceAccess, Procedure1<? super SymbolInformation> acceptor) {
    String name = getSymbolName(description);
    if (name == null) {
        return;
    }
    SymbolKind kind = getSymbolKind(description);
    if (kind == null) {
        return;
    }
    getSymbolLocation(description, resourceAccess, (Location location) -> {
        SymbolInformation symbol = new SymbolInformation(name, kind, location);
        acceptor.apply(symbol);
    });
}
Also used : SymbolKind(org.eclipse.lsp4j.SymbolKind) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location)

Example 33 with SymbolInformation

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

the class DocumentSymbolService method getSymbols.

public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(XtextResource resource, CancelIndicator cancelIndicator) {
    String uri = uriExtensions.toUriString(resource.getURI());
    ArrayList<SymbolInformation> infos = new ArrayList<>();
    List<DocumentSymbol> rootSymbols = Lists.transform(hierarchicalDocumentSymbolService.getSymbols(resource, cancelIndicator), Either::getRight);
    for (DocumentSymbol rootSymbol : rootSymbols) {
        Iterable<DocumentSymbol> symbols = Traverser.forTree(DocumentSymbol::getChildren).depthFirstPreOrder(rootSymbol);
        Function1<? super DocumentSymbol, ? extends String> containerNameProvider = (DocumentSymbol symbol) -> {
            DocumentSymbol firstSymbol = IterableExtensions.findFirst(symbols, (DocumentSymbol it) -> {
                return it != symbol && !IterableExtensions.isNullOrEmpty(it.getChildren()) && it.getChildren().contains(symbol);
            });
            if (firstSymbol != null) {
                return firstSymbol.getName();
            }
            return null;
        };
        for (DocumentSymbol s : symbols) {
            infos.add(createSymbol(uri, s, containerNameProvider));
        }
    }
    return Lists.transform(infos, Either::forLeft);
}
Also used : ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Example 34 with SymbolInformation

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

the class DocumentSymbolService method createSymbol.

protected SymbolInformation createSymbol(IEObjectDescription description) {
    String symbolName = getSymbolName(description);
    if (symbolName == null) {
        return null;
    }
    SymbolKind symbolKind = getSymbolKind(description);
    if (symbolKind == null) {
        return null;
    }
    SymbolInformation symbol = new SymbolInformation();
    symbol.setName(symbolName);
    symbol.setKind(symbolKind);
    return symbol;
}
Also used : SymbolKind(org.eclipse.lsp4j.SymbolKind) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Example 35 with SymbolInformation

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

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