PT 152579405 - Show resource location for workspace symbols

This commit is contained in:
nsingh
2017-11-21 00:51:17 -08:00
parent fe689f2306
commit ad317bebfa
5 changed files with 64 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ package org.springframework.tooling.ls.eclipse.gotosymbol.dialogs;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
@@ -26,8 +27,11 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.lsp4e.outline.SymbolsLabelProvider;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
@@ -46,6 +50,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
import org.springframework.tooling.ls.eclipse.gotosymbol.GotoSymbolPlugin;
import org.springsource.ide.eclipse.commons.livexp.core.UIValueListener;
import org.springsource.ide.eclipse.commons.livexp.ui.Disposable;
import org.springsource.ide.eclipse.commons.livexp.ui.Stylers;
import org.springsource.ide.eclipse.commons.livexp.ui.util.SwtConnect;
@SuppressWarnings("restriction")
@@ -78,7 +83,7 @@ public class GotoSymbolDialog extends PopupDialog {
}
}
private static class GotoSymbolsLabelProvider extends SymbolsLabelProvider {
private class GotoSymbolsLabelProvider extends SymbolsLabelProvider {
@Override
protected int getMaxSeverity(IResource resource, SymbolInformation symbolInformation)
throws CoreException, BadLocationException {
@@ -91,6 +96,21 @@ public class GotoSymbolDialog extends PopupDialog {
}
return maxSeverity;
}
@Override
public StyledString getStyledText(Object element) {
StyledString s = super.getStyledText(element);
if (element instanceof SymbolInformation) {
Optional<String> workspacePath = GotoSymbolDialog.this
.getWorkspaceLocation((SymbolInformation) element);
if (workspacePath.isPresent()) {
s.append(" -- [", Stylers.NULL);
s.append(workspacePath.get(), Stylers.NULL);
s.append("]", Stylers.NULL);
}
}
return s;
}
}
private static final Point DEFAULT_SIZE = new Point(280, 300);
@@ -199,6 +219,21 @@ public class GotoSymbolDialog extends PopupDialog {
list.addDoubleClickListener(e -> performOk(list));
}
private Optional<String> getWorkspaceLocation(SymbolInformation symbolInformation) {
String val = null;
if (!model.fromFileProvider(symbolInformation)) {
Location location = symbolInformation.getLocation();
IResource targetResource = LSPEclipseUtils.findResourceFor(location.getUri());
if (targetResource != null && targetResource.getFullPath() != null) {
val = targetResource.getFullPath().toString();
}
}
return val != null ? Optional.of(val) : Optional.empty();
}
private void performOk(TreeViewer list) {
if (model.performOk(getTarget(list))) {
close();

View File

@@ -182,6 +182,14 @@ public class GotoSymbolDialogModel {
public boolean performOk(SymbolInformation selection) {
return this.okHandler.performOk(selection);
}
public boolean fromFileProvider(SymbolInformation symbolInformation) {
SymbolsProvider sp = currentSymbolsProvider.getValue();
if (sp!=null) {
return sp.fromFile(symbolInformation);
}
return false;
}
}

View File

@@ -68,4 +68,13 @@ public class InFileSymbolsProvider implements SymbolsProvider {
public String getName() {
return "Symbols in File";
}
@Override
public boolean fromFile(SymbolInformation symbol) {
if (symbol != null && symbol.getLocation() != null) {
String symbolUri = symbol.getLocation().getUri();
return info.getFileUri().toString().equals(symbolUri);
}
return false;
}
}

View File

@@ -64,7 +64,6 @@ public class InWorkspaceSymbolsProvider implements SymbolsProvider {
// really use this with a single language server anyways.
WorkspaceSymbolParams params = new WorkspaceSymbolParams(query);
ImmutableList.Builder<SymbolInformation> allSymbols = ImmutableList.builder();
Flux<SymbolInformation> symbols = Flux.fromIterable(this.languageServers)
.flatMap(server -> Mono.fromFuture(server.getWorkspaceService().symbol(params))
.timeout(TIMEOUT)
@@ -108,4 +107,8 @@ public class InWorkspaceSymbolsProvider implements SymbolsProvider {
return null;
}
@Override
public boolean fromFile(SymbolInformation symbol) {
return false;
}
}

View File

@@ -22,4 +22,11 @@ import org.eclipse.lsp4j.SymbolInformation;
public interface SymbolsProvider {
String getName();
Collection<SymbolInformation> 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
* @return True if the symbol information is provided from a file provider (a file is the provider of the symbols). False otherwise
*/
boolean fromFile(SymbolInformation symbol);
}