Java Code Examples for org.eclipse.lsp4j.CompletionItem#getData()
The following examples show how to use
org.eclipse.lsp4j.CompletionItem#getData() .
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 |
@Test public void testCompletion_dataFieldURI() throws Exception { ICompilationUnit unit = getWorkingCopy( "src/java/Foo.java", "public class Foo {\n"+ " void foo() {\n"+ " Objec\n"+ " }\n"+ "}\n"); int[] loc = findCompletionLocation(unit, "Objec"); CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight(); assertNotNull(list); assertFalse("No proposals were found",list.getItems().isEmpty()); List<CompletionItem> items = new ArrayList<>(list.getItems()); for ( CompletionItem item : items) { @SuppressWarnings("unchecked") Map<String,String> data = (Map<String, String>) item.getData(); assertNotNull(data); String uri = data.get(CompletionResolveHandler.DATA_FIELD_URI); assertTrue(isNotBlank(uri)); assertTrue("unexpected URI prefix: " + uri, uri.matches("file://.*/src/java/Foo\\.java")); } }
Example 2
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testCompletion_object() throws Exception{ ICompilationUnit unit = getWorkingCopy( "src/java/Foo.java", "public class Foo {\n"+ " void foo() {\n"+ " Objec\n"+ " }\n"+ "}\n"); int[] loc = findCompletionLocation(unit, "Objec"); CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight(); assertNotNull(list); assertFalse("No proposals were found",list.getItems().isEmpty()); List<CompletionItem> items = list.getItems(); for ( CompletionItem item : items) { assertTrue(isNotBlank(item.getLabel())); assertNotNull(item.getKind() ); assertTrue(isNotBlank(item.getSortText())); //text edits are set during calls to "completion" assertNotNull(item.getTextEdit()); assertTrue(isNotBlank(item.getInsertText())); assertNotNull(item.getFilterText()); assertFalse(item.getFilterText().contains(" ")); assertTrue(item.getLabel().startsWith(item.getInsertText())); assertTrue(item.getFilterText().startsWith("Objec")); //Check contains data used for completionItem resolution @SuppressWarnings("unchecked") Map<String,String> data = (Map<String, String>) item.getData(); assertNotNull(data); assertTrue(isNotBlank(data.get(CompletionResolveHandler.DATA_FIELD_URI))); assertTrue(isNotBlank(data.get(CompletionResolveHandler.DATA_FIELD_PROPOSAL_ID))); assertTrue(isNotBlank(data.get(CompletionResolveHandler.DATA_FIELD_REQUEST_ID))); } }
Example 3
Source File: SyntaxServerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Test public void testCompletionOnSingleName() throws Exception{ URI fileURI = openFile("maven/salut4", "src/main/java/java/Completion.java"); ICompilationUnit cu = JDTUtils.resolveCompilationUnit(fileURI); assertNotNull(cu); cu.getBuffer().setContents("package java;\n\n" + "public class Completion {\n" + " void foo() {\n" + " Objec\n" + " }\n" + "}\n"); cu.makeConsistent(null); int[] loc = findLocation(cu, "Objec"); String fileUri = ResourceUtils.fixURI(fileURI); TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri); CompletionParams params = new CompletionParams(identifier, new Position(loc[0], loc[1])); CompletionList list = server.completion(params).join().getRight(); assertNotNull(list); assertFalse("No proposals were found", list.getItems().isEmpty()); List<CompletionItem> items = list.getItems(); for (CompletionItem item : items) { assertTrue(StringUtils.isNotBlank(item.getLabel())); assertNotNull(item.getKind()); assertTrue(StringUtils.isNotBlank(item.getSortText())); //text edits are set during calls to "completion" assertNotNull(item.getTextEdit()); assertTrue(StringUtils.isNotBlank(item.getInsertText())); assertNotNull(item.getFilterText()); assertFalse(item.getFilterText().contains(" ")); assertTrue(item.getLabel().startsWith(item.getInsertText())); assertTrue(item.getFilterText().startsWith("Objec")); //Check contains data used for completionItem resolution @SuppressWarnings("unchecked") Map<String,String> data = (Map<String, String>) item.getData(); assertNotNull(data); assertTrue(StringUtils.isNotBlank(data.get(CompletionResolveHandler.DATA_FIELD_URI))); assertTrue(StringUtils.isNotBlank(data.get(CompletionResolveHandler.DATA_FIELD_PROPOSAL_ID))); assertTrue(StringUtils.isNotBlank(data.get(CompletionResolveHandler.DATA_FIELD_REQUEST_ID))); } }