diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/META-INF/MANIFEST.MF b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/META-INF/MANIFEST.MF index 89abcdee5..2c8ef1aee 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/META-INF/MANIFEST.MF +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/META-INF/MANIFEST.MF @@ -5,9 +5,9 @@ Bundle-SymbolicName: org.springframework.tooling.ls.eclipse.gotosymbol;singleton Bundle-Version: 4.15.0.qualifier Require-Bundle: org.eclipse.ui, org.eclipse.ui.workbench.texteditor, - org.eclipse.lsp4e;bundle-version="0.13.7", - org.eclipse.lsp4j;bundle-version="0.6.0", - org.eclipse.lsp4j.jsonrpc;bundle-version="0.6.0", + org.eclipse.lsp4e;bundle-version="0.13.12", + org.eclipse.lsp4j;bundle-version="0.14.0", + org.eclipse.lsp4j.jsonrpc;bundle-version="0.14.0", org.eclipse.jface.text;bundle-version="3.12.0", org.eclipse.core.resources;bundle-version="3.12.0", org.eclipse.core.filebuffers, diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolDialogModel.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolDialogModel.java index f5095410f..36c347317 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolDialogModel.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolDialogModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017, 2019 Pivotal, Inc. + * Copyright (c) 2017, 2022 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -19,10 +19,8 @@ import java.util.stream.Collectors; import org.eclipse.core.runtime.Assert; import org.eclipse.lsp4e.LSPEclipseUtils; -import org.eclipse.lsp4j.DocumentSymbol; import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.SymbolInformation; -import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.springframework.tooling.ls.eclipse.gotosymbol.GotoSymbolPlugin; @@ -70,12 +68,12 @@ public class GotoSymbolDialogModel { } - public static Comparator>> MATCH_COMPARATOR = (m1, m2) -> { + public static Comparator> MATCH_COMPARATOR = (m1, m2) -> { int comp = Double.compare(m2.score, m1.score); - if (comp!=0) return comp; + if (comp != 0) return comp; - String m1Name = m1.value.isLeft() ? m1.value.getLeft().getName() : m1.value.getRight().getName(); - String m2Name = m2.value.isLeft() ? m2.value.getLeft().getName() : m2.value.getRight().getName(); + String m1Name = m1.value.getName(); + String m2Name = m2.value.getName(); return m1Name.compareTo(m2Name); }; @@ -113,7 +111,7 @@ public class GotoSymbolDialogModel { private int currentSymbolsProviderIndex; public final LiveVariable currentSymbolsProvider = new LiveVariable<>(null); private final LiveVariable searchBox = new LiveVariable<>(""); - public final ObservableSet> unfilteredSymbols = new ObservableSet>(ImmutableSet.of(), AsyncMode.ASYNC, AsyncMode.SYNC) { + public final ObservableSet unfilteredSymbols = new ObservableSet(ImmutableSet.of(), AsyncMode.ASYNC, AsyncMode.SYNC) { //Note: fetching is 'slow' so is done asynchronously { setRefreshDelay(100); @@ -122,7 +120,7 @@ public class GotoSymbolDialogModel { } @Override - protected ImmutableSet> compute() { + protected ImmutableSet compute() { status.setValue(HighlightedText.plain("Fetching symbols...")); try { SymbolsProvider sp = currentSymbolsProvider.getValue(); @@ -131,7 +129,7 @@ public class GotoSymbolDialogModel { debug("Fetching "+currentProviderName); String query = searchBox.getValue(); debug("Fetching symbols... from symbol provider, for '"+query+"'"); - Collection> fetched = sp.fetchFor(query); + Collection fetched = sp.fetchFor(query); if (keyBindings==null) { status.setValue(HighlightedText.plain(currentProviderName)); } else { @@ -160,7 +158,7 @@ public class GotoSymbolDialogModel { } }; - private LiveExpression>>> filteredSymbols = new LiveExpression>>>() { + private LiveExpression>> filteredSymbols = new LiveExpression>>() { //Note: filtering is 'fast' so is done synchronously { dependsOn(searchBox); @@ -168,25 +166,23 @@ public class GotoSymbolDialogModel { } @Override - protected Collection>> compute() { + protected Collection> compute() { String query = searchBox.getValue(); if (!StringUtil.hasText(query)) { query = ""; } query = query.toLowerCase(); - List>> matches = new ArrayList<>(); - for (Either symbol : unfilteredSymbols.getValues()) { - String name = null; - if (symbol.isLeft()) { - name = symbol.getLeft().getName().toLowerCase(); - } - else if (symbol.isRight()) { - name = symbol.getRight().getName().toLowerCase(); + List> matches = new ArrayList<>(); + for (SymbolContainer symbol : unfilteredSymbols.getValues()) { + String name = symbol.getName(); + + if (name != null) { + name = name.toLowerCase(); } double score = FuzzyMatcher.matchScore(query, name); - if (score!=0.0) { - matches.add(new Match>(score, query, symbol)); + if (score != 0.0) { + matches.add(new Match(score, query, symbol)); } } Collections.sort(matches, MATCH_COMPARATOR); @@ -223,11 +219,11 @@ public class GotoSymbolDialogModel { return favourites; } - private List summary(Collection>> collection) { - return collection.stream().map(match -> match.value.isLeft() ? match.value.getLeft().getName() : match.value.getRight().getName()).collect(Collectors.toList()); + private List summary(Collection> collection) { + return collection.stream().map(match -> match.value.getName()).collect(Collectors.toList()); } - public LiveExpression>>> getSymbols() { + public LiveExpression>> getSymbols() { return filteredSymbols; } @@ -270,7 +266,8 @@ public class GotoSymbolDialogModel { public boolean fromFileProvider(SymbolInformation symbolInformation) { SymbolsProvider sp = currentSymbolsProvider.getValue(); - if (sp!=null) { + + if (sp != null) { return sp.fromFile(symbolInformation); } return false; diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolSection.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolSection.java index 85821af77..a0f58b579 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolSection.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolSection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2021 Rogue Wave Software Inc. and others. + * Copyright (c) 2016, 2022 Rogue Wave Software Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -464,7 +464,7 @@ public class GotoSymbolSection extends WizardPageSection { private SymbolInformation getFirstElement(TreeViewer list) { TreeItem[] items = list.getTree().getItems(); - if (items != null && items.length>0) { + if (items != null && items.length > 0) { TreeItem item = items[0]; Object data = item.getData(); if (data instanceof Match) { @@ -478,16 +478,11 @@ public class GotoSymbolSection extends WizardPageSection { } private SymbolInformation getSymbolInformation(Match element) { - if (element.value instanceof SymbolInformation) { - return (SymbolInformation) element.value; - } - if (element.value instanceof Either) { - Either either = (Either)element.value; - if (either.isLeft()) { - Object left = either.getLeft(); - if (left instanceof SymbolInformation) { - return (SymbolInformation) left; - } + if (element.value instanceof SymbolContainer) { + SymbolContainer symbolContainer = (SymbolContainer) element.value; + + if (symbolContainer.isSymbolInformation()) { + return symbolContainer.getSymbolInformation(); } } return null; diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InFileSymbolsProvider.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InFileSymbolsProvider.java index a9c3acf6a..24e617fe6 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InFileSymbolsProvider.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InFileSymbolsProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017, 2021 Pivotal, Inc. + * Copyright (c) 2017, 2022 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,6 +14,7 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; +import java.util.stream.Collectors; import org.eclipse.jface.text.IDocument; import org.eclipse.lsp4e.LSPEclipseUtils; @@ -47,16 +48,21 @@ public class InFileSymbolsProvider implements SymbolsProvider { } @Override - public List> fetchFor(String query) throws Exception { + public List fetchFor(String query) throws Exception { CompletableFuture server = getServer(); String uri = getUri(); + if (server != null && uri != null) { - DocumentSymbolParams params = new DocumentSymbolParams( - new TextDocumentIdentifier(uri)); + DocumentSymbolParams params = new DocumentSymbolParams(new TextDocumentIdentifier(uri)); + CompletableFuture>> symbolsFuture = server .get() .getTextDocumentService().documentSymbol(params); - List> symbols = symbolsFuture.get(); + + List symbols = symbolsFuture.get().stream() + .map(either -> either.isLeft() ? SymbolContainer.fromSymbolInformation(either.getLeft()) : SymbolContainer.fromDocumentSymbol(either.getRight())) + .collect(Collectors.toList()); + return symbols == null ? ImmutableList.of() : ImmutableList.copyOf(symbols); } return ImmutableList.of(); diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InProjectSymbolsProvider.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InProjectSymbolsProvider.java index cb881093d..cac28fdb1 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InProjectSymbolsProvider.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InProjectSymbolsProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2021 Pivotal, Inc. + * Copyright (c) 2019, 2022 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -21,6 +21,7 @@ import org.eclipse.lsp4e.LSPEclipseUtils; import org.eclipse.lsp4e.LanguageServiceAccessor; import org.eclipse.lsp4j.DocumentSymbol; import org.eclipse.lsp4j.SymbolInformation; +import org.eclipse.lsp4j.WorkspaceSymbol; import org.eclipse.lsp4j.WorkspaceSymbolParams; import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.lsp4j.services.LanguageServer; @@ -29,6 +30,7 @@ import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression; import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -74,7 +76,7 @@ public class InProjectSymbolsProvider implements SymbolsProvider { } @Override - public List> fetchFor(String query) throws Exception { + public List 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> @@ -86,20 +88,27 @@ public class InProjectSymbolsProvider implements SymbolsProvider { // really use this with a single language server anyways. IProject project = this.project.get(); - if (project!=null) { + + if (project != null) { String projectLocationPrefix = LSPEclipseUtils.toUri(project).toString(); query = "locationPrefix:" + projectLocationPrefix + "?" + query; WorkspaceSymbolParams params = new WorkspaceSymbolParams(query); - Flux> symbols = Flux.fromIterable(this.languageServers.get()) - .flatMap(server -> Mono.fromFuture(server.getWorkspaceService().symbol(params)) - .timeout(TIMEOUT) - .doOnError(e -> log(e)) - .onErrorReturn(ImmutableList.of()) - .flatMapMany(Flux::fromIterable) - .map(symbol -> Either.forLeft(symbol)) - ); + List servers = this.languageServers.get(); + + Flux, List>> first = Flux.fromIterable(servers) + .flatMap(server -> Mono.fromFuture(server.getWorkspaceService().symbol(params))) + .timeout(TIMEOUT); + + Flux symbols = first + .doOnError(e -> log(e)) + .onErrorReturn(Either.forLeft(ImmutableList.of())) + .map(eitherList -> (eitherList.isLeft() + ? SymbolsProvider.toSymbolContainerFromSymbolInformation(eitherList.getLeft()) + : SymbolsProvider.toSymbolContainerFromWorkspaceSymbols(eitherList.getRight()))) + .flatMap(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(); } @@ -114,5 +123,5 @@ public class InProjectSymbolsProvider implements SymbolsProvider { private static void log(Throwable e) { GotoSymbolPlugin.getInstance().getLog().log(ExceptionUtil.status(e)); } - + } diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InWorkspaceSymbolsProvider.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InWorkspaceSymbolsProvider.java index 08c3f9699..c7cd1e795 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InWorkspaceSymbolsProvider.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InWorkspaceSymbolsProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017, 2021 Pivotal, Inc. + * Copyright (c) 2017, 2022 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,16 +23,15 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.lsp4e.LSPEclipseUtils; import org.eclipse.lsp4e.LanguageServiceAccessor; -import org.eclipse.lsp4j.DocumentSymbol; import org.eclipse.lsp4j.ServerCapabilities; import org.eclipse.lsp4j.SymbolInformation; +import org.eclipse.lsp4j.WorkspaceSymbol; import org.eclipse.lsp4j.WorkspaceSymbolParams; import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.lsp4j.services.LanguageServer; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.handlers.HandlerUtil; import org.springframework.tooling.ls.eclipse.gotosymbol.GotoSymbolPlugin; -import org.springsource.ide.eclipse.commons.livexp.ui.Ilabelable; import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil; import com.google.common.collect.ImmutableList; @@ -81,7 +80,7 @@ public class InWorkspaceSymbolsProvider implements SymbolsProvider { } @Override - public List> fetchFor(String query) throws Exception { + public List 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> @@ -93,14 +92,20 @@ public class InWorkspaceSymbolsProvider implements SymbolsProvider { // really use this with a single language server anyways. WorkspaceSymbolParams params = new WorkspaceSymbolParams(query); - Flux> symbols = Flux.fromIterable(this.languageServers.get()) - .flatMap(server -> Mono.fromFuture(server.getWorkspaceService().symbol(params)) - .timeout(TIMEOUT) - .doOnError(e -> log(e)) - .onErrorReturn(ImmutableList.of()) - .flatMapMany(Flux::fromIterable) - .map(symbol -> Either.forLeft(symbol)) - ); + List servers = this.languageServers.get(); + + Flux, List>> first = Flux.fromIterable(servers) + .flatMap(server -> Mono.fromFuture(server.getWorkspaceService().symbol(params))) + .timeout(TIMEOUT); + + Flux symbols = first + .doOnError(e -> log(e)) + .onErrorReturn(Either.forLeft(ImmutableList.of())) + .map(eitherList -> (eitherList.isLeft() + ? SymbolsProvider.toSymbolContainerFromSymbolInformation(eitherList.getLeft()) + : SymbolsProvider.toSymbolContainerFromWorkspaceSymbols(eitherList.getRight()))) + .flatMap(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(); } @@ -141,4 +146,5 @@ public class InWorkspaceSymbolsProvider implements SymbolsProvider { private static void log(Throwable e) { GotoSymbolPlugin.getInstance().getLog().log(ExceptionUtil.status(e)); } + } diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SymbolContainer.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SymbolContainer.java new file mode 100644 index 000000000..354d32943 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SymbolContainer.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2022 VMware Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Lippert (VMware Inc.) - initial implementation + *******************************************************************************/ +package org.springframework.tooling.ls.eclipse.gotosymbol.dialogs; + +import org.eclipse.lsp4j.DocumentSymbol; +import org.eclipse.lsp4j.SymbolInformation; +import org.eclipse.lsp4j.WorkspaceSymbol; + +public class SymbolContainer { + + private SymbolInformation symbolInformation; + private DocumentSymbol documentSymbol; + private WorkspaceSymbol workspaceSymbol; + + public static SymbolContainer fromSymbolInformation(SymbolInformation symbolInformation) { + return new SymbolContainer(symbolInformation); + } + + public static SymbolContainer fromDocumentSymbol(DocumentSymbol documentSymbol) { + return new SymbolContainer(documentSymbol); + } + + public static SymbolContainer fromWorkspaceSymbol(WorkspaceSymbol workspaceSymbol) { + return new SymbolContainer(workspaceSymbol); + } + + private SymbolContainer(SymbolInformation symbolInformation) { + this.symbolInformation = symbolInformation; + } + + private SymbolContainer(DocumentSymbol documentSymbol) { + this.documentSymbol = documentSymbol; + } + + private SymbolContainer(WorkspaceSymbol workspaceSymbol) { + this.workspaceSymbol = workspaceSymbol; + } + + public boolean isSymbolInformation() { + return symbolInformation != null; + } + + public boolean isDocumentSymbol() { + return documentSymbol != null; + } + + public boolean isWorkspaceSymbol() { + return workspaceSymbol != null; + } + + public SymbolInformation getSymbolInformation() { + return symbolInformation; + } + + public DocumentSymbol getDocumentSymbol() { + return documentSymbol; + } + + public WorkspaceSymbol getWorkspaceSymbol() { + return workspaceSymbol; + } + + /** + * convenience method to get the name from the symbol, independent of which type of symbol it is + */ + public String getName() { + + if (isSymbolInformation()) { + return symbolInformation.getName(); + } + else if (isDocumentSymbol()) { + return documentSymbol.getName(); + } + else if (isWorkspaceSymbol()) { + return workspaceSymbol.getName(); + } + + return null; + } + +} diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SymbolsProvider.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SymbolsProvider.java index f426e193a..1de3bf64b 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SymbolsProvider.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SymbolsProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 Pivotal, Inc. + * Copyright (c) 2017, 2022 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,10 +11,10 @@ package org.springframework.tooling.ls.eclipse.gotosymbol.dialogs; import java.util.List; +import java.util.stream.Collectors; -import org.eclipse.lsp4j.DocumentSymbol; import org.eclipse.lsp4j.SymbolInformation; -import org.eclipse.lsp4j.jsonrpc.messages.Either; +import org.eclipse.lsp4j.WorkspaceSymbol; /** * An SymbolsProvider can fetch symbols from a service (typically, a language server @@ -24,7 +24,7 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either; public interface SymbolsProvider { String getName(); - List> fetchFor(String query) throws Exception; + List fetchFor(String query) throws Exception; /** * True if the symbol information is provided from a file provider (a file is the provider of the symbols). False otherwise * @param symbol @@ -32,4 +32,15 @@ public interface SymbolsProvider { */ boolean fromFile(SymbolInformation symbol); + + + // helper methods for symbol providers to convert lists + static List toSymbolContainerFromSymbolInformation(List symbols) { + return symbols.stream().map(sym -> SymbolContainer.fromSymbolInformation(sym)).collect(Collectors.toList()); + } + + static List toSymbolContainerFromWorkspaceSymbols(List symbols) { + return symbols.stream().map(sym -> SymbolContainer.fromWorkspaceSymbol(sym)).collect(Collectors.toList()); + } + } \ No newline at end of file