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()));
|
||||
|
||||
Reference in New Issue
Block a user