PT #165911996: Switch to LocationLink from Location for definitions

This commit is contained in:
BoykoAlex
2019-10-04 18:34:09 -04:00
parent 2e73b4b66f
commit bb79221cfe
18 changed files with 228 additions and 113 deletions

View File

@@ -15,14 +15,18 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
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.definition.SimpleDefinitionFinder;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.util.BadLocationException;
import org.springframework.ide.vscode.commons.util.Log;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
import org.springframework.ide.vscode.commons.yaml.ast.NodeUtil;
import org.springframework.ide.vscode.commons.yaml.ast.YamlAstCache;
@@ -34,9 +38,9 @@ import org.yaml.snakeyaml.nodes.Node;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import reactor.core.publisher.Flux;
public class BoshDefintionFinder extends SimpleDefinitionFinder<SimpleLanguageServer> {
private static final Logger log = LoggerFactory.getLogger(BoshDefintionFinder.class);
//TODO: lots of common code between BoshDefintionFinder and ConcourseDefinitionFinder.
// should be possible to pull up into a common super class.
@@ -69,7 +73,7 @@ public class BoshDefintionFinder extends SimpleDefinitionFinder<SimpleLanguageSe
}
@Override
public List<Location> handle(TextDocumentPositionParams params) {
public List<LocationLink> handle(TextDocumentPositionParams params) {
try {
TextDocument doc = server.getTextDocumentService().get(params);
if (doc!=null) {
@@ -81,14 +85,19 @@ public class BoshDefintionFinder extends SimpleDefinitionFinder<SimpleLanguageSe
if (type!=null) {
Handler handler = handlers.get(type);
if (handler!=null) {
return handler.handle(refNode, doc, ast);
int start = refNode.getStartMark().getIndex();
int end = refNode.getEndMark().getIndex();
Range originalRange = doc.toRange(start, end - start);
return handler.handle(refNode, doc, ast).stream()
.map(l -> new LocationLink(l.getUri(), l.getRange(), l.getRange(), originalRange))
.collect(Collectors.toList());
}
}
}
}
}
} catch (Exception e) {
Log.log(e);
log.error("", e);;
}
return ImmutableList.of();
}
@@ -129,7 +138,7 @@ public class BoshDefintionFinder extends SimpleDefinitionFinder<SimpleLanguageSe
try {
return Optional.of(new Location(doc.getUri(), doc.toRange(start, end-start)));
} catch (BadLocationException e) {
Log.log(e);
log.error("", e);;
return Optional.empty();
}
}