org.eclipse.lsp4j.CompletionList Java Examples

The following examples show how to use org.eclipse.lsp4j.CompletionList. 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: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_array_foreach() throws JavaModelException {
	//@formatter:off
	ICompilationUnit unit = getWorkingCopy(
		"src/org/sample/Test.java",
		"package org.sample;\n" +
		"public class Test {\n" +
		"	public void testMethod(String[] args) {\n" +
		"		foreach" +
		"	}\n" +
		"}"
	);
	//@formatter:on
	int[] loc = findCompletionLocation(unit, "foreach");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);

	List<CompletionItem> items = new ArrayList<>(list.getItems());
	CompletionItem item = items.get(0);
	assertEquals("foreach", item.getLabel());
	String insertText = item.getInsertText();
	assertEquals("for (${1:String} ${2:string} : ${3:args}) {\n\t$TM_SELECTED_TEXT${0}\n}", insertText);
}
 
Example #2
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: CamelLanguageServerCompletionPositionTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest(name="{6} - Position ({1},{2})")
   @MethodSource("data")
void testProvideCompletionForCamelBlueprintNamespace(
		String textToTest,
		int line,
		int characterCallingCompletion,
		int characterStartCompletion,
		int characterEndCompletion,
		boolean shouldHaveCompletion,
		String testNameQualification) throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer(textToTest);
	
	CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(line, characterCallingCompletion));
	
	if(shouldHaveCompletion) {
		assertThat(completions.get().getLeft()).contains(createExpectedAhcCompletionItem(line, characterStartCompletion, line, characterEndCompletion));
	} else {
		Condition<CompletionItem> ahc = new Condition<>(completionItem -> completionItem.getLabel().contains("ahc"), "Found an ahc component");
		assertThat(completions.get().getLeft().stream()).areNot(ahc);
		assertThat(completions.get().getRight()).isNull();
	}
}
 
Example #5
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with Apache License 2.0 6 votes vote down vote up
@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 #6
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 #7
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCompletion_javadocCommentPartial() throws JavaModelException {
	ICompilationUnit unit = getWorkingCopy(
	//@formatter:off
	"src/java/Foo.java",
	"public class Foo {\n"+
	"	/** \n"+
	"	 * @int \n"+
	"	*/ \n"+
	"	void foo(int i, String s) {\n"+
	"	}\n"+
	"}\n");
	//@formatter:on
	int[] loc = findCompletionLocation(unit, "/**");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
	assertNotNull(list);
	assertEquals(0, list.getItems().size());
}
 
Example #8
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCompletion_javadoc() throws Exception {
	IJavaProject javaProject = JavaCore.create(project);
	ICompilationUnit unit = (ICompilationUnit) javaProject.findElement(new Path("org/sample/TestJavadoc.java"));
	unit.becomeWorkingCopy(null);
	String joinOnCompletion = System.getProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION);
	try {
		System.setProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION, "true");
		int[] loc = findCompletionLocation(unit, "inner.");
		CompletionParams position = JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]));
		String source = unit.getSource();
		changeDocument(unit, source, 3);
		Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, new NullProgressMonitor());
		changeDocument(unit, source, 4);
		CompletionList list = server.completion(position).join().getRight();
		CompletionItem resolved = server.resolveCompletionItem(list.getItems().get(0)).join();
		assertEquals("Test ", resolved.getDocumentation().getLeft());
	} finally {
		unit.discardWorkingCopy();
		if (joinOnCompletion == null) {
			System.clearProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION);
		} else {
			System.setProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION, joinOnCompletion);
		}
	}
}
 
Example #9
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCompletion_type() throws Exception {
	ICompilationUnit unit = getWorkingCopy(
			"src/org/sample/Foo.java",
			"public class Foo {\n"+
					"    public static void main(String[] args) {\n" +
					"        ArrayList\n" +
					"    }\n" +
			"}\n");
	waitForBackgroundJobs();
	int[] loc = findCompletionLocation(unit, "ArrayList");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
	assertNotNull(list);
	CompletionItem ci = list.getItems().stream()
			.filter(item -> item.getLabel().startsWith("ArrayList"))
			.findFirst().orElse(null);
	assertNotNull(ci);

	assertEquals("ArrayList", ci.getInsertText());
	assertEquals(CompletionItemKind.Class, ci.getKind());
	assertEquals("ArrayList - java.util", ci.getLabel());
	assertEquals("java.util.ArrayList", ci.getDetail());
	assertEquals("999999148", ci.getSortText());
	assertNotNull(ci.getTextEdit());
}
 
Example #10
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 #11
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testMemberAccessOnLocalVariableWithExistingVariableExpressionOnNextLine() 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("    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 #12
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 #13
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 #14
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_if() throws JavaModelException {
	//@formatter:off
	ICompilationUnit unit = getWorkingCopy(
		"src/org/sample/Test.java",
		"package org.sample;\n" +
		"public class Test {\n" +
		"	public void testMethod(boolean con) {\n" +
		"		if" +
		"	}\n" +
		"}"
	);
	//@formatter:on
	int[] loc = findCompletionLocation(unit, "if");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);

	List<CompletionItem> items = new ArrayList<>(list.getItems());
	CompletionItem item = items.get(5);
	assertEquals("if", item.getLabel());
	String insertText = item.getInsertText();
	assertEquals("if (${1:con}) {\n\t$TM_SELECTED_TEXT${0}\n}", insertText);
}
 
Example #15
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_nested_inner_interface() throws JavaModelException {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java", "package org.sample;\npublic interface Test {}\npublic interface InnerTest{\n");
	int[] loc = findCompletionLocation(unit, "package org.sample;\npublic interface Test {}\npublic interface InnerTest{\n");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);
	List<CompletionItem> items = new ArrayList<>(list.getItems());
	assertFalse(items.isEmpty());
	items.sort((i1, i2) -> (i1.getSortText().compareTo(i2.getSortText())));

	CompletionItem item = items.get(23);
	assertEquals("interface", item.getLabel());
	String te = item.getInsertText();
	assertEquals("/**\n * ${1:InnerTest_1}\n */\npublic interface ${1:InnerTest_1} {\n\n\t${0}\n}", te);
}
 
Example #16
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_context_method2() throws JavaModelException {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java",
	//@formatter:off
			"package org.sample;\n"
		+	"public class Test {\n\n"
		+	"	void test() {\n\n"
		+	"		if (c\n"
		+	"	}\n"
		+	"}\n");
		//@formatter:off
	int[] loc = findCompletionLocation(unit, "if (c");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
	assertNotNull(list);
	CompletionItem ci = list.getItems().stream()
			.filter( item->  (item.getLabel().matches("class") && item.getKind() == CompletionItemKind.Snippet))
			.findFirst().orElse(null);
	assertNull(ci);
	ci = list.getItems().stream()
			.filter( item->  (item.getLabel().matches("interface") && item.getKind() == CompletionItemKind.Snippet))
			.findFirst().orElse(null);
	assertNull(ci);
}
 
Example #17
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Ignore(value = "When running tests, in SnippetCompletionProposal.getSnippetContent(), cu.getAllTypes() returns en empty array, so inner record name is not computed")
@Test
public void testSnippet_sibling_inner_record() throws Exception {
	importProjects("eclipse/records");
	project = WorkspaceHelper.getProject("records");
	ICompilationUnit unit = getWorkingCopy("src/main/java/org/sample/Test.java", "package org.sample;\npublic record Test() {}\npublic record InnerTest(){}\n");
	int[] loc = findCompletionLocation(unit, "package org.sample;\npublic record Test {}\npublic record InnerTest(){}\n");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);
	List<CompletionItem> items = new ArrayList<>(list.getItems());
	assertFalse(items.isEmpty());
	items.sort((i1, i2) -> (i1.getSortText().compareTo(i2.getSortText())));

	CompletionItem item = items.get(7);
	assertEquals("record", item.getLabel());
	String te = item.getInsertText();
	assertEquals("/**\n * ${1:InnerTest_1}\n */\npublic record ${1:InnerTest_1}(${0) {\n}", te);
}
 
Example #18
Source File: SyntaxLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams position) {
	logInfo(">> document/completion");
	CompletionHandler handler = new CompletionHandler(preferenceManager);
	final IProgressMonitor[] monitors = new IProgressMonitor[1];
	CompletableFuture<Either<List<CompletionItem>, CompletionList>> result = computeAsync((monitor) -> {
		monitors[0] = monitor;
		if (Boolean.getBoolean(JAVA_LSP_JOIN_ON_COMPLETION)) {
			waitForLifecycleJobs(monitor);
		}
		return handler.completion(position, monitor);
	});
	result.join();
	if (monitors[0].isCanceled()) {
		result.cancel(true);
	}
	return result;
}
 
Example #19
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_while() throws JavaModelException {
	//@formatter:off
	ICompilationUnit unit = getWorkingCopy(
		"src/org/sample/Test.java",
		"package org.sample;\n" +
		"public class Test {\n" +
		"	public void testMethod(boolean con) {\n" +
		"		while" +
		"	}\n" +
		"}"
	);
	//@formatter:on
	int[] loc = findCompletionLocation(unit, "while");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);

	List<CompletionItem> items = new ArrayList<>(list.getItems());
	CompletionItem item = items.get(1);
	assertEquals("while", item.getLabel());
	String insertText = item.getInsertText();
	assertEquals("while (${1:con}) {\n\t$TM_SELECTED_TEXT${0}\n}", insertText);
}
 
Example #20
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCompletion_Enum() throws JavaModelException {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java",
	//@formatter:off
			"package org.sample;\n"
		+	"public class Test {\n\n"
		+   "   enum Zenum{A,B}\n"
		+	"	void test() {\n\n"
		+	"      Zenu\n"
		+	"	}\n"
		+	"}\n");
	//@formatter:on
	int[] loc = findCompletionLocation(unit, "   Zenu");

	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
	assertNotNull(list);
	assertEquals(1, list.getItems().size());
	CompletionItem item = list.getItems().get(0);
	assertEquals(CompletionItemKind.Enum, item.getKind());
	assertEquals("Zenum", item.getInsertText());
}
 
Example #21
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_context_package() throws JavaModelException {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java",
	//@formatter:off
		"package org.sample;\n");
		//@formatter:off
	int[] loc = findCompletionLocation(unit, "package ");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
	assertNotNull(list);
	CompletionItem ci = list.getItems().stream()
			.filter( item->  (item.getLabel().matches("class") && item.getKind() == CompletionItemKind.Snippet))
			.findFirst().orElse(null);
	assertNull(ci);
	ci = list.getItems().stream()
			.filter( item->  (item.getLabel().matches("interface") && item.getKind() == CompletionItemKind.Snippet))
			.findFirst().orElse(null);
	assertNull(ci);
}
 
Example #22
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_context_method3() throws JavaModelException {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java",
	//@formatter:off
			"package org.sample;\n"
		+	"public class Test {\n\n"
		+	"	void test() {\n\n"
		+	"		int \n"
		+	"	}\n"
		+	"}\n");
		//@formatter:off
	int[] loc = findCompletionLocation(unit, "int ");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
	assertNotNull(list);
	CompletionItem ci = list.getItems().stream()
			.filter( item->  (item.getLabel().matches("class") && item.getKind() == CompletionItemKind.Snippet))
			.findFirst().orElse(null);
	assertNull(ci);
	ci = list.getItems().stream()
			.filter( item->  (item.getLabel().matches("interface") && item.getKind() == CompletionItemKind.Snippet))
			.findFirst().orElse(null);
	assertNull(ci);
}
 
Example #23
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 #24
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_ifelse() throws JavaModelException {
	//@formatter:off
	ICompilationUnit unit = getWorkingCopy(
		"src/org/sample/Test.java",
		"package org.sample;\n" +
		"public class Test {\n" +
		"	public void testMethod(boolean con) {\n" +
		"		ifelse" +
		"	}\n" +
		"}"
	);
	//@formatter:on
	int[] loc = findCompletionLocation(unit, "ifelse");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);

	List<CompletionItem> items = new ArrayList<>(list.getItems());
	CompletionItem item = items.get(0);
	assertEquals("ifelse", item.getLabel());
	String insertText = item.getInsertText();
	assertEquals("if (${1:con}) {\n\t${2}\n} else {\n\t${0}\n}", insertText);
}
 
Example #25
Source File: CompletionProvider.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
private void autoCompleteTypes(IASNode withNode, AddImportData addImportData, ILspProject project, CompletionList result)
{
    //start by getting the types in scope
    IASNode node = withNode;
    do
    {
        //just keep traversing up until we get a scoped node or run out of
        //nodes to check
        if (node instanceof IScopedNode)
        {
            IScopedNode scopedNode = (IScopedNode) node;

            //include all members and local things that are in scope
            autoCompleteScope(scopedNode, true, (char) -1, addImportData, project, result);
            break;
        }
        node = node.getParent();
    }
    while (node != null);
    autoCompleteDefinitionsForActionScript(result, project, withNode, true, null, null, false, null, (char) -1, addImportData);
}
 
Example #26
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_array_fori() throws JavaModelException {
	//@formatter:off
	ICompilationUnit unit = getWorkingCopy(
		"src/org/sample/Test.java",
		"package org.sample;\n" +
		"public class Test {\n" +
		"	public void testMethod(String[] args) {\n" +
		"		fori" +
		"	}\n" +
		"}"
	);
	//@formatter:on
	int[] loc = findCompletionLocation(unit, "fori");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);

	List<CompletionItem> items = new ArrayList<>(list.getItems());
	CompletionItem item = items.get(0);
	assertEquals("fori", item.getLabel());
	String insertText = item.getInsertText();
	assertEquals("for (${1:int} ${2:i} = ${3:0}; ${2:i} < ${4:args.length}; ${2:i}++) {\n\t$TM_SELECTED_TEXT${0}\n}", insertText);
}
 
Example #27
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Ignore(value = "When running tests, in SnippetCompletionProposal.getSnippetContent(), cu.getAllTypes() returns en empty array, so inner record name is not computed")
@Test
public void testSnippet_inner_record() throws Exception {
	importProjects("eclipse/records");
	project = WorkspaceHelper.getProject("records");
	ICompilationUnit unit = getWorkingCopy("src/main/java/org/sample/Test.java", "package org.sample;\npublic record Test() {}\n");
	int[] loc = findCompletionLocation(unit, "package org.sample;\npublic record Test() {");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);
	List<CompletionItem> items = new ArrayList<>(list.getItems());
	assertFalse(items.isEmpty());
	items.sort((i1, i2) -> (i1.getSortText().compareTo(i2.getSortText())));

	CompletionItem item = items.get(7);
	assertEquals("record", item.getLabel());
	String te = item.getInsertText();
	assertEquals("/**\n * ${1:InnerTest}\n */\npublic record ${1:InnerTest}(${0}) {\n}", te);
}
 
Example #28
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_record_with_package() throws Exception {
	importProjects("eclipse/records");
	project = WorkspaceHelper.getProject("records");
	ICompilationUnit unit = getWorkingCopy("src/main/java/org/sample/Test.java", "package org.sample;\n");
	int[] loc = findCompletionLocation(unit, "package org.sample;\n");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);
	List<CompletionItem> items = new ArrayList<>(list.getItems());
	assertFalse(items.isEmpty());
	items.sort((i1, i2) -> (i1.getSortText().compareTo(i2.getSortText())));

	CompletionItem item = items.get(9);
	assertEquals("record", item.getLabel());
	String te = item.getInsertText();
	assertEquals("/**\n * Test\n */\npublic record Test(${0}) {\n}", te);
}
 
Example #29
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSnippet_sibling_inner_class() throws JavaModelException {
	ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java", "package org.sample;\npublic class Test {}\npublic class InnerTest{}\n");
	int[] loc = findCompletionLocation(unit, "package org.sample;\npublic class Test {}\npublic class InnerTest{}\n");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);
	List<CompletionItem> items = new ArrayList<>(list.getItems());
	assertFalse(items.isEmpty());
	items.sort((i1, i2) -> (i1.getSortText().compareTo(i2.getSortText())));

	CompletionItem item = items.get(5);
	assertEquals("class", item.getLabel());
	String te = item.getInsertText();
	assertEquals("/**\n * ${1:InnerTest_1}\n */\npublic class ${1:InnerTest_1} {\n\n\t${0}\n}", te);
}
 
Example #30
Source File: CamelPropertiesComponentOptionNameCompletionTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideCompletionWithoutDefaultValueIfAValueAlreadyProvided() throws Exception {
	CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = retrieveCompletion(new Position(0, 27), "camel.component.acomponent.aComponentProperty=aValue");
	CompletionItem expectedCompletionItem = new CompletionItem("aComponentProperty");
	expectedCompletionItem.setInsertText("aComponentProperty");
	expectedCompletionItem.setDocumentation("A parameter description");
	expectedCompletionItem.setDeprecated(false);
	expectedCompletionItem.setDetail(String.class.getName());
	expectedCompletionItem.setTextEdit(new TextEdit(new Range(new Position(0, 27), new Position(0, 45)), "aComponentProperty"));
	assertThat(completions.get().getLeft()).contains(expectedCompletionItem);
}