PT #165911996: Switch to LocationLink from Location for definitions
This commit is contained in:
@@ -14,13 +14,17 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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,6 +38,8 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
|
||||
public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<SimpleLanguageServer> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ConcourseDefinitionFinder.class);
|
||||
|
||||
@FunctionalInterface
|
||||
private interface Handler {
|
||||
@@ -84,7 +90,7 @@ public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<SimpleLang
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Location> handle(TextDocumentPositionParams params) {
|
||||
public List<LocationLink> handle(TextDocumentPositionParams params) {
|
||||
try {
|
||||
TextDocument doc = server.getTextDocumentService().get(params);
|
||||
if (doc!=null) {
|
||||
@@ -96,14 +102,19 @@ public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<SimpleLang
|
||||
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();
|
||||
}
|
||||
@@ -114,7 +125,7 @@ public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<SimpleLang
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 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
|
||||
@@ -46,7 +46,6 @@ import org.springframework.ide.vscode.languageserver.testharness.CodeAction;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.Editor;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.SynchronizationPoint;
|
||||
import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -3161,7 +3160,8 @@ public class ConcourseEditorTest {
|
||||
);
|
||||
|
||||
editor.assertGotoDefinition(editor.positionOf("get: my-git", "my-git"),
|
||||
editor.rangeOf("- name: my-git", "my-git")
|
||||
editor.rangeOf("- name: my-git", "my-git"),
|
||||
editor.rangeOf("get: my-git", "my-git")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3184,7 +3184,8 @@ public class ConcourseEditorTest {
|
||||
" - prepare-stuff\n"
|
||||
);
|
||||
editor.assertGotoDefinition(editor.positionOf("- prepare-stuff", "prepare-stuff"),
|
||||
editor.rangeOf("- name: prepare-stuff", "prepare-stuff")
|
||||
editor.rangeOf("- name: prepare-stuff", "prepare-stuff"),
|
||||
editor.rangeOf("- prepare-stuff", "prepare-stuff")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3199,7 +3200,8 @@ public class ConcourseEditorTest {
|
||||
" type: slack-notification\n"
|
||||
);
|
||||
editor.assertGotoDefinition(editor.positionOf("type: slack-notification", "slack-notification"),
|
||||
editor.rangeOf("- name: slack-notification", "slack-notification")
|
||||
editor.rangeOf("- name: slack-notification", "slack-notification"),
|
||||
editor.rangeOf("type: slack-notification", "slack-notification")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user