org.eclipse.lsp4j.DidOpenTextDocumentParams Java Examples
The following examples show how to use
org.eclipse.lsp4j.DidOpenTextDocumentParams.
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: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testLocalVariableDefinitionFromMethodCallObjectExpression() 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(" String localVar = \"hi\"\n"); contents.append(" localVar.charAt(0)\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(11, location.getRange().getStart().getCharacter()); Assertions.assertEquals(2, location.getRange().getEnd().getLine()); Assertions.assertEquals(19, location.getRange().getEnd().getCharacter()); }
Example #2
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 #3
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberAccessOnLocalVariableAfterDot() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public Completion() {\n"); contents.append(" String localVar\n"); contents.append(" 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(3, 13); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); Assertions.assertTrue(items.size() > 0); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("charAt") && item.getKind().equals(CompletionItemKind.Method); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #4
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberAccessOnMemberVariableAfterDot() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" String memberVar\n"); contents.append(" public Completion() {\n"); contents.append(" memberVar.\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, 14); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); Assertions.assertTrue(items.size() > 0); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("charAt") && item.getKind().equals(CompletionItemKind.Method); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #5
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberAccessOnThisAfterDot() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" String memberVar\n"); contents.append(" public Completion() {\n"); contents.append(" this.\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, 9); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); Assertions.assertTrue(items.size() > 0); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("memberVar") && item.getKind().equals(CompletionItemKind.Field); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #6
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberAccessOnClassAfterDot() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public Completion() {\n"); contents.append(" Completion.\n"); contents.append(" }\n"); contents.append(" public static void staticMethod() {}\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, 15); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); Assertions.assertTrue(items.size() > 0); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("staticMethod") && item.getKind().equals(CompletionItemKind.Method); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #7
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberAccessOnLocalArrayAfterDot() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public Completion() {\n"); contents.append(" String[] localVar\n"); contents.append(" localVar[0].\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, 16); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); Assertions.assertTrue(items.size() > 0); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("charAt") && item.getKind().equals(CompletionItemKind.Method); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #8
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberAccessOnLocalVariableWithPartialPropertyExpression() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public Completion() {\n"); contents.append(" String localVar\n"); contents.append(" localVar.charA\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, 18); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("charAt") && item.getKind().equals(CompletionItemKind.Method); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #9
Source File: GroovyServicesTypeDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberMethodTypeDefinitionFromCall() 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(" public TypeDefinitions() {\n"); contents.append(" 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(4, 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(6, location.getRange().getEnd().getLine()); Assertions.assertEquals(1, location.getRange().getEnd().getCharacter()); }
Example #10
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testCompletionForParameterOnCompleteVariableExpression() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public void testMethod(String paramName) {\n"); contents.append(" paramName\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, 13); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("paramName") && item.getKind().equals(CompletionItemKind.Variable); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #11
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testCompletionForLocalVariableOnPartialVariableExpression() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public void testMethod(String paramName) {\n"); contents.append(" String localVar\n"); contents.append(" loc\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, 7); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("localVar") && item.getKind().equals(CompletionItemKind.Variable); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #12
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testCompletionForLocalVariableOnCompleteVariableExpression() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public void testMethod() {\n"); contents.append(" String localVar\n"); contents.append(" 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(3, 12); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("localVar") && item.getKind().equals(CompletionItemKind.Variable); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #13
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testCompletionForLocalVariableOnPartialVariableExpressionInsideBlock() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public void testMethod(String paramName) {\n"); contents.append(" String localVar\n"); contents.append(" if(true) {\n"); contents.append(" loc\n"); contents.append(" }\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(4, 9); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("localVar") && item.getKind().equals(CompletionItemKind.Variable); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #14
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 #15
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 #16
Source File: EditorEventManager.java From lsp4intellij with Apache License 2.0 | 6 votes |
public void documentOpened() { pool(() -> { if (editor.isDisposed()) { return; } if (isOpen) { LOG.warn("Editor " + editor + " was already open"); } else { final String extension = FileDocumentManager.getInstance().getFile(editor.getDocument()).getExtension(); requestManager.didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(identifier.getUri(), wrapper.serverDefinition.languageIdFor(extension), version++, editor.getDocument().getText()))); isOpen = true; } }); }
Example #17
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 #18
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberVariableDefinitionFromDeclaration() 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 int memberVar\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, 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(1, location.getRange().getStart().getLine()); Assertions.assertEquals(2, location.getRange().getStart().getCharacter()); Assertions.assertEquals(1, location.getRange().getEnd().getLine()); Assertions.assertEquals(22, location.getRange().getEnd().getCharacter()); }
Example #19
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberVariableDefinitionFromAssignment() 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 int memberVar\n"); contents.append(" public Definitions() {\n"); contents.append(" memberVar = 123\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(22, location.getRange().getEnd().getCharacter()); }
Example #20
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 #21
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 #22
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testClassDefinitionFromDeclaration() throws Exception { Path filePath = srcRoot.resolve("Definitions.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Definitions {\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(0, 8); 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(1, location.getRange().getEnd().getLine()); Assertions.assertEquals(1, location.getRange().getEnd().getCharacter()); }
Example #23
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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
Source File: GroovyServicesDefinitionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testDefinitionFromArrayItemMemberAccess() 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[] items\n"); contents.append(" items[0].hello\n"); contents.append(" }\n"); contents.append(" public String hello\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, 15); 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(5, location.getRange().getStart().getLine()); Assertions.assertEquals(2, location.getRange().getStart().getCharacter()); Assertions.assertEquals(5, location.getRange().getEnd().getLine()); Assertions.assertEquals(21, location.getRange().getEnd().getCharacter()); }
Example #30
Source File: DocumentLifeCycleHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public ICompilationUnit handleOpen(DidOpenTextDocumentParams params) { ICompilationUnit unit = super.handleOpen(params); if (unit == null || unit.getResource() == null || unit.getResource().isDerived()) { return unit; } try { installSemanticHighlightings(unit); } catch (JavaModelException | BadPositionCategoryException e) { JavaLanguageServerPlugin.logException("Error while opening document. URI: " + params.getTextDocument().getUri(), e); } return unit; }