Search in sources :

Example 1 with SymbolKind

use of org.eclipse.lsp4j.SymbolKind 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 2 with SymbolKind

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

the class DocumentSymbolService method createSymbol.

protected SymbolInformation createSymbol(final EObject object) {
    final String name = this.getSymbolName(object);
    if ((name == null)) {
        return null;
    }
    final SymbolKind kind = this.getSymbolKind(object);
    if ((kind == null)) {
        return null;
    }
    final Location location = this.getSymbolLocation(object);
    if ((location == null)) {
        return null;
    }
    final 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 3 with SymbolKind

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

the class DocumentSymbolService method createSymbol.

protected SymbolInformation createSymbol(final IEObjectDescription description) {
    final String symbolName = this.getSymbolName(description);
    if ((symbolName == null)) {
        return null;
    }
    final SymbolKind symbolKind = this.getSymbolKind(description);
    if ((symbolKind == null)) {
        return null;
    }
    final 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 4 with SymbolKind

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

the class DocumentSymbolService method createSymbol.

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

Example 5 with SymbolKind

use of org.eclipse.lsp4j.SymbolKind in project ballerina by ballerina-lang.

the class SymbolFindingVisitor method visit.

public void visit(BLangVariable variableNode) {
    SymbolKind kind;
    String btype = variableNode.getTypeNode().toString();
    switch(btype) {
        case "boolean":
            kind = SymbolKind.Boolean;
            break;
        case "int":
            kind = SymbolKind.Number;
            break;
        case "float":
            kind = SymbolKind.Number;
            break;
        default:
            if (btype.endsWith("[]")) {
                kind = SymbolKind.Array;
            } else {
                kind = SymbolKind.Variable;
            }
    }
    this.addSymbol(variableNode, variableNode.symbol, kind);
}
Also used : SymbolKind(org.eclipse.lsp4j.SymbolKind) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)

Aggregations

SymbolKind (org.eclipse.lsp4j.SymbolKind)5 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)4 Location (org.eclipse.lsp4j.Location)3 ArrayList (java.util.ArrayList)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 SearchEngine (org.eclipse.jdt.core.search.SearchEngine)1 TypeNameMatch (org.eclipse.jdt.core.search.TypeNameMatch)1 TypeNameMatchRequestor (org.eclipse.jdt.core.search.TypeNameMatchRequestor)1 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)1