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 File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 #2
Source File: GroovyServicesTypeDefinitionTests.java    From groovy-language-server with 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 File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 #4
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 #5
Source File: TeiidDdlTextDocumentService.java    From syndesis with 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 #6
Source File: CamelKYamlDSLParser.java    From camel-language-server with 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 File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 #9
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 #10
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 #11
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 #13
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 #14
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with 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 #15
Source File: GroovyServicesDefinitionTests.java    From groovy-language-server with 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 #16
Source File: EndpointDiagnosticService.java    From camel-language-server with 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 File: GroovyServicesDefinitionTests.java    From groovy-language-server with 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 File: EditorEventManager.java    From lsp4intellij with 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 #19
Source File: GroovyServicesDefinitionTests.java    From groovy-language-server with 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 #20
Source File: GroovyServicesDefinitionTests.java    From groovy-language-server with 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 #21
Source File: GroovyServicesDefinitionTests.java    From groovy-language-server with 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 #22
Source File: MultiDocumentReferencesProcessorTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
private List<? extends Location> testRetrieveReferencesFromMultipleOpenedDocuments(String suffix, Position posInFirstDoc, int expectedResultCount, TextDocumentItem... documentItems) throws URISyntaxException, InterruptedException, ExecutionException {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer(suffix, documentItems);
	CompletableFuture<List<? extends Location>> referencesFuture = getReferencesFor(camelLanguageServer, posInFirstDoc, "uri1.xml");
	List<? extends Location> references = referencesFuture.get();
	assertThat(references).hasSize(expectedResultCount);
	return references;
}
 
Example #23
Source File: AbstractIdeTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Opens the given file in the LSP server and waits for the triggered build to finish. */
protected void openFile(FileURI fileURI) {
	if (isOpen(fileURI)) {
		Assert.fail("trying to open a file that is already open: " + fileURI);
	}

	Path filePath = fileURI.toJavaIoFile().toPath();
	String content;
	try {
		content = Files.readString(filePath);
	} catch (IOException e) {
		throw new AssertionError("exception while reading file contents from disk", e);
	}

	TextDocumentItem textDocument = new TextDocumentItem();
	textDocument.setLanguageId(languageInfo.getLanguageName());
	textDocument.setUri(fileURI.toString());
	textDocument.setVersion(1);
	textDocument.setText(toUnixLineSeparator(content));

	DidOpenTextDocumentParams dotdp = new DidOpenTextDocumentParams();
	dotdp.setTextDocument(textDocument);

	languageServer.didOpen(dotdp);
	openFiles.put(fileURI, new OpenFileInfo(content));

	joinServerRequests();
}
 
Example #24
Source File: CamelKafkaConnectDSLParser.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Override
public CamelURIInstance createCamelURIInstance(TextDocumentItem textDocumentItem, Position position,
		String camelComponentUri) {
	CamelURIInstance uriInstance = new CamelURIInstance(camelComponentUri, new PropertiesDSLModelHelper(getCorrespondingMethodName(textDocumentItem, position.getLine())), textDocumentItem);
	int start = getStartCharacterInDocumentOnLinePosition(textDocumentItem, position);
	uriInstance.setStartPositionInDocument(new Position(position.getLine(), start));
	uriInstance.setEndPositionInDocument(new Position(position.getLine(), start+camelComponentUri.length()));
	return uriInstance;
}
 
Example #25
Source File: AbstractQuickfix.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
protected String retrieveCurrentErrorValue(TextDocumentItem openedDocument, Diagnostic diagnostic) {
	Range diagnosticRange = diagnostic.getRange();
	String line = new ParserFileHelperUtil().getLine(openedDocument, diagnosticRange.getStart().getLine());
	int endCharacter = diagnosticRange.getEnd().getCharacter();
	if (line.length() > endCharacter) {
		return line.substring(diagnosticRange.getStart().getCharacter(), endCharacter);
	} else {
		return null;
	}
}
 
Example #26
Source File: DiagnosticRunner.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
public void computeDiagnostics(String camelText, String uri) {
	CompletableFuture.runAsync(() -> {
		Map<CamelEndpointDetails, EndpointValidationResult> endpointErrors = endpointDiagnosticService.computeCamelEndpointErrors(camelText, uri);
		TextDocumentItem openedDocument = camelLanguageServer.getTextDocumentService().getOpenedDocument(uri);
		List<Diagnostic> diagnostics = endpointDiagnosticService.converToLSPDiagnostics(camelText, endpointErrors, openedDocument);
		Map<String, ConfigurationPropertiesValidationResult> configurationPropertiesErrors = configurationPropertiesDiagnosticService.computeCamelConfigurationPropertiesErrors(camelText, uri);
		diagnostics.addAll(configurationPropertiesDiagnosticService.converToLSPDiagnostics(configurationPropertiesErrors));
		camelLanguageServer.getClient().publishDiagnostics(new PublishDiagnosticsParams(uri, diagnostics));
	});
}
 
Example #27
Source File: DiagnosticsCommandTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void openDocument(ICompilationUnit cu, String content, int version) {
	DidOpenTextDocumentParams openParms = new DidOpenTextDocumentParams();
	TextDocumentItem textDocument = new TextDocumentItem();
	textDocument.setLanguageId("java");
	textDocument.setText(content);
	textDocument.setUri(JDTUtils.toURI(cu));
	textDocument.setVersion(version);
	openParms.setTextDocument(textDocument);
	lifeCycleHandler.didOpen(openParms);
}
 
Example #28
Source File: GroovyServicesDefinitionTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testClassDefinitionFromImport() 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));

	Path filePath2 = srcRoot.resolve("Definitions2.groovy");
	String uri2 = filePath2.toUri().toString();
	StringBuilder contents2 = new StringBuilder();
	contents2.append("import Definitions\n");
	contents2.append("class Definitions2 {\n");
	contents2.append("}");
	TextDocumentItem textDocumentItem2 = new TextDocumentItem(uri2, LANGUAGE_GROOVY, 1, contents2.toString());
	services.didOpen(new DidOpenTextDocumentParams(textDocumentItem2));

	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri2);
	Position position = new Position(0, 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(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 #29
Source File: ParserXMLFileHelper.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
/**
 * @param textDocumentItem	the text document item
 * @param line 	the line number
 * @return Currently returns the first from Camel Node ignoring the exact position
 */
public Node getCorrespondingCamelNodeForCompletion(TextDocumentItem textDocumentItem, int line) {
	try {
		if (hasElementFromCamelNamespace(textDocumentItem)) {
			Document parseXml = getDocumentWithLineInformation(textDocumentItem);
			Element documentElement = parseXml.getDocumentElement();
			return findElementAtLine(line, documentElement);
		} else {
			return null;
		}
	} catch (Exception e) {
		LOGGER.warn("Exception while trying to parse the file", e);
		return null;
	}
}
 
Example #30
Source File: OptionParamValueURIInstance.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<CompletionItem>> getCompletions(CompletableFuture<CamelCatalog> camelCatalog, int positionInCamelUri, TextDocumentItem docItem) {
	if(getStartPositionInUri() <= positionInCamelUri && positionInCamelUri <= getEndPositionInUri()) {
		return camelCatalog.thenApply(new CamelOptionValuesCompletionsFuture(this, getFilter(positionInCamelUri)));
	} else {
		return CompletableFuture.completedFuture(Collections.emptyList());
	}
}