Search in sources :

Example 1 with SymbolInformation

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

the class ActionScriptTextDocumentService method querySymbolsInScope.

private void querySymbolsInScope(String query, IASScope scope, List<SymbolInformation> result) {
    String lowerCaseQuery = query.toLowerCase();
    Collection<IDefinition> definitions = scope.getAllLocalDefinitions();
    for (IDefinition definition : definitions) {
        if (definition instanceof IPackageDefinition) {
            IPackageDefinition packageDefinition = (IPackageDefinition) definition;
            IASScope packageScope = packageDefinition.getContainedScope();
            querySymbolsInScope(query, packageScope, result);
        } else if (definition instanceof ITypeDefinition) {
            ITypeDefinition typeDefinition = (ITypeDefinition) definition;
            if (!definition.isImplicit() && typeDefinition.getQualifiedName().toLowerCase().contains(lowerCaseQuery)) {
                SymbolInformation symbol = definitionToSymbol(typeDefinition);
                result.add(symbol);
            }
            IASScope typeScope = typeDefinition.getContainedScope();
            querySymbolsInScope(query, typeScope, result);
        } else if (definition instanceof IFunctionDefinition) {
            if (definition.isImplicit()) {
                continue;
            }
            IFunctionDefinition functionDefinition = (IFunctionDefinition) definition;
            if (functionDefinition.getQualifiedName().toLowerCase().contains(lowerCaseQuery)) {
                SymbolInformation symbol = definitionToSymbol(functionDefinition);
                result.add(symbol);
            }
            IASScope functionScope = functionDefinition.getContainedScope();
            querySymbolsInScope(query, functionScope, result);
        } else if (definition instanceof IVariableDefinition) {
            if (definition.isImplicit()) {
                continue;
            }
            IVariableDefinition variableDefinition = (IVariableDefinition) definition;
            if (variableDefinition.getQualifiedName().toLowerCase().contains(lowerCaseQuery)) {
                SymbolInformation symbol = definitionToSymbol(variableDefinition);
                result.add(symbol);
            }
        }
    }
}
Also used : IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) IASScope(org.apache.flex.compiler.scopes.IASScope) IPackageDefinition(org.apache.flex.compiler.definitions.IPackageDefinition) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) IVariableDefinition(org.apache.flex.compiler.definitions.IVariableDefinition) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 2 with SymbolInformation

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

the class DocumentSymbolHandler method documentSymbol.

public List<? extends SymbolInformation> documentSymbol(DocumentSymbolParams params, IProgressMonitor monitor) {
    ITypeRoot unit = JDTUtils.resolveTypeRoot(params.getTextDocument().getUri());
    if (unit == null) {
        return Collections.emptyList();
    }
    SymbolInformation[] elements = this.getOutline(unit, monitor);
    return Arrays.asList(elements);
}
Also used : ITypeRoot(org.eclipse.jdt.core.ITypeRoot) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Example 3 with SymbolInformation

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

the class WorkspaceSymbolHandler method search.

public List<SymbolInformation> search(String query, IProgressMonitor monitor) {
    if (query == null || query.trim().isEmpty()) {
        return Collections.emptyList();
    }
    try {
        ArrayList<SymbolInformation> symbols = new ArrayList<>();
        new SearchEngine().searchAllTypeNames(null, SearchPattern.R_PATTERN_MATCH, query.toCharArray(), SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.TYPE, createSearchScope(), new TypeNameMatchRequestor() {

            @Override
            public void acceptTypeNameMatch(TypeNameMatch match) {
                SymbolInformation symbolInformation = new SymbolInformation();
                symbolInformation.setContainerName(match.getTypeContainerName());
                symbolInformation.setName(match.getSimpleTypeName());
                symbolInformation.setKind(mapKind(match));
                Location location;
                try {
                    if (match.getType().isBinary()) {
                        location = JDTUtils.toLocation(match.getType().getClassFile());
                    } else {
                        location = JDTUtils.toLocation(match.getType());
                    }
                } catch (Exception e) {
                    JavaLanguageServerPlugin.logException("Unable to determine location for " + match.getSimpleTypeName(), e);
                    return;
                }
                symbolInformation.setLocation(location);
                symbols.add(symbolInformation);
            }

            private SymbolKind mapKind(TypeNameMatch match) {
                int flags = match.getModifiers();
                if (Flags.isInterface(flags)) {
                    return SymbolKind.Interface;
                }
                if (Flags.isAnnotation(flags)) {
                    return SymbolKind.Property;
                }
                if (Flags.isEnum(flags)) {
                    return SymbolKind.Enum;
                }
                return SymbolKind.Class;
            }
        }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
        return symbols;
    } catch (Exception e) {
        JavaLanguageServerPlugin.logException("Problem getting search for" + query, e);
    }
    return Collections.emptyList();
}
Also used : SearchEngine(org.eclipse.jdt.core.search.SearchEngine) TypeNameMatch(org.eclipse.jdt.core.search.TypeNameMatch) SymbolKind(org.eclipse.lsp4j.SymbolKind) ArrayList(java.util.ArrayList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) TypeNameMatchRequestor(org.eclipse.jdt.core.search.TypeNameMatchRequestor) JavaModelException(org.eclipse.jdt.core.JavaModelException) Location(org.eclipse.lsp4j.Location)

Example 4 with SymbolInformation

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

the class WorkspaceSymbolHandlerTest method testWorkspaceSearch.

@Test
public void testWorkspaceSearch() {
    String query = "Array";
    List<SymbolInformation> results = handler.search(query, monitor);
    assertNotNull(results);
    assertEquals("Unexpected results", 11, results.size());
    Range defaultRange = JDTUtils.newRange();
    for (SymbolInformation symbol : results) {
        assertNotNull("Kind is missing", symbol.getKind());
        assertNotNull("ContainerName is missing", symbol.getContainerName());
        assertTrue(symbol.getName().startsWith(query));
        Location location = symbol.getLocation();
        assertEquals(defaultRange, location.getRange());
        // No class in the workspace project starts with Array, so everything comes from the JDK
        assertTrue("Unexpected uri " + location.getUri(), location.getUri().startsWith("jdt://"));
    }
}
Also used : Range(org.eclipse.lsp4j.Range) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Example 5 with SymbolInformation

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

the class WorkspaceSymbolHandlerTest method testWorkspaceSearchOnFileInWorkspace.

@Test
public void testWorkspaceSearchOnFileInWorkspace() {
    String query = "Baz";
    List<SymbolInformation> results = handler.search(query, monitor);
    assertNotNull(results);
    assertEquals("Unexpected results", 2, results.size());
    Range defaultRange = JDTUtils.newRange();
    for (SymbolInformation symbol : results) {
        assertNotNull("Kind is missing", symbol.getKind());
        assertNotNull("ContainerName is missing", symbol.getContainerName());
        assertTrue(symbol.getName().startsWith(query));
        Location location = symbol.getLocation();
        assertNotEquals("Range should not equal the default range", defaultRange, location.getRange());
        assertTrue("Unexpected uri " + location.getUri(), location.getUri().startsWith("file://"));
    }
}
Also used : Range(org.eclipse.lsp4j.Range) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Aggregations

SymbolInformation (org.eclipse.lsp4j.SymbolInformation)43 Location (org.eclipse.lsp4j.Location)22 ArrayList (java.util.ArrayList)11 List (java.util.List)10 SymbolKind (org.eclipse.lsp4j.SymbolKind)8 ImmutableList (com.google.common.collect.ImmutableList)7 EnhancedSymbolInformation (org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation)7 Path (java.nio.file.Path)6 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)6 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)6 URI (java.net.URI)5 Collectors (java.util.stream.Collectors)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 CompletableFuture (java.util.concurrent.CompletableFuture)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4