Java Code Examples for org.eclipse.lsp4j.CompletionItem#setDocumentation()

The following examples show how to use org.eclipse.lsp4j.CompletionItem#setDocumentation() . 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: DdlCompletionItemLoader.java    From syndesis with Apache License 2.0 6 votes vote down vote up
/**
 * Clones a {@link CompletionItem} for the given label from the supplied items
 *
 * @param targetLabel
 * @return a completion item
 */
private static CompletionItem cloneCompletionItem(List<CompletionItem> items, String targetLabel) {
    for (CompletionItem item : items) {
        if (item.getLabel().equalsIgnoreCase(targetLabel)) {
            CompletionItem clone = new CompletionItem(targetLabel);
            clone.setAdditionalTextEdits(item.getAdditionalTextEdits());
            clone.setCommand(item.getCommand());
            clone.setData(item.getData());
            clone.setDetail(item.getDetail());
            clone.setFilterText(item.getFilterText());
            clone.setInsertText(item.getInsertText());
            clone.setInsertTextFormat(item.getInsertTextFormat());
            clone.setDocumentation(item.getDocumentation());
            clone.setDeprecated(item.getDeprecated());
            clone.setKind(item.getKind());
            clone.setSortText(item.getSortText());
            clone.setPreselect(item.getPreselect());
            clone.setTextEdit(item.getTextEdit());
            return clone;
        }
    }
    return null;
}
 
Example 2
Source File: ContentModelCompletionParticipant.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
private static void addCompletionItem(CMElementDeclaration elementDeclaration, DOMElement parentElement,
		String defaultPrefix, boolean forceUseOfPrefix, ICompletionRequest request, ICompletionResponse response,
		XMLGenerator generator, Set<String> tags) {
	String prefix = forceUseOfPrefix ? defaultPrefix
			: (parentElement != null ? parentElement.getPrefix(elementDeclaration.getNamespace()) : null);
	String label = elementDeclaration.getName(prefix);
	if (tags != null) {
		if (tags.contains(label)) {
			return;
		} else {
			tags.add(label);
		}
	}

	CompletionItem item = new CompletionItem(label);
	item.setFilterText(request.getFilterForStartTagName(label));
	item.setKind(CompletionItemKind.Property);
	MarkupContent documentation = XMLGenerator.createMarkupContent(elementDeclaration, request);
	item.setDocumentation(documentation);
	String xml = generator.generate(elementDeclaration, prefix,
			isGenerateEndTag(request.getNode(), request.getOffset(), label));
	item.setTextEdit(new TextEdit(request.getReplaceRange(), xml));
	item.setInsertTextFormat(InsertTextFormat.Snippet);
	response.addCompletionItem(item, true);
}
 
Example 3
Source File: CamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingDoubleQuotesInPlain() throws Exception {
	File f = new File("src/test/resources/workspace/samplewithModelineLikeWithDoubleQuotesInPlainInsideURI.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: CompletionItemBuilder.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public CompletionItem createSnippetItem(String label, String detail, String documentation, String insertText) {
    CompletionItem ci = new CompletionItem();
    ci.setLabel(label);
    ci.setKind(CompletionItemKind.Snippet);
    ci.setInsertTextFormat(InsertTextFormat.Snippet);
    ci.setInsertText(insertText);
    if (documentation != null) {
        ci.setDocumentation(documentation);
    } else {
        ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText()));
    }
    if (detail != null) {
        ci.setDetail(detail);
    }

    return ci;
}
 
Example 5
Source File: CamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingSingleQuotesInSingleQuotes() throws Exception {
	File f = new File("src/test/resources/workspace/samplewithModelineLikeWithSingleQuotesInSingleQuotesInsideURI.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, 47));
		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, 47), new Position(12, 47)), "anyOrder=false"));
		assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem);
	}
}
 
Example 6
Source File: CamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingDoubleQuotes() throws Exception {
	File f = new File("src/test/resources/workspace/samplewithModelineLikeWithDoubleQuotesInsideURI.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, 47));
		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, 47), new Position(12, 47)), "anyOrder=false"));
		assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem);
	}
}
 
Example 7
Source File: DdlCompletionItemLoader.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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 8
Source File: CamelComponentOptionsCompletionsTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: CamelComponentOptionsCompletionsTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: CamelComponentOptionsCompletionsTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: SnippetCompletionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static void setFields(CompletionItem ci, ICompilationUnit cu) {
	ci.setKind(CompletionItemKind.Snippet);
	ci.setInsertTextFormat(InsertTextFormat.Snippet);
	ci.setDocumentation(SnippetUtils.beautifyDocument(ci.getInsertText()));
	Map<String, String> data = new HashMap<>(3);
	data.put(CompletionResolveHandler.DATA_FIELD_URI, JDTUtils.toURI(cu));
	data.put(CompletionResolveHandler.DATA_FIELD_REQUEST_ID, "0");
	data.put(CompletionResolveHandler.DATA_FIELD_PROPOSAL_ID, "0");
	ci.setData(data);
}
 
Example 12
Source File: CamelExtraComponentTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
private CompletionItem createExpectedExtraComponentCompletionItem(int lineStart, int characterStart, int lineEnd, int characterEnd, String syntax, String description) {
	CompletionItem expectedAhcCompletioncompletionItem = new CompletionItem(syntax);
	expectedAhcCompletioncompletionItem.setDocumentation(description);
	expectedAhcCompletioncompletionItem.setDeprecated(false);
	expectedAhcCompletioncompletionItem.setTextEdit(new TextEdit(new Range(new Position(lineStart, characterStart), new Position(lineEnd, characterEnd)), syntax));
	return expectedAhcCompletioncompletionItem;
}
 
Example 13
Source File: CamelPropertiesComponentCompletionTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
protected CompletionItem createExpectedCompletionItem() {
	CompletionItem expectedCompletionItem = new CompletionItem("acomponent");
	expectedCompletionItem.setDocumentation("Description of my component.");
	expectedCompletionItem.setDeprecated(false);
	expectedCompletionItem.setTextEdit(new TextEdit(new Range(new Position(0, 16), new Position(0, 21)), "acomponent"));
	return expectedCompletionItem;
}
 
Example 14
Source File: CustomContentAssistService.java    From solidity-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition,
		Document document) {
	CompletionItem completionItem = super.toCompletionItem(entry, caretOffset, caretPosition, document);
	Either<String, MarkupContent> documentation = completionItem.getDocumentation();
	if (documentation != null && documentation.getLeft() == null && documentation.getRight()==null) {
		completionItem.setDocumentation((Either<String,MarkupContent>)null);
	}
	return completionItem;
}
 
Example 15
Source File: TableBodyCompletionProvider.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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 16
Source File: EntitiesCompletionParticipant.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private static void fillCompletion(String name, MarkupContent documentation, Range entityRange,
		ICompletionResponse response) {
	String entityName = "&" + name + ";";
	CompletionItem item = new CompletionItem();
	item.setLabel(entityName);
	item.setKind(CompletionItemKind.Keyword);
	item.setInsertTextFormat(InsertTextFormat.PlainText);
	String insertText = entityName;
	item.setFilterText(insertText);
	item.setTextEdit(new TextEdit(entityRange, insertText));
	item.setDocumentation(documentation);
	response.addCompletionItem(item);
}
 
Example 17
Source File: PrologModel.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private static void createCompletionItem(String attrName, boolean canSupportSnippet, boolean generateValue,
		Range editRange, String defaultValue, Collection<String> enumerationValues, String documentation,
		ICompletionResponse response, SharedSettings sharedSettings) {
	CompletionItem item = new AttributeCompletionItem(attrName, canSupportSnippet, editRange, generateValue,
			defaultValue, enumerationValues, sharedSettings);
	MarkupContent markup = new MarkupContent();
	markup.setKind(MarkupKind.MARKDOWN);

	markup.setValue(StringUtils.getDefaultString(documentation));
	item.setDocumentation(markup);
	response.addCompletionItem(item);
}
 
Example 18
Source File: CamelKModelineOptionNames.java    From camel-language-server with Apache License 2.0 4 votes vote down vote up
private static CompletionItem createCompletionItem(String label, String documentation) {
	CompletionItem completionItem = new CompletionItem(label);
	completionItem.setDocumentation(documentation);
	return completionItem;
}
 
Example 19
Source File: TraitDefinition.java    From camel-language-server with Apache License 2.0 4 votes vote down vote up
public CompletionItem createCompletionItem() {
	CompletionItem completionItem = new CompletionItem(name);
	completionItem.setDocumentation(description);
	return completionItem;
}
 
Example 20
Source File: CamelKModelineCompletionTest.java    From camel-language-server with Apache License 2.0 4 votes vote down vote up
private void checkTraitCompletionAvailable(List<CompletionItem> completionItems) {
	CompletionItem traitCompletionItem = new CompletionItem("trait");
	traitCompletionItem.setDocumentation("Configure a trait. E.g. \"trait=service.enabled=false\"");
	assertThat(completionItems).contains(traitCompletionItem);
}