Java Code Examples for org.eclipse.lsp4j.TextDocumentPositionParams#setPosition()
The following examples show how to use
org.eclipse.lsp4j.TextDocumentPositionParams#setPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefinitionTest.java From n4js with Eclipse Public License 1.0 | 6 votes |
/***/ @Test public void testDefinition_04() throws Exception { testWorkspaceManager.createTestProjectOnDisk(Collections.emptyMap()); startAndWaitForLspServer(); TextDocumentPositionParams textDocumentPositionParams = new TextDocumentPositionParams(); textDocumentPositionParams.setTextDocument(new TextDocumentIdentifier("n4scheme:/builtin_js.n4ts")); // see position from test above textDocumentPositionParams.setPosition(new Position(838, 15)); CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definitionsFuture = languageServer .definition(textDocumentPositionParams); Either<List<? extends Location>, List<? extends LocationLink>> definitions = definitionsFuture.get(); File root = getRoot(); String actualSignatureHelp = new StringLSP4J(root).toString4(definitions); assertEquals("(n4scheme:/builtin_js.n4ts, [838:15 - 838:21])", actualSignatureHelp.trim()); }
Example 2
Source File: AbstractDefinitionTest.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected void performTest(Project project, String moduleName, DefinitionTestConfiguration dtc) throws InterruptedException, ExecutionException, URISyntaxException { TextDocumentPositionParams textDocumentPositionParams = new TextDocumentPositionParams(); String completeFileUri = getFileURIFromModuleName(dtc.getFilePath()).toString(); textDocumentPositionParams.setTextDocument(new TextDocumentIdentifier(completeFileUri)); textDocumentPositionParams.setPosition(new Position(dtc.getLine(), dtc.getColumn())); CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definitionsFuture = languageServer .definition(textDocumentPositionParams); Either<List<? extends Location>, List<? extends LocationLink>> definitions = definitionsFuture.get(); if (dtc.getAssertDefinitions() != null) { dtc.getAssertDefinitions().apply(definitions.getLeft()); } else { String actualSignatureHelp = getStringLSP4J().toString4(definitions); assertEquals(dtc.getExpectedDefinitions().trim(), actualSignatureHelp.trim()); } }
Example 3
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testInterfaceImplementation() { URI uri = project.getFile("src/org/sample/IFoo.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(2, 20)); //Position over IFoo param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); assertEquals(2, implementations.size()); Location foo2 = implementations.get(0); assertTrue("Unexpected implementation : " + foo2.getUri(), foo2.getUri().contains("org/sample/Foo2.java")); assertEquals(JDTUtils.newLineRange(2, 13, 17), foo2.getRange()); Location foo3 = implementations.get(1); assertTrue("Unexpected implementation : " + foo3.getUri(), foo3.getUri().contains("org/sample/Foo3.java")); assertEquals(JDTUtils.newLineRange(5, 13, 17), foo3.getRange()); }
Example 4
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testMethodImplementation() { URI uri = project.getFile("src/org/sample/IFoo.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(4, 14)); //Position over IFoo#someMethod param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); assertEquals(implementations.toString(), 1, implementations.size()); Location foo2 = implementations.get(0); assertTrue("Unexpected implementation : " + foo2.getUri(), foo2.getUri().contains("org/sample/Foo2.java")); //check range points to someMethod() position assertEquals(new Position(4, 16), foo2.getRange().getStart()); assertEquals(new Position(4, 26), foo2.getRange().getEnd()); }
Example 5
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testMethodInvocationImplementation() { URI uri = project.getFile("src/org/sample/FooService.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(6, 14)); //Position over foo.someMethod param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); assertEquals(implementations.toString(), 1, implementations.size()); Location foo2 = implementations.get(0); assertTrue("Unexpected implementation : " + foo2.getUri(), foo2.getUri().contains("org/sample/Foo2.java")); //check range points to someMethod() position assertEquals(new Position(4, 16), foo2.getRange().getStart()); assertEquals(new Position(4, 26), foo2.getRange().getEnd()); }
Example 6
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testMethodSuperInvocationImplementation() { URI uri = project.getFile("src/org/sample/FooChild.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(5, 14)); //Position over super.someMethod param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); assertEquals(implementations.toString(), 1, implementations.size()); Location foo = implementations.get(0); assertTrue("Unexpected implementation : " + foo.getUri(), foo.getUri().contains("org/sample/Foo.java")); //check range points to someMethod() position assertEquals(new Position(8, 13), foo.getRange().getStart()); assertEquals(new Position(8, 23), foo.getRange().getEnd()); }
Example 7
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testClassImplementation_includeDefinition() { URI uri = project.getFile("src/org/sample/FooService.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(10, 20)); //Position over new Foo() param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); assertEquals(implementations.toString(), 2, implementations.size()); Location foo = implementations.get(0); assertTrue("Unexpected implementation : " + foo.getUri(), foo.getUri().contains("org/sample/Foo.java")); //check range points to Foo class declaration position assertEquals(new Position(2, 13), foo.getRange().getStart()); assertEquals(new Position(2, 16), foo.getRange().getEnd()); foo = implementations.get(1); assertTrue("Unexpected implementation : " + foo.getUri(), foo.getUri().contains("org/sample/FooChild.java")); //check range points to FooChild class declaration position assertEquals(new Position(2, 13), foo.getRange().getStart()); assertEquals(new Position(2, 21), foo.getRange().getEnd()); }
Example 8
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testMethodImplementation_includeDefinition() { URI uri = project.getFile("src/org/sample/FooService.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(11, 13)); //Position over someMethod() param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); assertEquals(implementations.toString(), 2, implementations.size()); Location foo = implementations.get(0); assertTrue("Unexpected implementation : " + foo.getUri(), foo.getUri().contains("org/sample/Foo.java")); //check range points to someMethod() position assertEquals(new Position(8, 13), foo.getRange().getStart()); assertEquals(new Position(8, 23), foo.getRange().getEnd()); foo = implementations.get(1); assertTrue("Unexpected implementation : " + foo.getUri(), foo.getUri().contains("org/sample/FooChild.java")); //check range points to someMethod() position assertEquals(new Position(4, 13), foo.getRange().getStart()); assertEquals(new Position(4, 23), foo.getRange().getEnd()); }
Example 9
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testUnimplementedClassImplementation_includeDefinition() { URI uri = project.getFile("src/org/sample/FooService.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(14, 13)); //Position over AbstractFoo. param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); assertEquals(implementations.toString(), 1, implementations.size()); Location foo = implementations.get(0); assertTrue("Unexpected implementation : " + foo.getUri(), foo.getUri().contains("org/sample/AbstractFoo.java")); //check range points to AbstractFoo class declaration position assertEquals(new Position(2, 22), foo.getRange().getStart()); assertEquals(new Position(2, 33), foo.getRange().getEnd()); }
Example 10
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testUnimplementedMethodImplementation_includeDefinition() { URI uri = project.getFile("src/org/sample/FooService.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(15, 13)); //Position over someMethod() param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); assertEquals(implementations.toString(), 1, implementations.size()); Location foo = implementations.get(0); assertTrue("Unexpected implementation : " + foo.getUri(), foo.getUri().contains("org/sample/AbstractFoo.java")); //check range points to someMethod() position assertEquals(new Position(4, 15), foo.getRange().getStart()); assertEquals(new Position(4, 25), foo.getRange().getEnd()); }
Example 11
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testEmpty(){ TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(1, 1)); param.setTextDocument(new TextDocumentIdentifier("/foo/bar")); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull(implementations); assertTrue("implementations are not empty", implementations.isEmpty()); }
Example 12
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassImplementation() { URI uri = project.getFile("src/org/sample/Foo2.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(2, 14)); //Position over Foo2 param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); assertEquals(implementations.toString(), 1, implementations.size()); Location foo3 = implementations.get(0); assertTrue("Unexpected implementation : " + foo3.getUri(), foo3.getUri().contains("org/sample/Foo3.java")); assertEquals(JDTUtils.newLineRange(5, 13, 17), foo3.getRange()); }
Example 13
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private List<? extends Location> getRunnableImplementations() { URI uri = project.getFile("src/org/sample/RunnableTest.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(2, 42));//implementations of java.lang.Runnable param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); return implementations; }
Example 14
Source File: ImplementationsHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testInvalidElement() { URI uri = project.getFile("src/org/sample/Foo4.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); TextDocumentPositionParams param = new TextDocumentPositionParams(); param.setPosition(new Position(3, 34)); //Position over T param.setTextDocument(new TextDocumentIdentifier(fileURI)); List<? extends Location> implementations = handler.findImplementations(param, monitor); assertNotNull("findImplementations should not return null", implementations); assertEquals(implementations.toString(), 0, implementations.size()); }