Java Code Examples for org.eclipse.lsp4j.CompletionItem#setDetail()
The following examples show how to use
org.eclipse.lsp4j.CompletionItem#setDetail() .
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: CamelLanguageServerTest.java From camel-language-server with Apache License 2.0 | 6 votes |
@Test void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingSingleQuotes() throws Exception { File f = new File("src/test/resources/workspace/samplewithModelineLikeWithSingleQuotesInsideURI.yaml"); assertThat(f).exists(); try (FileInputStream fis = new FileInputStream(f)) { CamelLanguageServer cls = initializeLanguageServer(fis, ".yaml"); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(cls, new Position(12, 46)); CompletionItem expectedanyOrderAttributeCompletionItem = new CompletionItem("anyOrder"); expectedanyOrderAttributeCompletionItem.setDocumentation("Whether the expected messages should arrive in the same order or can be in any order."); expectedanyOrderAttributeCompletionItem.setDeprecated(false); expectedanyOrderAttributeCompletionItem.setDetail("boolean"); expectedanyOrderAttributeCompletionItem.setInsertText("anyOrder=false"); expectedanyOrderAttributeCompletionItem.setTextEdit(new TextEdit(new Range(new Position(12, 46), new Position(12, 46)), "anyOrder=false")); assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem); } }
Example 2
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
void createTypeProposalLabel(char[] fullName, CompletionItem item) { // only display innermost type name as type name, using any // enclosing types as qualification int qIndex= findSimpleNameStart(fullName); String name = new String(fullName, qIndex, fullName.length - qIndex); StringBuilder nameBuffer= new StringBuilder(); nameBuffer.append(name); if (qIndex > 0) { nameBuffer.append(PACKAGE_NAME_SEPARATOR); nameBuffer.append(new String(fullName,0,qIndex-1)); } item.setFilterText(name); item.setInsertText(name); item.setLabel(nameBuffer.toString()); item.setDetail(new String(fullName)); }
Example 3
Source File: CamelLanguageServerTest.java From camel-language-server with Apache License 2.0 | 6 votes |
@Test void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingSingleQuotesInPlain() throws Exception { File f = new File("src/test/resources/workspace/samplewithModelineLikeWithSingleQuotesInPlainInsideURI.yaml"); assertThat(f).exists(); try (FileInputStream fis = new FileInputStream(f)) { CamelLanguageServer cls = initializeLanguageServer(fis, ".yaml"); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(cls, new Position(12, 45)); CompletionItem expectedanyOrderAttributeCompletionItem = new CompletionItem("anyOrder"); expectedanyOrderAttributeCompletionItem.setDocumentation("Whether the expected messages should arrive in the same order or can be in any order."); expectedanyOrderAttributeCompletionItem.setDeprecated(false); expectedanyOrderAttributeCompletionItem.setDetail("boolean"); expectedanyOrderAttributeCompletionItem.setInsertText("anyOrder=false"); expectedanyOrderAttributeCompletionItem.setTextEdit(new TextEdit(new Range(new Position(12, 45), new Position(12, 45)), "anyOrder=false")); assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem); } }
Example 4
Source File: CamelLanguageServerTest.java From camel-language-server with Apache License 2.0 | 6 votes |
@Test void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingDoubleQuotesInPlainUsingMoreSpaces() throws Exception { File f = new File("src/test/resources/workspace/samplewithModelineLikeWithDoubleQuotesInPlainInsideURIUsingMoreSpaces.yaml"); assertThat(f).exists(); try (FileInputStream fis = new FileInputStream(f)) { CamelLanguageServer cls = initializeLanguageServer(fis, ".yaml"); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(cls, new Position(12, 50)); CompletionItem expectedanyOrderAttributeCompletionItem = new CompletionItem("anyOrder"); expectedanyOrderAttributeCompletionItem.setDocumentation("Whether the expected messages should arrive in the same order or can be in any order."); expectedanyOrderAttributeCompletionItem.setDeprecated(false); expectedanyOrderAttributeCompletionItem.setDetail("boolean"); expectedanyOrderAttributeCompletionItem.setInsertText("anyOrder=false"); expectedanyOrderAttributeCompletionItem.setTextEdit(new TextEdit(new Range(new Position(12, 50), new Position(12, 50)), "anyOrder=false")); assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem); } }
Example 5
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void createAnonymousTypeLabel(CompletionProposal proposal, CompletionItem item) { char[] declaringTypeSignature= proposal.getDeclarationSignature(); declaringTypeSignature= Signature.getTypeErasure(declaringTypeSignature); String name = new String(Signature.getSignatureSimpleName(declaringTypeSignature)); item.setInsertText(name); StringBuilder buf= new StringBuilder(); buf.append(name); buf.append('('); appendUnboundedParameterList(buf, proposal); buf.append(')'); buf.append(" "); //$NON-NLS-1$ buf.append("Anonymous Inner Type"); //TODO: consider externalization item.setLabel(buf.toString()); if (proposal.getRequiredProposals() != null) { char[] signatureQualifier= Signature.getSignatureQualifier(declaringTypeSignature); if (signatureQualifier.length > 0) { item.setDetail(String.valueOf(signatureQualifier) + "." + name); } } setDeclarationSignature(item, String.valueOf(declaringTypeSignature)); }
Example 6
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void createJavadocTypeProposalLabel(char[] fullName, CompletionItem item) { // only display innermost type name as type name, using any // enclosing types as qualification int qIndex= findSimpleNameStart(fullName); StringBuilder nameBuffer= new StringBuilder(); String name = new String(fullName, qIndex, fullName.length - qIndex); nameBuffer.append("{@link "); //$NON-NLS-1$ nameBuffer.append(name); nameBuffer.append('}'); item.setLabel(nameBuffer.toString()); item.setFilterText(name); if (qIndex > 0) { item.setDetail(new String(fullName, 0, qIndex - 1)); } }
Example 7
Source File: DdlCompletionItemLoader.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getCreateViewCompletionItem(int data, String sortValue) { CompletionItem ci = new CompletionItem(); ci.setLabel("CREATE VIEW..."); ci.setInsertText(QueryExpressionHelper.CREATE_VIEW_INSERT_TEXT); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setDetail("Simple CREATE VIEW statement"); ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); ci.setData(data); ci.setPreselect(true); ci.setSortText(sortValue); return ci; }
Example 8
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void createPackageProposalLabel(CompletionProposal proposal, CompletionItem item) { Assert.isTrue(proposal.getKind() == CompletionProposal.PACKAGE_REF || proposal.getKind() == CompletionProposal.MODULE_REF || proposal.getKind() == CompletionProposal.MODULE_DECLARATION); item.setLabel(String.valueOf(proposal.getDeclarationSignature())); StringBuilder detail = new StringBuilder(); detail.append(proposal.getKind() == CompletionProposal.PACKAGE_REF ? "(package) " : "(module) "); detail.append(String.valueOf(proposal.getDeclarationSignature())); item.setDetail(detail.toString()); }
Example 9
Source File: DdlCompletionItemLoader.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getCreateViewInnerJoinCompletionItem(int data, String sortValue) { CompletionItem ci = new CompletionItem(); ci.setLabel("CREATE VIEW with INNER JOIN"); ci.setInsertText(QueryExpressionHelper.CREATE_VIEW_INNER_JOIN_INSERT_TEXT); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setDetail(" CREATE VIEW with inner join"); ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); ci.setData(data); ci.setPreselect(true); ci.setSortText(sortValue); return ci; }
Example 10
Source File: CompletionItemBuilder.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem createKeywordItem(String label, String detail, String documentation) { CompletionItem ci = new CompletionItem(); ci.setLabel(label); ci.setKind(CompletionItemKind.Keyword); if (detail != null) { ci.setDetail(detail); } if (documentation != null) { ci.setDocumentation(documentation); } return ci; }
Example 11
Source File: XContentAssistService.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Convert to a completion item. */ protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition, Document document) { CompletionItem result = new CompletionItem(); String label = null; if (entry.getLabel() != null) { label = entry.getLabel(); } else { label = entry.getProposal(); } result.setLabel(label); result.setDetail(entry.getDescription()); result.setDocumentation(entry.getDocumentation()); String prefix = null; if (entry.getPrefix() != null) { prefix = entry.getPrefix(); } else { prefix = ""; } Position prefixPosition = document.getPosition(caretOffset - prefix.length()); result.setTextEdit(new TextEdit(new Range(prefixPosition, caretPosition), entry.getProposal())); if (!entry.getTextReplacements().isEmpty()) { if (result.getAdditionalTextEdits() == null) { result.setAdditionalTextEdits(new ArrayList<>(entry.getTextReplacements().size())); } entry.getTextReplacements().forEach(it -> { result.getAdditionalTextEdits().add(toTextEdit(it, document)); }); } if (entry.getKind().startsWith(ContentAssistEntry.KIND_SNIPPET + ":")) { result.setInsertTextFormat(InsertTextFormat.Snippet); entry.setKind(entry.getKind().substring(ContentAssistEntry.KIND_SNIPPET.length() + 1)); } else if (Objects.equal(entry.getKind(), ContentAssistEntry.KIND_SNIPPET)) { result.setInsertTextFormat(InsertTextFormat.Snippet); } result.setKind(translateKind(entry)); return result; }
Example 12
Source File: CamelPropertiesComponentOptionNameCompletionTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@Test void testInsertAndReplace() throws Exception { CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = retrieveCompletion(new Position(0, 27), "camel.component.acomponent.awrongtoreplace=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, 42)), "aComponentProperty")); assertThat(completions.get().getLeft()).contains(expectedCompletionItem); }
Example 13
Source File: CamelPropertiesComponentOptionNameCompletionTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@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); }
Example 14
Source File: CamelComponentOptionsCompletionsTest.java From camel-language-server with Apache License 2.0 | 5 votes |
private CompletionItem getBridgeEndpointExpectedCompletionItem(int startCharacter, int endCharacter) { CompletionItem completionItem = new CompletionItem("bridgeEndpoint"); completionItem.setInsertText("bridgeEndpoint=false"); completionItem.setTextEdit(new TextEdit(new Range(new Position(0, startCharacter), new Position(0, endCharacter)), "bridgeEndpoint=false")); completionItem.setDocumentation("If the option is true, then the Exchange.HTTP_URI header is ignored, and use the endpoint's URI for request. You may also set the throwExceptionOnFailure to be false to let the AhcProducer send all the fault response back."); completionItem.setDetail("boolean"); completionItem.setDeprecated(false); return completionItem; }
Example 15
Source File: CamelComponentOptionsCompletionsTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@Test void testProvideCamelOptionsForConsumerOrProducer() throws Exception { CompletionItem completionItem = new CompletionItem("clientConfigOptions"); completionItem.setInsertText("clientConfigOptions="); completionItem.setTextEdit(new TextEdit(new Range(new Position(0, 23), new Position(0, 23)), "clientConfigOptions=")); completionItem.setDocumentation("To configure the AsyncHttpClientConfig using the key/values from the Map."); completionItem.setDetail("java.util.Map<java.lang.String, java.lang.Object>"); completionItem.setDeprecated(false); testProvideCamelOptions("<from uri=\"ahc:httpUri?\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 23, completionItem); }
Example 16
Source File: CamelComponentOptionsCompletionsTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@Test void testProvideCamelOptionsForConsumerOnlyForJava() throws Exception { CompletionItem completionItem = new CompletionItem("bridgeErrorHandler"); completionItem.setInsertText("bridgeErrorHandler=false"); completionItem.setTextEdit(new TextEdit(new Range(new Position(0, 22), new Position(0, 22)), "bridgeErrorHandler=false")); completionItem.setDocumentation("Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored."); completionItem.setDetail("boolean"); completionItem.setDeprecated(false); testProvideCamelOptions("from(\"timer:timerName?\")//camel", 0, 22, completionItem, ".java"); }
Example 17
Source File: CamelComponentOptionsCompletionsTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@Test void testProvideCamelOptionsForConsumerOnly() throws Exception { CompletionItem completionItem = new CompletionItem("bridgeErrorHandler"); completionItem.setInsertText("bridgeErrorHandler=false"); completionItem.setTextEdit(new TextEdit(new Range(new Position(0, 27), new Position(0, 27)), "bridgeErrorHandler=false")); completionItem.setDocumentation("Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored."); completionItem.setDetail("boolean"); completionItem.setDeprecated(false); testProvideCamelOptions("<from uri=\"timer:timerName?\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 27, completionItem); }
Example 18
Source File: DdlCompletionItemLoader.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getCreateViewJoinCompletionItem(int data, String sortValue) { CompletionItem ci = new CompletionItem(); ci.setLabel("CREATE VIEW with JOIN"); ci.setInsertText(QueryExpressionHelper.CREATE_VIEW_LEFT_OUTER_JOIN_INSERT_TEXT); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setDetail(" CREATE VIEW with left join"); ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); ci.setData(data); ci.setPreselect(true); ci.setSortText(sortValue); return ci; }
Example 19
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void createOverrideMethodProposalLabel(CompletionProposal methodProposal, CompletionItem item) { StringBuilder nameBuffer= new StringBuilder(); // method name String name = new String(methodProposal.getName()); item.setInsertText(name); nameBuffer.append(name); // parameters nameBuffer.append('('); appendUnboundedParameterList(nameBuffer, methodProposal); nameBuffer.append(')'); nameBuffer.append(RETURN_TYPE_SEPARATOR); // return type // TODO remove SignatureUtil.fix83600 call when bugs are fixed char[] returnType= createTypeDisplayName(SignatureUtil.getUpperBound(Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature())))); nameBuffer.append(returnType); item.setLabel(nameBuffer.toString()); item.setFilterText(name); // declaring type StringBuilder typeBuffer = new StringBuilder(); String declaringType= extractDeclaringTypeFQN(methodProposal); declaringType= Signature.getSimpleName(declaringType); typeBuffer.append(String.format("Override method in '%s'", declaringType)); item.setDetail(typeBuffer.toString()); setSignature(item, String.valueOf(methodProposal.getSignature())); setDeclarationSignature(item, String.valueOf(methodProposal.getDeclarationSignature())); setName(item, String.valueOf(methodProposal.getName())); }
Example 20
Source File: DdlCompletionItemLoader.java From syndesis with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private List<CompletionItem> loadItemsFromFile(String fileName) { List<CompletionItem> items = new ArrayList<CompletionItem>(); try (InputStream stream = this.getClass().getResourceAsStream(fileName)) { JSONParser parser = new JSONParser(stream); // A JSON object. Key value pairs are unordered. JSONObject supports // java.util.Map interface. LinkedHashMap<String, Object> jsonObject = parser.object(); // A JSON array. JSONObject supports java.util.List interface. ArrayList<?> completionItemArray = (ArrayList<?>) jsonObject.get("items"); if (completionItemArray != null) { for (Object item : completionItemArray) { LinkedHashMap<String, Object> itemInfo = (LinkedHashMap<String, Object>) item; CompletionItem newItem = new CompletionItem(); newItem.setLabel((String) itemInfo.get("label")); newItem.setKind(STRING_TO_KIND_MAP.get(((String) itemInfo.get("kind")).toUpperCase(Locale.US))); String detail = (String) itemInfo.get("detail"); if (detail != null) { newItem.setDetail(detail); } String documentation = (String) itemInfo.get("documentation"); if (documentation != null) { newItem.setDocumentation(documentation); } newItem.setDeprecated(Boolean.parseBoolean((String) itemInfo.get("deprecated"))); newItem.setPreselect(Boolean.parseBoolean((String) itemInfo.get("preselect"))); String sortText = (String) itemInfo.get("sortText"); if (sortText != null) { newItem.setSortText(sortText); } String insertText = (String) itemInfo.get("insertText"); if (insertText != null) { insertText = insertText.replaceAll("\\n", "\n"); insertText = insertText.replaceAll("\\t", "\t"); newItem.setInsertText(insertText); } String insertTextFormat = (String) itemInfo.get("insertTextFormat"); if (insertTextFormat != null) { if (newItem.getKind().equals(CompletionItemKind.Snippet)) { newItem.setInsertTextFormat(InsertTextFormat.Snippet); } else { newItem.setInsertTextFormat(InsertTextFormat.PlainText); } } // TODO: Implement quick fixes // newItem.setTextEdit((TextEdit)itemInfo.get("textEdit")); // newItem.setAdditionalTextEdits((List<TextEdit>)itemInfo.get("additionalTextEdits")); // newItem.setCommitCharacters((List<String>)itemInfo.get("commitCharacters")); String category = (String) itemInfo.get("category"); if (category != null && !category.isEmpty()) { addItemByCategory(category, newItem); } else { items.add(newItem); } } } } catch (IOException | ParseException e) { throw new IllegalArgumentException("Unable to parse given file: " + fileName, e); } return items; }