Search in sources :

Example 26 with SymbolInformation

use of org.eclipse.lsp4j.SymbolInformation in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method documentSymbol.

/**
     * Searches by name for a symbol in a specific document (not the whole
     * workspace)
     */
@Override
public CompletableFuture<List<? extends SymbolInformation>> documentSymbol(DocumentSymbolParams params) {
    TextDocumentIdentifier textDocument = params.getTextDocument();
    Path path = LanguageServerUtils.getPathFromLanguageServerURI(textDocument.getUri());
    if (path == null) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    ICompilationUnit unit = getCompilationUnit(path);
    if (unit == null) {
        //we couldn't find a compilation unit with the specified path
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    IASScope[] scopes;
    try {
        scopes = unit.getFileScopeRequest().get().getScopes();
    } catch (Exception e) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    List<SymbolInformation> result = new ArrayList<>();
    for (IASScope scope : scopes) {
        scopeToSymbols(scope, result);
    }
    return CompletableFuture.completedFuture(result);
}
Also used : Path(java.nio.file.Path) ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) IASScope(org.apache.flex.compiler.scopes.IASScope) ArrayList(java.util.ArrayList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 27 with SymbolInformation

use of org.eclipse.lsp4j.SymbolInformation in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method workspaceSymbol.

/**
     * Searches by name for a symbol in the workspace.
     */
public CompletableFuture<List<? extends SymbolInformation>> workspaceSymbol(WorkspaceSymbolParams params) {
    if (compilationUnits == null) {
        //if we haven't successfully compiled the project, we can't do this
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    List<SymbolInformation> result = new ArrayList<>();
    String query = params.getQuery();
    for (ICompilationUnit unit : compilationUnits) {
        if (unit == null || unit instanceof SWCCompilationUnit) {
            continue;
        }
        IASScope[] scopes;
        try {
            scopes = unit.getFileScopeRequest().get().getScopes();
        } catch (Exception e) {
            return CompletableFuture.completedFuture(Collections.emptyList());
        }
        for (IASScope scope : scopes) {
            querySymbolsInScope(query, scope, result);
        }
    }
    return CompletableFuture.completedFuture(result);
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) SWCCompilationUnit(org.apache.flex.compiler.internal.units.SWCCompilationUnit) IASScope(org.apache.flex.compiler.scopes.IASScope) ArrayList(java.util.ArrayList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 28 with SymbolInformation

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

the class DocumentSymbolService method getSymbols.

public List<? extends SymbolInformation> getSymbols(final IResourceDescription resourceDescription, final String query, final IReferenceFinder.IResourceAccess resourceAccess, final CancelIndicator cancelIndicator) {
    final LinkedList<SymbolInformation> symbols = CollectionLiterals.<SymbolInformation>newLinkedList();
    Iterable<IEObjectDescription> _exportedObjects = resourceDescription.getExportedObjects();
    for (final IEObjectDescription description : _exportedObjects) {
        {
            this.operationCanceledManager.checkCanceled(cancelIndicator);
            boolean _filter = this.filter(description, query);
            if (_filter) {
                final Procedure1<SymbolInformation> _function = (SymbolInformation symbol) -> {
                    symbols.add(symbol);
                };
                this.createSymbol(description, resourceAccess, _function);
            }
        }
    }
    return symbols;
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 29 with SymbolInformation

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

the class WorkspaceSymbolService method getSymbols.

public List<? extends SymbolInformation> getSymbols(final String query, final IReferenceFinder.IResourceAccess resourceAccess, final IResourceDescriptions indexData, final CancelIndicator cancelIndicator) {
    final LinkedList<SymbolInformation> result = CollectionLiterals.<SymbolInformation>newLinkedList();
    Iterable<IResourceDescription> _allResourceDescriptions = indexData.getAllResourceDescriptions();
    for (final IResourceDescription resourceDescription : _allResourceDescriptions) {
        {
            this.operationCanceledManager.checkCanceled(cancelIndicator);
            final IResourceServiceProvider resourceServiceProvider = this._registry.getResourceServiceProvider(resourceDescription.getURI());
            DocumentSymbolService _get = null;
            if (resourceServiceProvider != null) {
                _get = resourceServiceProvider.<DocumentSymbolService>get(DocumentSymbolService.class);
            }
            final DocumentSymbolService documentSymbolService = _get;
            if ((documentSymbolService != null)) {
                List<? extends SymbolInformation> _symbols = documentSymbolService.getSymbols(resourceDescription, query, resourceAccess, cancelIndicator);
                Iterables.<SymbolInformation>addAll(result, _symbols);
            }
        }
    }
    return result;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) DocumentSymbolService(org.eclipse.xtext.ide.server.symbol.DocumentSymbolService) List(java.util.List) LinkedList(java.util.LinkedList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Example 30 with SymbolInformation

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

the class DocumentSymbolHandlerTest method testClass.

private void testClass(String className) throws JavaModelException, UnsupportedEncodingException, InterruptedException, ExecutionException {
    List<? extends SymbolInformation> symbols = getSymbols(className);
    for (SymbolInformation symbol : symbols) {
        Location loc = symbol.getLocation();
        assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.", loc != null && isValid(loc.getRange()));
    }
}
Also used : 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