org.eclipse.lsp4j.TextDocumentItem Java Examples

The following examples show how to use org.eclipse.lsp4j.TextDocumentItem. 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 Project: lsp4intellij   Author: ballerina-platform   File: EditorEventManager.java    License: Apache License 2.0 6 votes vote down vote up
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 #2
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesTypeDefinitionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 #3
Source Project: syndesis   Author: syndesisio   File: TeiidDdlTextDocumentService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(
        CompletionParams completionParams) {
    String uri = completionParams.getTextDocument().getUri();
    LOGGER.debug("completion: {}", uri);
    TextDocumentItem doc = openedDocuments.get(uri);

    // get applicable completion items
    List<CompletionItem> items = completionProvider.getCompletionItems(doc.getText(),
            completionParams.getPosition());

    // if items exist, return them
    if (items != null && !items.isEmpty()) {
        return CompletableFuture.completedFuture(Either.forLeft(items));
    }

    // if items do no exist return empty results
    return CompletableFuture.completedFuture(Either.forLeft(Collections.emptyList()));
}
 
Example #4
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 #5
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: camel-language-server   Author: camel-tooling   File: CamelKYamlDSLParser.java    License: Apache License 2.0 6 votes vote down vote up
public String getCorrespondingType(TextDocumentItem textDocumentItem, int lineNumber) {
	for (int lineNo = lineNumber; lineNo >=0; lineNo--) {
		String tempLine = parserFileHelperUtil.getLine(textDocumentItem, lineNo);
		Map<?, ?> data = parseYaml(tempLine);
		if (data != null) {
			if (data.containsKey(TO_KEY)) {
				return "to";
			} else if (data.containsKey(FROM_KEY)) {
				return "from";
			} else if (data.containsKey(REST_KEY)) {
				return null;
			}
		}
	}
	return null;
}
 
Example #7
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void testMemberAccessOnLocalVariableWithExistingMethodCallExpressionOnNextLine() 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("    method()\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 #9
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void testCompletionForMemberVariableOnPartialVariableExpression() 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("    mem\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("memberVar") && item.getKind().equals(CompletionItemKind.Field);
	}).collect(Collectors.toList());
	Assertions.assertEquals(1, filteredItems.size());
}
 
Example #10
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void testCompletionForMemberVariableOnCompleteVariableExpression() 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, 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("memberVar") && item.getKind().equals(CompletionItemKind.Field);
	}).collect(Collectors.toList());
	Assertions.assertEquals(1, filteredItems.size());
}
 
Example #11
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void testCompletionForMemberMethodOnPartialVariableExpression() 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 memberMethod() {}\n");
	contents.append("  public Completion() {\n");
	contents.append("    mem\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("memberMethod") && item.getKind().equals(CompletionItemKind.Method);
	}).collect(Collectors.toList());
	Assertions.assertEquals(1, filteredItems.size());
}
 
Example #12
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void testCompletionForMemberMethodOnCompleteVariableExpression() 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 memberMethod() {}\n");
	contents.append("  public Completion() {\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(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("memberMethod") && item.getKind().equals(CompletionItemKind.Method);
	}).collect(Collectors.toList());
	Assertions.assertEquals(1, filteredItems.size());
}
 
Example #13
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void testCompletionForParameterOnPartialVariableExpression() 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("    par\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, 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("paramName") && item.getKind().equals(CompletionItemKind.Variable);
	}).collect(Collectors.toList());
	Assertions.assertEquals(1, filteredItems.size());
}
 
Example #14
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 #15
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesCompletionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 #16
Source Project: camel-language-server   Author: camel-tooling   File: EndpointDiagnosticService.java    License: Apache License 2.0 6 votes vote down vote up
public List<Diagnostic> converToLSPDiagnostics(String fullCamelText, Map<CamelEndpointDetails, EndpointValidationResult> endpointErrors, TextDocumentItem textDocumentItem) {
	List<Diagnostic> lspDiagnostics = new ArrayList<>();
	for (Map.Entry<CamelEndpointDetails, EndpointValidationResult> endpointError : endpointErrors.entrySet()) {
		EndpointValidationResult validationResult = endpointError.getValue();
		CamelEndpointDetails camelEndpointDetails = endpointError.getKey();
		List<Diagnostic> unknownParameterDiagnostics = computeUnknowParameters(fullCamelText, textDocumentItem, validationResult, camelEndpointDetails);
		lspDiagnostics.addAll(unknownParameterDiagnostics);
		List<Diagnostic> invalidEnumDiagnostics = computeInvalidEnumsDiagnostic(fullCamelText, textDocumentItem, validationResult, camelEndpointDetails);
		lspDiagnostics.addAll(invalidEnumDiagnostics);
		if (invalidEnumDiagnostics.size() + unknownParameterDiagnostics.size() < validationResult.getNumberOfErrors()) {
			lspDiagnostics.add(new Diagnostic(
					computeRange(fullCamelText, textDocumentItem, camelEndpointDetails),
					computeErrorMessage(validationResult),
					DiagnosticSeverity.Error,
					APACHE_CAMEL_VALIDATION,
					null));
		}
	}
	return lspDiagnostics;
}
 
Example #17
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesDefinitionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 #18
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesDefinitionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: groovy-language-server   Author: prominic   File: GroovyServicesDefinitionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: groovy-language-server   Author: prominic   File: GroovyServicesDefinitionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: groovy-language-server   Author: prominic   File: GroovyServicesDefinitionTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 #22
Source Project: groovy-language-server   Author: prominic   File: GroovyServicesTypeDefinitionTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testLocalVariableTypeDefinitionFromMethodCall() 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 void method() {\n");
	contents.append("  }\n");
	contents.append("  public TypeDefinitions() {\n");
	contents.append("    TypeDefinitions localVar\n");
	contents.append("    localVar.method()\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(5, 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(7, location.getRange().getEnd().getLine());
	Assertions.assertEquals(1, location.getRange().getEnd().getCharacter());
}
 
Example #23
Source Project: MSPaintIDE   Author: MSPaintIDE   File: BasicDocument.java    License: MIT License 5 votes vote down vote up
public void open(boolean updateLSP) {
    this.opened = true;

    if (this.text == null) {
        this.imageClass.scan();
        if ((this.text = this.imageClass.getText()) == null) return;
    }

    if (!updateLSP) return;
    this.requestManager.didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(getURI(), "java", version++, this.text)));
}
 
Example #24
Source Project: eclipse.jdt.ls   Author: eclipse   File: DocumentLifeCycleHandlerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void openDocument(String uri, String content, int version) {
	DidOpenTextDocumentParams openParms = new DidOpenTextDocumentParams();
	TextDocumentItem textDocument = new TextDocumentItem();
	textDocument.setLanguageId("java");
	textDocument.setText(content);
	textDocument.setUri(uri);
	textDocument.setVersion(version);
	openParms.setTextDocument(textDocument);
	lifeCycleHandler.didOpen(openParms);
}
 
Example #25
Source Project: camel-language-server   Author: camel-tooling   File: EndpointDiagnosticService.java    License: Apache License 2.0 5 votes vote down vote up
private List<Diagnostic> computeUnknowParameters(String fullCamelText, TextDocumentItem textDocumentItem, EndpointValidationResult validationResult, CamelEndpointDetails camelEndpointDetails) {
	List<Diagnostic> lspDiagnostics = new ArrayList<>();
	Set<String> unknownParameters = validationResult.getUnknown();
	if (unknownParameters != null) {
		for (String unknownParameter : unknownParameters) {
			lspDiagnostics.add(new Diagnostic(
					computeRange(fullCamelText, textDocumentItem, camelEndpointDetails, unknownParameter),
					new UnknownErrorMsg().getErrorMessage(unknownParameter),
					DiagnosticSeverity.Error,
					APACHE_CAMEL_VALIDATION,
					ERROR_CODE_UNKNOWN_PROPERTIES));
		}
	}
	return lspDiagnostics;
}
 
Example #26
Source Project: groovy-language-server   Author: prominic   File: FileContentsTrackerTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testDidOpen() {
	DidOpenTextDocumentParams params = new DidOpenTextDocumentParams();
	params.setTextDocument(new TextDocumentItem("file.txt", "plaintext", 1, "hello world"));
	tracker.didOpen(params);
	Assertions.assertEquals("hello world", tracker.getContents(URI.create("file.txt")));
}
 
Example #27
Source Project: groovy-language-server   Author: prominic   File: FileContentsTrackerTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testDidChangeWithRange() {
	DidOpenTextDocumentParams openParams = new DidOpenTextDocumentParams();
	openParams.setTextDocument(new TextDocumentItem("file.txt", "plaintext", 1, "hello world"));
	tracker.didOpen(openParams);
	DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams();
	changeParams.setTextDocument(new VersionedTextDocumentIdentifier("file.txt", 2));
	TextDocumentContentChangeEvent changeEvent = new TextDocumentContentChangeEvent();
	changeEvent.setText(", friend");
	changeEvent.setRange(new Range(new Position(0, 5), new Position(0, 11)));
	changeEvent.setRangeLength(6);
	changeParams.setContentChanges(Collections.singletonList(changeEvent));
	tracker.didChange(changeParams);
	Assertions.assertEquals("hello, friend", tracker.getContents(URI.create("file.txt")));
}
 
Example #28
Source Project: groovy-language-server   Author: prominic   File: FileContentsTrackerTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testDidChangeWithRangeMultiline() {
	DidOpenTextDocumentParams openParams = new DidOpenTextDocumentParams();
	openParams.setTextDocument(new TextDocumentItem("file.txt", "plaintext", 1, "hello\nworld"));
	tracker.didOpen(openParams);
	DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams();
	changeParams.setTextDocument(new VersionedTextDocumentIdentifier("file.txt", 2));
	TextDocumentContentChangeEvent changeEvent = new TextDocumentContentChangeEvent();
	changeEvent.setText("affles");
	changeEvent.setRange(new Range(new Position(1, 1), new Position(1, 5)));
	changeEvent.setRangeLength(4);
	changeParams.setContentChanges(Collections.singletonList(changeEvent));
	tracker.didChange(changeParams);
	Assertions.assertEquals("hello\nwaffles", tracker.getContents(URI.create("file.txt")));
}
 
Example #29
Source Project: camel-language-server   Author: camel-tooling   File: MultiDocumentReferencesProcessorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testDirectProducerToConsumersReferences() throws Exception {
	TextDocumentItem item1 = new TextDocumentItem("uri1.xml", CamelLanguageServer.LANGUAGE_ID, 0, MULTI_DOCUMENT_REFERENCE_DOC1);
	TextDocumentItem item2 = new TextDocumentItem("uri2.xml", CamelLanguageServer.LANGUAGE_ID, 0, MULTI_DOCUMENT_REFERENCE_DOC2);
	Position pos = new Position(5, 25);
	List<? extends Location> results = testRetrieveReferencesFromMultipleOpenedDocuments(".xml", pos, 3, item1, item2);
	
	int foundInFile1 = 0;
	int foundInFile2 = 0;
	
	int lastFoundLine = -1;
	for (Location loc : results) {
		int line = loc.getRange().getStart().getLine();
		if (loc.getUri().equals("uri1.xml")) {
			assertThat(line).isEqualTo(12);
			foundInFile1++;
		} else {
			assertThat(loc.getUri()).isEqualTo("uri2.xml");
			if (lastFoundLine != line) {
				lastFoundLine = line;
			}
			assertThat(line).isIn(3, 8);
			foundInFile2++;
		}
	}
	
	assertThat(foundInFile1).isEqualTo(1);
	assertThat(foundInFile2).isEqualTo(2);
}
 
Example #30
Source Project: camel-language-server   Author: camel-tooling   File: CamelTextDocumentService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(DefinitionParams params) {
	TextDocumentIdentifier textDocument = params.getTextDocument();
	LOGGER.info("definition: {}", textDocument);
	TextDocumentItem textDocumentItem = openedDocuments.get(textDocument.getUri());
	return new DefinitionProcessor(textDocumentItem).getDefinitions(params.getPosition());
}