Search in sources :

Example 41 with SymbolInformation

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

the class GotoSymbolDialog method getTarget.

/**
 * Determine the 'target' for the dialog's action.
 */
private SymbolInformation getTarget(TreeViewer list) {
    ISelection sel = list.getSelection();
    if (sel instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) sel;
        Object selected = ss.getFirstElement();
        if (selected instanceof Match) {
            selected = ((Match<?>) selected).value;
            if (selected instanceof SymbolInformation) {
                return (SymbolInformation) selected;
            }
        }
    }
    // This allows user to execute the action without explicitly selecting an element.
    return getFirstElement(list);
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Match(org.springframework.tooling.ls.eclipse.gotosymbol.dialogs.GotoSymbolDialogModel.Match)

Example 42 with SymbolInformation

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

the class InWorkspaceSymbolsProvider method fetchFor.

@Override
public Collection<SymbolInformation> fetchFor(String query) throws Exception {
    // TODO: if we want decent support for multiple language servers...
    // consider changing SymbolsProvider api and turning the stuff in here into something producing a
    // Flux<Collection<SymbolInformation>>
    // This will help in
    // - supporting cancelation
    // - executing multiple requests to different servers in parallel.
    // - producing results per server so don't have to wait for one slow server to see the rest.
    // However it will also add complexity to the code that consumes this and at this time we only
    // really use this with a single language server anyways.
    WorkspaceSymbolParams params = new WorkspaceSymbolParams(query);
    Flux<SymbolInformation> symbols = Flux.fromIterable(this.languageServers).flatMap(server -> Mono.fromFuture(server.getWorkspaceService().symbol(params)).timeout(TIMEOUT).doOnError(e -> log(e)).onErrorReturn(ImmutableList.of()).flatMapMany(Flux::fromIterable));
    // Consider letting the Flux go out from here instead of blocking and collecting elements.
    return symbols.take(MAX_RESULTS).collect(Collectors.toList()).block();
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IAdaptable(org.eclipse.core.runtime.IAdaptable) Collection(java.util.Collection) WorkspaceSymbolParams(org.eclipse.lsp4j.WorkspaceSymbolParams) Mono(reactor.core.publisher.Mono) LanguageServer(org.eclipse.lsp4j.services.LanguageServer) Collectors(java.util.stream.Collectors) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) ExceptionUtil(org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil) Flux(reactor.core.publisher.Flux) List(java.util.List) IProject(org.eclipse.core.resources.IProject) ImmutableList(com.google.common.collect.ImmutableList) Duration(java.time.Duration) IResource(org.eclipse.core.resources.IResource) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LanguageServiceAccessor(org.eclipse.lsp4e.LanguageServiceAccessor) IEditorPart(org.eclipse.ui.IEditorPart) GotoSymbolPlugin(org.springframework.tooling.ls.eclipse.gotosymbol.GotoSymbolPlugin) WorkspaceSymbolParams(org.eclipse.lsp4j.WorkspaceSymbolParams) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Example 43 with SymbolInformation

use of org.eclipse.lsp4j.SymbolInformation in project freemarker-languageserver by angelozerr.

the class FMLanguageService method provideFileSymbolsInternal.

private void provideFileSymbolsInternal(TextDocumentItem document, Node node, String container, List<SymbolInformation> symbols) {
    String name = nodeToName(node);
    Position start = null;
    Position end = null;
    Range range = new Range(start, end);
    Location location = new Location(document.getUri(), range);
    // 
    // Location.create(document.getUri(),
    // Range.create(document.positionAt(node.start), document.positionAt(node.end)));
    SymbolInformation symbol = new SymbolInformation(name, SymbolKind.Field, location, container);
    symbols.add(symbol);
    node.children.forEach(child -> {
        provideFileSymbolsInternal(document, child, name, symbols);
    });
}
Also used : Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location)

Example 44 with SymbolInformation

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

the class MoveHandler method resolveTargetTypeName.

private static String resolveTargetTypeName(Object destinationObj) throws IllegalArgumentException {
    if (destinationObj instanceof String) {
        return (String) destinationObj;
    }
    String json = (destinationObj == null ? null : new Gson().toJson(destinationObj));
    SymbolInformation destination = JSONUtility.toLsp4jModel(json, SymbolInformation.class);
    if (destination == null) {
        throw new IllegalArgumentException("Invalid destination object: " + destinationObj);
    }
    String typeName = destination.getName();
    if (StringUtils.isNotBlank(destination.getContainerName())) {
        typeName = destination.getContainerName() + "." + destination.getName();
    }
    return typeName;
}
Also used : Gson(com.google.gson.Gson) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Example 45 with SymbolInformation

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

the class DocumentSymbolHandler method collectChildren.

private void collectChildren(ITypeRoot unit, IJavaElement[] elements, ArrayList<SymbolInformation> symbols, IProgressMonitor monitor) throws JavaModelException {
    for (IJavaElement element : elements) {
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        if (element instanceof IParent) {
            collectChildren(unit, filter(((IParent) element).getChildren()), symbols, monitor);
        }
        int type = element.getElementType();
        if (type != IJavaElement.TYPE && type != IJavaElement.FIELD && type != IJavaElement.METHOD) {
            continue;
        }
        Location location = JDTUtils.toLocation(element);
        if (location != null) {
            SymbolInformation si = new SymbolInformation();
            String name = JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
            si.setName(name == null ? element.getElementName() : name);
            si.setKind(mapKind(element));
            if (JDTUtils.isDeprecated(element)) {
                if (preferenceManager.getClientPreferences().isSymbolTagSupported()) {
                    si.setTags(List.of(SymbolTag.Deprecated));
                } else {
                    si.setDeprecated(true);
                }
            }
            if (element.getParent() != null) {
                si.setContainerName(element.getParent().getElementName());
            }
            location.setUri(ResourceUtils.toClientUri(location.getUri()));
            si.setLocation(location);
            if (!symbols.contains(si)) {
                symbols.add(si);
            }
        }
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IParent(org.eclipse.jdt.core.IParent) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) 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