PT #165911996: Switch to LocationLink from Location for definitions
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ import org.springframework.ide.vscode.bosh.models.ReleaseData;
|
||||
import org.springframework.ide.vscode.bosh.models.ReleasesModel;
|
||||
import org.springframework.ide.vscode.bosh.models.StemcellData;
|
||||
import org.springframework.ide.vscode.bosh.models.StemcellsModel;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.ExternalCommand;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems;
|
||||
@@ -1587,7 +1586,8 @@ public class BoshEditorTest {
|
||||
"- name: some-release\n"
|
||||
,
|
||||
"some-release"
|
||||
)
|
||||
),
|
||||
editor.rangeOf("- release: some-release", "some-release")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1612,7 +1612,8 @@ public class BoshEditorTest {
|
||||
|
||||
editor.assertGotoDefinition(
|
||||
editor.positionOf("stemcell: windoze", "windoze"),
|
||||
editor.rangeOf("- alias: windoze", "windoze")
|
||||
editor.rangeOf("- alias: windoze", "windoze"),
|
||||
editor.rangeOf("stemcell: windoze", "windoze")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user