org.eclipse.lsp4j.CompletionItemKind Java Examples
The following examples show how to use
org.eclipse.lsp4j.CompletionItemKind.
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: HTMLCompletionExtensionsTest.java From lemminx with Eclipse Public License 2.0 | 6 votes |
@Override public void onTagOpen(ICompletionRequest completionRequest, ICompletionResponse completionResponse) throws Exception { Range range = completionRequest.getReplaceRange(); HTMLTag.HTML_TAGS.forEach(t -> { String tag = t.getTag(); String label = t.getLabel(); CompletionItem item = new CompletionItem(); item.setLabel(tag); item.setFilterText(completionRequest.getFilterForStartTagName(tag)); item.setKind(CompletionItemKind.Property); item.setDocumentation(Either.forLeft(label)); item.setTextEdit(new TextEdit(range, "<" + tag + "/>")); item.setInsertTextFormat(InsertTextFormat.PlainText); completionResponse.addCompletionItem(item); }); }
Example #2
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberAccessOnClassAfterDot() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public Completion() {\n"); contents.append(" Completion.\n"); contents.append(" }\n"); contents.append(" public static void staticMethod() {}\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(2, 15); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); Assertions.assertTrue(items.size() > 0); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("staticMethod") && item.getKind().equals(CompletionItemKind.Method); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #3
Source File: Icons.java From netbeans with Apache License 2.0 | 6 votes |
public static Icon getCompletionIcon(CompletionItemKind completionKind) { Image img = null; if (completionKind != null) { img = ImageUtilities.loadImage(ICON_BASE + completionKind.name().toLowerCase(Locale.US) + PNG_EXTENSION); if (img == null) { img = ImageUtilities.loadImage(ICON_BASE + completionKind.name().toLowerCase(Locale.US) + GIF_EXTENSION); } } if (img == null) { img = ImageUtilities.loadImage(ICON_BASE + "variable" + GIF_EXTENSION); } return img == null ? null : new ImageIcon (img); }
Example #4
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@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 #5
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testSnippet_context_method1() 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" + " }\n" + "}\n"); //@formatter:off int[] loc = findCompletionLocation(unit, "{\n\n"); 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); assertNotNull(ci); String text = ci.getInsertText(); assertEquals("class ${1:InnerTest} {\n\n\t${0}\n}", text); ci = list.getItems().stream() .filter( item-> (item.getLabel().matches("interface") && item.getKind() == CompletionItemKind.Snippet)) .findFirst().orElse(null); assertNull(ci); }
Example #6
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testMemberAccessOnLocalArrayAfterDot() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public Completion() {\n"); contents.append(" String[] localVar\n"); contents.append(" localVar[0].\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(3, 16); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); Assertions.assertTrue(items.size() > 0); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("charAt") && item.getKind().equals(CompletionItemKind.Method); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #7
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@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 #8
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testSnippet_context_static() throws JavaModelException { ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java", //@formatter:off "package org.sample;\n" + "public class Test {\n\n" + " static {\n" + " }\n" + "}\n"); //@formatter:off int[] loc = findCompletionLocation(unit, "static {\n"); 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); assertNotNull(ci); String text = ci.getInsertText(); assertEquals("class ${1:InnerTest} {\n\n\t${0}\n}", text); ci = list.getItems().stream() .filter( item-> (item.getLabel().matches("interface") && item.getKind() == CompletionItemKind.Snippet)) .findFirst().orElse(null); assertNull(ci); }
Example #9
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #10
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #11
Source File: GroovyLanguageServerUtils.java From groovy-language-server with Apache License 2.0 | 6 votes |
public static CompletionItemKind astNodeToCompletionItemKind(ASTNode node) { if (node instanceof ClassNode) { ClassNode classNode = (ClassNode) node; if (classNode.isInterface()) { return CompletionItemKind.Interface; } else if (classNode.isEnum()) { return CompletionItemKind.Enum; } return CompletionItemKind.Class; } else if (node instanceof MethodNode) { return CompletionItemKind.Method; } else if (node instanceof Variable) { if (node instanceof FieldNode || node instanceof PropertyNode) { return CompletionItemKind.Field; } return CompletionItemKind.Variable; } return CompletionItemKind.Property; }
Example #12
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #13
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #14
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testCompletion_import_type() throws JavaModelException{ ICompilationUnit unit = getWorkingCopy( "src/java/Foo.java", "import java.sq \n" + "public class Foo {\n"+ " void foo() {\n"+ " java.util.Ma\n"+ " }\n"+ "}\n"); int[] loc = findCompletionLocation(unit, "java.util.Ma"); 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.Interface, item.getKind()); assertEquals("Map", item.getInsertText()); assertNotNull(item.getTextEdit()); assertTextEdit(3, 3, 15, "java.util.Map", item.getTextEdit()); assertTrue(item.getFilterText().startsWith("java.util.Ma")); //Not checking the range end character }
Example #15
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #16
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@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 #17
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testCompletionForParameterOnCompleteVariableExpression() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public void testMethod(String paramName) {\n"); contents.append(" paramName\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(2, 13); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("paramName") && item.getKind().equals(CompletionItemKind.Variable); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #18
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testCompletion_AnonymousDeclarationType2() throws Exception { ICompilationUnit unit = getWorkingCopy( "src/java/Foo.java", "public class Foo {\n"+ " public static void main(String[] args) {\n" + " new Runnable( )\n" + " }\n" + "}\n"); waitForBackgroundJobs(); int[] loc = findCompletionLocation(unit, "Runnable( "); 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("Runnable() Anonymous Inner Type")) .findFirst().orElse(null); assertNotNull(ci); assertEquals("Runnable", ci.getInsertText()); assertEquals(CompletionItemKind.Class, ci.getKind()); assertEquals("999999372", ci.getSortText()); assertNotNull(ci.getTextEdit()); assertTextEdit(2, 20, 24, "(){\n" + " ${0}\n" + "}", ci.getTextEdit()); }
Example #19
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testCompletionForLocalVariableOnCompleteVariableExpression() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public void testMethod() {\n"); contents.append(" String localVar\n"); contents.append(" localVar\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(3, 12); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("localVar") && item.getKind().equals(CompletionItemKind.Variable); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #20
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@Test void testCompletionForLocalVariableOnPartialVariableExpressionInsideBlock() throws Exception { Path filePath = srcRoot.resolve("Completion.groovy"); String uri = filePath.toUri().toString(); StringBuilder contents = new StringBuilder(); contents.append("class Completion {\n"); contents.append(" public void testMethod(String paramName) {\n"); contents.append(" String localVar\n"); contents.append(" if(true) {\n"); contents.append(" loc\n"); contents.append(" }\n"); contents.append(" }\n"); contents.append("}"); TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString()); services.didOpen(new DidOpenTextDocumentParams(textDocumentItem)); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Position position = new Position(4, 9); Either<List<CompletionItem>, CompletionList> result = services .completion(new CompletionParams(textDocument, position)).get(); Assertions.assertTrue(result.isLeft()); List<CompletionItem> items = result.getLeft(); List<CompletionItem> filteredItems = items.stream().filter(item -> { return item.getLabel().equals("localVar") && item.getKind().equals(CompletionItemKind.Variable); }).collect(Collectors.toList()); Assertions.assertEquals(1, filteredItems.size()); }
Example #21
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testCompletion_javadocOriginal() throws JavaModelException { ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java", //@formatter:off "package org.sample;\n" + "import java.util.List;\n" + "import java.util.LinkedList;\n" + "public class Test {\n\n" + " void test() {\n" + " MyList<String> l = new LinkedList<>();\n" + " l.add\n" + " }\n" + "}\n"); //@formatter:on int[] loc = findCompletionLocation(unit, "l.add"); CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight(); assertNotNull(list); assertEquals(4, list.getItems().size()); CompletionItem ci = list.getItems().get(0); assertEquals(CompletionItemKind.Method, ci.getKind()); assertEquals("add(String e) : boolean", ci.getLabel()); CompletionItem resolvedItem = server.resolveCompletionItem(ci).join(); assertEquals(CompletionItemKind.Method, resolvedItem.getKind()); String documentation = resolvedItem.getDocumentation().getLeft(); assertEquals(" Test ", documentation); }
Example #22
Source File: CompletionSortTextHelper.java From lemminx with Eclipse Public License 2.0 | 6 votes |
public static String getSortText(CompletionItemKind kind) { switch (kind) { case Variable: case Property: // DOMElement case Enum: case EnumMember: case Value: return "aa"; case File: return "ab"; case Folder: return "ac"; default: return "zz"; } }
Example #23
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testCompletion_class_name_contains_$() throws Exception { ICompilationUnit unit = getWorkingCopy( "src/org/sample/Foo$Bar.java", "public class Foo$Bar {\n"+ " public static void main(String[] args) {\n" + " new Foo\n" + " }\n" + "}\n"); waitForBackgroundJobs(); int[] loc = findCompletionLocation(unit, "new Foo"); 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("Foo$Bar")) .findFirst().orElse(null); assertNotNull(ci); assertEquals("Foo$Bar", ci.getInsertText()); assertEquals(CompletionItemKind.Constructor, ci.getKind()); assertEquals("999999115", ci.getSortText()); assertNotNull(ci.getTextEdit()); assertTextEdit(2, 12, 15, "Foo\\$Bar()", ci.getTextEdit()); }
Example #24
Source File: FilePathCompletionParticipant.java From lemminx with Eclipse Public License 2.0 | 6 votes |
private void createFilePathCompletionItem(File f, Range replaceRange, ICompletionResponse response, String slash) { CompletionItem item = new CompletionItem(); String fName = f.getName(); if(isWindows && fName.isEmpty()) { // Edge case for Windows drive letter fName = f.getPath(); fName = fName.substring(0, fName.length() - 1); } String insertText; insertText = slash + fName; item.setLabel(insertText); CompletionItemKind kind = f.isDirectory()? CompletionItemKind.Folder : CompletionItemKind.File; item.setKind(kind); item.setSortText(CompletionSortTextHelper.getSortText(kind)); item.setFilterText(insertText); item.setTextEdit(new TextEdit(replaceRange, insertText)); response.addCompletionItem(item); }
Example #25
Source File: XMLReferencesCompletionParticipant.java From lemminx with Eclipse Public License 2.0 | 6 votes |
@Override public void onXMLContent(ICompletionRequest request, ICompletionResponse response) throws Exception { int offset = request.getOffset(); final DOMNode node = getNodeAt(request.getNode(), offset); if (node != null) { XMLReferencesManager.getInstance().collect(node, n -> { DOMDocument doc = n.getOwnerDocument(); Range range = XMLPositionUtility.createRange(node.getStart(), node.getEnd(), doc); String label = n.getNodeValue(); CompletionItem item = new CompletionItem(); item.setLabel(label); String insertText = label; item.setKind(CompletionItemKind.Property); item.setDocumentation(Either.forLeft(label)); item.setFilterText(insertText); item.setTextEdit(new TextEdit(range, insertText)); item.setInsertTextFormat(InsertTextFormat.PlainText); response.addCompletionItem(item); }); } }
Example #26
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testCompletion_class_name_contains_$withoutSnippetSupport() throws Exception { mockLSPClient(false, true); ICompilationUnit unit = getWorkingCopy( "src/org/sample/Foo$Bar.java", "public class Foo$Bar {\n"+ " public static void main(String[] args) {\n" + " new Foo\n" + " }\n" + "}\n"); waitForBackgroundJobs(); int[] loc = findCompletionLocation(unit, "new Foo"); 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("Foo$Bar")) .findFirst().orElse(null); assertNotNull(ci); assertEquals("Foo$Bar", ci.getInsertText()); assertEquals(CompletionItemKind.Constructor, ci.getKind()); assertEquals("999999115", ci.getSortText()); assertNotNull(ci.getTextEdit()); assertTextEdit(2, 12, 15, "Foo$Bar", ci.getTextEdit()); }
Example #27
Source File: GroovyServicesCompletionTests.java From groovy-language-server with Apache License 2.0 | 6 votes |
@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 #28
Source File: TableBodyCompletionProvider.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getQueryExpressionSnippet(int data) { CompletionItem ci = new CompletionItem(); ci.setLabel("AS SELECT * FROM ..."); ci.setInsertText(" AS SELECT * FROM ${4:table_name};"); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); ci.setData(data); ci.setPreselect(true); return ci; }
Example #29
Source File: TableBodyCompletionProvider.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getPrimaryKeyCompletionItem(int data) { CompletionItem ci = new CompletionItem(); ci.setLabel("PRIMARY KEY (column, ...)"); ci.setInsertText("PRIMARY KEY (${1:column})"); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); ci.setData(data); ci.setPreselect(true); ci.setSortText("1120"); return ci; }
Example #30
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testCompletion_insert() throws Exception { ICompilationUnit unit = getCompletionOverwriteReplaceUnit(); int[] loc = findCompletionLocation(unit, "method(t."); try { JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setCompletionOverwrite(false); 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("testInt : int")).findFirst().orElse(null); assertNotNull(ci); assertEquals("testInt", ci.getInsertText()); assertEquals(CompletionItemKind.Field, ci.getKind()); assertEquals("999998554", ci.getSortText()); assertNotNull(ci.getTextEdit()); List<TextEdit> edits = new ArrayList<>(); edits.add(ci.getTextEdit()); String returned = TextEditUtil.apply(unit, edits); //@formatter:off String expected = "package foo.bar;\n\n" + "public class BaseTest {\n" + " public int testInt;\n\n" + " public boolean method(int x, int y, int z) {\n" + " return true;\n" + " } \n\n" + " public void update() {\n" + " BaseTest t = new BaseTest();\n" + " t.method(t.testIntthis.testInt, this.testInt);\n" + " }\n" + "}\n"; //@formatter:on assertEquals(returned, expected); } finally { JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setCompletionOverwrite(true); } }