Goto definition iin pipeline editor, working for resources
This commit is contained in:
@@ -31,9 +31,12 @@ import org.eclipse.lsp4j.CompletionItem;
|
||||
import org.eclipse.lsp4j.CompletionList;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.eclipse.lsp4j.Hover;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.PublishDiagnosticsParams;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.TextDocumentPositionParams;
|
||||
import org.eclipse.lsp4j.TextEdit;
|
||||
import org.junit.Assert;
|
||||
|
||||
@@ -498,4 +501,43 @@ public class Editor {
|
||||
ignoredTypes.add(type.toString());
|
||||
}
|
||||
|
||||
public void assertGotoDefinition(Position pos, Range expectedTarget) throws Exception {
|
||||
TextDocumentIdentifier textDocumentId = document.getId();
|
||||
TextDocumentPositionParams params = new TextDocumentPositionParams(textDocumentId, textDocumentId.getUri(), pos);
|
||||
List<? extends Location> defs = harness.getDefinitions(params);
|
||||
assertEquals(1, defs.size());
|
||||
assertEquals(new Location(textDocumentId.getUri(), expectedTarget), defs.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the position of (the middle of) a snippet of text in the document.
|
||||
*
|
||||
* @param contextSnippet A larger snippet containing the actual snippet to look for.
|
||||
* This larger snippet is used to narrow the section of the document
|
||||
* where we look for the actual snippet. This is useful when the snippet
|
||||
* occurs multiple times in the document.
|
||||
* @param focusSnippet The snippet to look for
|
||||
*/
|
||||
public Position positionOf(String longSnippet, String focusSnippet) throws Exception {
|
||||
Range r = rangeOf(longSnippet, focusSnippet);
|
||||
return r==null?null:r.getStart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the range of a snippet of text in the document.
|
||||
*
|
||||
* @param contextSnippet A larger snippet containing the actual snippet to look for.
|
||||
* This larger snippet is used to narrow the section of the document
|
||||
* where we look for the actual snippet. This is useful when the snippet
|
||||
* occurs multiple times in the document.
|
||||
* @param focusSnippet The snippet to look for
|
||||
*/
|
||||
public Range rangeOf(String longSnippet, String focusSnippet) throws Exception {
|
||||
int relativeOffset = longSnippet.indexOf(focusSnippet);
|
||||
int contextStart = getRawText().indexOf(longSnippet);
|
||||
Assert.assertTrue("'"+longSnippet+"' not found in editor", contextStart>=0);
|
||||
int start = contextStart+relativeOffset;
|
||||
return new Range(document.toPosition(start), document.toPosition(start+focusSnippet.length()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
@@ -38,6 +39,7 @@ import org.eclipse.lsp4j.DidOpenTextDocumentParams;
|
||||
import org.eclipse.lsp4j.Hover;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.MessageParams;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.PublishDiagnosticsParams;
|
||||
@@ -375,4 +377,8 @@ public class LanguageServerHarness {
|
||||
assertEquals(expected, completion.getLabel());
|
||||
}
|
||||
|
||||
public List<? extends Location> getDefinitions(TextDocumentPositionParams params) throws Exception {
|
||||
return server.getTextDocumentService().definition(params).get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user