PT #165911996: Switch to LocationLink from Location for definitions
This commit is contained in:
@@ -13,11 +13,13 @@ package org.springframework.ide.vscode.commons.languageserver.definition;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.LocationLink;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.TextDocumentPositionParams;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.DefinitionHandler;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -27,6 +29,8 @@ import com.google.common.collect.ImmutableList;
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
public class SimpleDefinitionFinder<T extends SimpleLanguageServer> implements DefinitionHandler {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SimpleDefinitionFinder.class);
|
||||
|
||||
protected final T server;
|
||||
|
||||
@@ -35,7 +39,7 @@ public class SimpleDefinitionFinder<T extends SimpleLanguageServer> implements D
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Location> handle(TextDocumentPositionParams params) {
|
||||
public List<LocationLink> handle(TextDocumentPositionParams params) {
|
||||
try {
|
||||
TextDocument doc = server.getTextDocumentService().get(params);
|
||||
if (doc != null) {
|
||||
@@ -50,19 +54,18 @@ public class SimpleDefinitionFinder<T extends SimpleLanguageServer> implements D
|
||||
end++;
|
||||
}
|
||||
String word = doc.textBetween(start, end);
|
||||
Log.log("Looking for definition of '"+word+"'");
|
||||
String text = doc.get();
|
||||
int def = text.indexOf(word);
|
||||
if (def>=0) {
|
||||
Location loc = new Location(params.getTextDocument().getUri(),
|
||||
doc.toRange(def, word.length())
|
||||
Range targetRange = doc.toRange(def, word.length());
|
||||
LocationLink link = new LocationLink(params.getTextDocument().getUri(),
|
||||
targetRange, targetRange, doc.toRange(start, end - start)
|
||||
);
|
||||
Log.log("definition: "+loc);
|
||||
return ImmutableList.of(loc);
|
||||
return ImmutableList.of(link);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
log.error("", e);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2019 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
|
||||
@@ -12,10 +12,10 @@ package org.springframework.ide.vscode.commons.languageserver.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.LocationLink;
|
||||
import org.eclipse.lsp4j.TextDocumentPositionParams;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface DefinitionHandler {
|
||||
List<Location> handle(TextDocumentPositionParams position);
|
||||
List<LocationLink> handle(TextDocumentPositionParams position);
|
||||
}
|
||||
|
||||
@@ -361,12 +361,12 @@ public class SimpleTextDocumentService implements TextDocumentService, DocumentE
|
||||
DefinitionHandler h = this.definitionHandler;
|
||||
if (h != null) {
|
||||
return async.invoke(() -> {
|
||||
List<Location> locations = h.handle(position);
|
||||
List<LocationLink> locations = h.handle(position);
|
||||
if (locations==null) {
|
||||
// vscode client does not like to recieve null result. See: https://github.com/spring-projects/sts4/issues/309
|
||||
locations = ImmutableList.of();
|
||||
}
|
||||
return Either.forLeft(locations);
|
||||
return Either.forRight(locations);
|
||||
});
|
||||
}
|
||||
return CompletableFuture.completedFuture(Either.forLeft(ImmutableList.of()));
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.eclipse.lsp4j.CompletionList;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.eclipse.lsp4j.DocumentSymbol;
|
||||
import org.eclipse.lsp4j.Hover;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.LocationLink;
|
||||
import org.eclipse.lsp4j.MarkedString;
|
||||
import org.eclipse.lsp4j.MarkupContent;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
@@ -745,7 +745,7 @@ public class Editor {
|
||||
return "Editor(\n"+getText()+"\n)";
|
||||
}
|
||||
|
||||
public void assertLinkTargets(String hoverOver, Set<Location> expectedLocations) throws Exception {
|
||||
public void assertLinkTargets(String hoverOver, Set<LocationLink> expectedLocations) throws Exception {
|
||||
int pos = getRawText().indexOf(hoverOver);
|
||||
if (pos>=0) {
|
||||
pos += hoverOver.length() / 2;
|
||||
@@ -753,7 +753,7 @@ public class Editor {
|
||||
assertTrue("Not found in editor: '"+hoverOver+"'", pos>=0);
|
||||
|
||||
TextDocumentPositionParams params = new TextDocumentPositionParams(new TextDocumentIdentifier(getUri()), doc.toPosition(pos));
|
||||
List<? extends Location> definitions = harness.getDefinitions(params);
|
||||
List<? extends LocationLink> definitions = harness.getDefinitions(params);
|
||||
|
||||
assertEquals(ImmutableSet.copyOf(expectedLocations), ImmutableSet.copyOf(definitions));
|
||||
}
|
||||
@@ -766,7 +766,7 @@ public class Editor {
|
||||
assertTrue("Not found in editor: '"+hoverOver+"'", pos>=0);
|
||||
|
||||
TextDocumentPositionParams params = new TextDocumentPositionParams(new TextDocumentIdentifier(getUri()), doc.toPosition(pos));
|
||||
List<? extends Location> definitions = harness.getDefinitions(params);
|
||||
List<? extends LocationLink> definitions = harness.getDefinitions(params);
|
||||
|
||||
assertTrue(definitions == null || definitions.isEmpty());
|
||||
}
|
||||
@@ -822,12 +822,12 @@ public class Editor {
|
||||
ignoredTypes.add(type.toString());
|
||||
}
|
||||
|
||||
public void assertGotoDefinition(Position pos, Range expectedTarget) throws Exception {
|
||||
public void assertGotoDefinition(Position pos, Range expectedTarget, Range highlightRange) throws Exception {
|
||||
TextDocumentIdentifier textDocumentId = doc.getId();
|
||||
TextDocumentPositionParams params = new TextDocumentPositionParams(textDocumentId, textDocumentId.getUri(), pos);
|
||||
List<? extends Location> defs = harness.getDefinitions(params);
|
||||
List<? extends LocationLink> defs = harness.getDefinitions(params);
|
||||
assertEquals(1, defs.size());
|
||||
assertEquals(new Location(textDocumentId.getUri(), expectedTarget), defs.get(0));
|
||||
assertEquals(new LocationLink(textDocumentId.getUri(), expectedTarget, expectedTarget, highlightRange), defs.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,7 +35,6 @@ import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@@ -75,6 +74,7 @@ import org.eclipse.lsp4j.Hover;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.LocationLink;
|
||||
import org.eclipse.lsp4j.MarkupContent;
|
||||
import org.eclipse.lsp4j.MessageActionItem;
|
||||
import org.eclipse.lsp4j.MessageParams;
|
||||
@@ -107,7 +107,6 @@ import org.springframework.ide.vscode.commons.languageserver.completion.Document
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LanguageServerTestListener;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.Settings;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.WorkspaceSymbolHandler;
|
||||
import org.springframework.ide.vscode.commons.protocol.CursorMovement;
|
||||
import org.springframework.ide.vscode.commons.protocol.HighlightParams;
|
||||
import org.springframework.ide.vscode.commons.protocol.ProgressParams;
|
||||
@@ -727,9 +726,9 @@ public class LanguageServerHarness {
|
||||
assertEquals(expected, completion.getLabel());
|
||||
}
|
||||
|
||||
public List<? extends Location> getDefinitions(TextDocumentPositionParams params) throws Exception {
|
||||
public List<? extends LocationLink> getDefinitions(TextDocumentPositionParams params) throws Exception {
|
||||
waitForReconcile(); //goto definitions relies on reconciler infos! Must wait or race condition breaking tests occasionally.
|
||||
return getServer().getTextDocumentService().definition(params).get().getLeft();
|
||||
return getServer().getTextDocumentService().definition(params).get().getRight();
|
||||
}
|
||||
|
||||
public static void assertDocumentation(String expected, CompletionItem completion) {
|
||||
|
||||
Reference in New Issue
Block a user