org.eclipse.lsp4j.TextDocumentPositionParams Java Examples
The following examples show how to use
org.eclipse.lsp4j.TextDocumentPositionParams.
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: 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 #2
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testLocalVariableDefinitionFromMethodCallArgument() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public Definitions() {\n"); contents.append(" int localVar\n"); contents.append(" this.method(localVar)\n"); contents.append(" }\n"); contents.append(" public void method(int param) {}\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(3, 18); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(2, location.getRange().getStart().getLine()); Assertions.assertEquals(8, location.getRange().getStart().getCharacter()); Assertions.assertEquals(2, location.getRange().getEnd().getLine()); Assertions.assertEquals(16, location.getRange().getEnd().getCharacter()); }
Example #3
Source File: XContentAssistService.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Create the completion proposals. */ public CompletionList createCompletionList(Document document, XtextResource resource, TextDocumentPositionParams params, CancelIndicator cancelIndicator) { CompletionList result = new CompletionList(); result.setIsIncomplete(false); // we set isInComplete to true, so we get asked always, which is the best match to the expected behavior in // Xtext XIdeContentProposalAcceptor acceptor = new XIdeContentProposalAcceptor(cancelIndicator); int caretOffset = document.getOffSet(params.getPosition()); Position caretPosition = params.getPosition(); TextRegion position = new TextRegion(caretOffset, 0); try { createProposals(document.getContents(), position, caretOffset, resource, acceptor); } catch (Throwable t) { if (!operationCanceledManager.isOperationCanceledException(t)) { throw t; } } operationCanceledManager.checkCanceled(cancelIndicator); IterableExtensions.forEach(acceptor.getEntries(), (it, idx) -> { CompletionItem item = toCompletionItem(it, caretOffset, caretPosition, document); item.setSortText(Strings.padStart(Integer.toString(idx.intValue()), 5, '0')); result.getItems().add(item); }); return result; }
Example #4
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testLocalVariableDefinitionFromDeclaration() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public Definitions() {\n"); contents.append(" int localVar\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(2, 14); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(2, location.getRange().getStart().getLine()); Assertions.assertEquals(8, location.getRange().getStart().getCharacter()); Assertions.assertEquals(2, location.getRange().getEnd().getLine()); Assertions.assertEquals(16, location.getRange().getEnd().getCharacter()); }
Example #5
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testLocalVariableDefinitionFromAssignment() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public Definitions() {\n"); contents.append(" int localVar\n"); contents.append(" localVar = 123\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(3, 6); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(2, location.getRange().getStart().getLine()); Assertions.assertEquals(8, location.getRange().getStart().getCharacter()); Assertions.assertEquals(2, location.getRange().getEnd().getLine()); Assertions.assertEquals(16, location.getRange().getEnd().getCharacter()); }
Example #6
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testInvalidJavadoc() throws Exception { importProjects("maven/aspose"); IProject project = null; ICompilationUnit unit = null; try { project = ResourcesPlugin.getWorkspace().getRoot().getProject("aspose"); IJavaProject javaProject = JavaCore.create(project); IType type = javaProject.findType("org.sample.TestJavadoc"); unit = type.getCompilationUnit(); unit.becomeWorkingCopy(null); String uri = JDTUtils.toURI(unit); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); TextDocumentPositionParams position = new TextDocumentPositionParams(textDocument, new Position(8, 24)); Hover hover = handler.hover(position, monitor); assertNotNull(hover); assertNotNull(hover.getContents()); assertEquals(1, hover.getContents().getLeft().size()); assertEquals("com.aspose.words.Document.Document(String fileName) throws Exception", hover.getContents().getLeft().get(0).getRight().getValue()); } finally { if (unit != null) { unit.discardWorkingCopy(); } } }
Example #7
Source File: GroovyServicesTypeDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberMethodTypeDefinitionFromDeclaration() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class TypeDefinitions {\n"); contents.append(" public TypeDefinitions memberMethod() {\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(1, 27); List<? extends Location> locations = services .typeDefinition(new TextDocumentPositionParams(textDocument, position)).get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(0, location.getRange().getStart().getLine()); Assertions.assertEquals(0, location.getRange().getStart().getCharacter()); Assertions.assertEquals(3, location.getRange().getEnd().getLine()); Assertions.assertEquals(1, location.getRange().getEnd().getCharacter()); }
Example #8
Source File: GroovyServicesTypeDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberVariableTypeDefinitionFromAssignment() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class TypeDefinitions {\n"); contents.append(" TypeDefinitions memberVar\n"); contents.append(" public TypeDefinitions() {\n"); contents.append(" memberVar = null\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(3, 6); List<? extends Location> locations = services .typeDefinition(new TextDocumentPositionParams(textDocument, position)).get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(0, location.getRange().getStart().getLine()); Assertions.assertEquals(0, location.getRange().getStart().getCharacter()); Assertions.assertEquals(5, location.getRange().getEnd().getLine()); Assertions.assertEquals(1, location.getRange().getEnd().getCharacter()); }
Example #9
Source File: GroovyServicesTypeDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberVariableTypeDefinitionFromDeclaration() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class TypeDefinitions {\n"); contents.append(" TypeDefinitions memberVar\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(1, 20); List<? extends Location> locations = services .typeDefinition(new TextDocumentPositionParams(textDocument, position)).get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(0, location.getRange().getStart().getLine()); Assertions.assertEquals(0, location.getRange().getStart().getCharacter()); Assertions.assertEquals(2, location.getRange().getEnd().getLine()); Assertions.assertEquals(1, location.getRange().getEnd().getCharacter()); }
Example #10
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverOnJavadocWithValueTag() throws Exception { importProjects("maven/salut"); project = WorkspaceHelper.getProject("salut"); handler = new HoverHandler(preferenceManager); //given String payload = createHoverRequest("src/main/java/java/Foo2.java", 12, 30); TextDocumentPositionParams position = getParams(payload); // when Hover hover = handler.hover(position, monitor); assertNotNull("Hover is null", hover); assertEquals("Unexpected hover contents:\n" + hover.getContents(), 2, hover.getContents().getLeft().size()); Either<String, MarkedString> javadoc = hover.getContents().getLeft().get(1); String content = null; assertTrue("javadoc has null content", javadoc != null && javadoc.getLeft() != null && (content = javadoc.getLeft()) != null); assertMatches("\\[\"SimpleStringData\"\\]\\(file:/.*/salut/src/main/java/java/Foo2.java#13\\) is a simple String", content); }
Example #11
Source File: GroovyServicesTypeDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testLocalVariableTypeDefinitionFromAssignment() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class TypeDefinitions {\n"); contents.append(" public TypeDefinitions() {\n"); contents.append(" TypeDefinitions localVar\n"); contents.append(" localVar = null\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(3, 6); List<? extends Location> locations = services .typeDefinition(new TextDocumentPositionParams(textDocument, position)).get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(0, location.getRange().getStart().getLine()); Assertions.assertEquals(0, location.getRange().getStart().getCharacter()); Assertions.assertEquals(5, location.getRange().getEnd().getLine()); Assertions.assertEquals(1, location.getRange().getEnd().getCharacter()); }
Example #12
Source File: GroovyServicesTypeDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testLocalVariableTypeDefinitionFromDeclaration() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class TypeDefinitions {\n"); contents.append(" public TypeDefinitions() {\n"); contents.append(" TypeDefinitions localVar\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(2, 22); List<? extends Location> locations = services .typeDefinition(new TextDocumentPositionParams(textDocument, position)).get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(0, location.getRange().getStart().getLine()); Assertions.assertEquals(0, location.getRange().getStart().getCharacter()); Assertions.assertEquals(4, location.getRange().getEnd().getLine()); Assertions.assertEquals(1, location.getRange().getEnd().getCharacter()); }
Example #13
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverThrowable() throws Exception { String uriString = ClassFileUtil.getURI(project, "java.lang.Exception"); IClassFile classFile = JDTUtils.resolveClassFile(uriString); String contents = JavaLanguageServerPlugin.getContentProviderManager().getSource(classFile, monitor); IDocument document = new Document(contents); IRegion region = new FindReplaceDocumentAdapter(document).find(0, "Throwable", true, false, false, false); int offset = region.getOffset(); int line = document.getLineOfOffset(offset); int character = offset - document.getLineOffset(line); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uriString); Position position = new Position(line, character); TextDocumentPositionParams params = new TextDocumentPositionParams(textDocument, position); Hover hover = handler.hover(params, monitor); assertNotNull(hover); assertTrue("Unexpected hover ", !hover.getContents().getLeft().isEmpty()); }
Example #14
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 #15
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverOnJava10var() throws Exception { importProjects("eclipse/java10"); project = WorkspaceHelper.getProject("java10"); assertNoErrors(project); handler = new HoverHandler(preferenceManager); //given //Hovers on name.toUpperCase() String payload = createHoverRequest("src/main/java/foo/bar/Foo.java", 8, 34); TextDocumentPositionParams position = getParams(payload); //when Hover hover = handler.hover(position, monitor); assertNotNull(hover); assertNotNull(hover.toString(), hover.getContents().getLeft().get(0).getRight()); String javadoc = hover.getContents().getLeft().get(0).getRight().getValue(); assertEquals("String java.lang.String.toUpperCase()", javadoc); }
Example #16
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberMethodDefinitionFromDeclaration() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public void memberMethod() {}\n"); contents.append("}\n"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(1, 16); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(1, location.getRange().getStart().getLine()); Assertions.assertEquals(2, location.getRange().getStart().getCharacter()); Assertions.assertEquals(1, location.getRange().getEnd().getLine()); Assertions.assertEquals(31, location.getRange().getEnd().getCharacter()); }
Example #17
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberMethodDefinitionFromCall() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public void memberMethod() {}\n"); contents.append(" public Definitions() {\n"); contents.append(" memberMethod()\n"); contents.append(" }\n"); contents.append("}\n"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(3, 6); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(1, location.getRange().getStart().getLine()); Assertions.assertEquals(2, location.getRange().getStart().getCharacter()); Assertions.assertEquals(1, location.getRange().getEnd().getLine()); Assertions.assertEquals(31, location.getRange().getEnd().getCharacter()); }
Example #18
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverVariable() throws Exception { //given //Hover on args parameter String argParam = createHoverRequest("src/java/Foo.java", 7, 37); TextDocumentPositionParams position = getParams(argParam); //when Hover hover = handler.hover(position, monitor); //then assertNotNull(hover); assertNotNull(hover.getContents()); MarkedString signature = hover.getContents().getLeft().get(0).getRight(); assertEquals("Unexpected hover " + signature, "java", signature.getLanguage()); assertEquals("Unexpected hover " + signature, "String[] args - java.Foo.main(String[])", signature.getValue()); }
Example #19
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testConstructorDefinitionFromConstructorCall() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public Definitions() {\n"); contents.append(" new Definitions()\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(2, 10); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(1, location.getRange().getStart().getLine()); Assertions.assertEquals(2, location.getRange().getStart().getCharacter()); Assertions.assertEquals(3, location.getRange().getEnd().getLine()); Assertions.assertEquals(3, location.getRange().getEnd().getCharacter()); }
Example #20
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testClassDefinitionFromVariableDeclaration() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public Definitions() {\n"); contents.append(" Definitions d\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(2, 6); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(0, location.getRange().getStart().getLine()); Assertions.assertEquals(0, location.getRange().getStart().getCharacter()); Assertions.assertEquals(4, location.getRange().getEnd().getLine()); Assertions.assertEquals(1, location.getRange().getEnd().getCharacter()); }
Example #21
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testClassDefinitionFromClassExpression() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public static void staticMethod() {}\n"); contents.append(" public Definitions() {\n"); contents.append(" Definitions.staticMethod()\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(3, 6); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(0, location.getRange().getStart().getLine()); Assertions.assertEquals(0, location.getRange().getStart().getCharacter()); Assertions.assertEquals(5, location.getRange().getEnd().getLine()); Assertions.assertEquals(1, location.getRange().getEnd().getCharacter()); }
Example #22
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testParameterDefinitionFromDeclarationInConstructor() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public Definitions(int param) {\n"); contents.append(" }\n"); contents.append("}\n"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(1, 27); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(1, location.getRange().getStart().getLine()); Assertions.assertEquals(21, location.getRange().getStart().getCharacter()); Assertions.assertEquals(1, location.getRange().getEnd().getLine()); Assertions.assertEquals(30, location.getRange().getEnd().getCharacter()); }
Example #23
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testParameterDefinitionFromDeclarationInMethod() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public void memberMethod(int param) {\n"); contents.append(" }\n"); contents.append("}\n"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(1, 33); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(1, location.getRange().getStart().getLine()); Assertions.assertEquals(27, location.getRange().getStart().getCharacter()); Assertions.assertEquals(1, location.getRange().getEnd().getLine()); Assertions.assertEquals(36, location.getRange().getEnd().getCharacter()); }
Example #24
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testParameterDefinitionFromReference() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\n"); contents.append(" public void memberMethod(int param) {\n"); contents.append(" param\n"); contents.append(" }\n"); contents.append("}\n"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(2, 6); List<? extends Location> locations = services.definition(new TextDocumentPositionParams(textDocument, position)) .get().getLeft(); Assertions.assertEquals(1, locations.size()); Location location = locations.get(0); Assertions.assertEquals(uri, location.getUri()); Assertions.assertEquals(1, location.getRange().getStart().getLine()); Assertions.assertEquals(27, location.getRange().getStart().getCharacter()); Assertions.assertEquals(1, location.getRange().getEnd().getLine()); Assertions.assertEquals(36, location.getRange().getEnd().getCharacter()); }
Example #25
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 #26
Source File: FindLinksHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testNoSuperMethod() throws JavaModelException { IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null); //@formatter:off ICompilationUnit unitA = pack1.createCompilationUnit("A.java", "package test1;\n" + "\n" + "public class A {\n" + " public void run() {\n" + " }\n" + "}", true, null); //@formatter:on String uri = JDTUtils.toURI(unitA); List<? extends Location> response = FindLinksHandler.findLinks("superImplementation", new TextDocumentPositionParams(new TextDocumentIdentifier(uri), new Position(3, 14)), new NullProgressMonitor()); assertTrue(response == null || response.isEmpty()); }
Example #27
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHover() throws Exception { //given //Hovers on the System.out String payload = createHoverRequest("src/java/Foo.java", 5, 15); TextDocumentPositionParams position = getParams(payload); //when Hover hover = handler.hover(position, monitor); //then assertNotNull(hover); assertNotNull(hover.getContents()); MarkedString signature = hover.getContents().getLeft().get(0).getRight(); assertEquals("Unexpected hover " + signature, "java", signature.getLanguage()); assertEquals("Unexpected hover " + signature, "java.Foo", signature.getValue()); String doc = hover.getContents().getLeft().get(1).getLeft(); assertEquals("Unexpected hover " + doc, "This is foo", doc); }
Example #28
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverWhenLinkDoesNotExist() throws Exception { importProjects("maven/salut"); project = WorkspaceHelper.getProject("salut"); handler = new HoverHandler(preferenceManager); //given String payload = createHoverRequest("src/main/java/java/Foo2.java", 51, 25); TextDocumentPositionParams position = getParams(payload); // when Hover hover = handler.hover(position, monitor); assertNotNull("Hover is null", hover); assertEquals("Unexpected hover contents:\n" + hover.getContents(), 2, hover.getContents().getLeft().size()); Either<String, MarkedString> javadoc = hover.getContents().getLeft().get(1); String content = null; assertTrue("javadoc has null content", javadoc != null && javadoc.getLeft() != null && (content = javadoc.getLeft()) != null); assertMatches("This link doesnt work LinkToSomethingNotFound", content); }
Example #29
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 #30
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverWithAttachedJavadoc() throws Exception { File commonPrimitivesJdoc = DependencyUtil.getJavadoc("commons-primitives", "commons-primitives", "1.0"); assertNotNull("Unable to locate commons-primitives-1.0-javadoc.jar", commonPrimitivesJdoc); importProjects("maven/attached-javadoc"); project = WorkspaceHelper.getProject("attached-javadoc"); handler = new HoverHandler(preferenceManager); //given //Hovers on org.apache.commons.collections.primitives.ShortCollections which has no source but an attached javadoc String payload = createHoverRequest("src/main/java/org/sample/Bar.java", 2, 56); TextDocumentPositionParams position = getParams(payload); // when Hover hover = handler.hover(position, monitor); assertNotNull("Hover is null", hover); assertEquals("Unexpected hover contents:\n" + hover.getContents(), 2, hover.getContents().getLeft().size()); Either<String, MarkedString> javadoc = hover.getContents().getLeft().get(1); String content = null; assertTrue("javadoc has null content", javadoc != null && javadoc.getLeft() != null && (content = javadoc.getLeft()) != null); assertTrue("Unexpected hover :\n" + content, content.contains("This class consists exclusively of static methods that operate on or return ShortCollections")); assertTrue("Unexpected hover :\n" + content, content.contains("**Author:**")); }