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

The following examples show how to use org.eclipse.lsp4j.CompletionItem#setTextEdit() . 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: 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 2
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 3
Source File: CamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: CamelPropertiesComponentOptionNameCompletionTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: CamelPropertiesComponentOptionEnumerationValuesCompletionTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideCompletionIsFilteredWhenInsideValue() throws Exception {
	CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = retrieveCompletion(new Position(0, 53), "camel.component.acomponent.errorHandlerLoggingLevel=T");
	
	CompletionItem expectedCompletionItem = new CompletionItem("TRACE");
	expectedCompletionItem.setTextEdit(new TextEdit(new Range(new Position(0, 52), new Position(0, 53)), "TRACE"));
	
	assertThat(completions.get().getLeft()).containsOnly(expectedCompletionItem);
}
 
Example 6
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 7
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 8
Source File: AbstractCamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
protected CompletionItem createExpectedAhcCompletionItem(int lineStart, int characterStart, int lineEnd, int characterEnd) {
	CompletionItem expectedAhcCompletioncompletionItem = new CompletionItem("ahc:httpUri");
	expectedAhcCompletioncompletionItem.setDocumentation(AHC_DOCUMENTATION);
	expectedAhcCompletioncompletionItem.setDeprecated(false);
	expectedAhcCompletioncompletionItem.setTextEdit(new TextEdit(new Range(new Position(lineStart, characterStart), new Position(lineEnd, characterEnd)), "ahc:httpUri"));
	return expectedAhcCompletioncompletionItem;
}
 
Example 9
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 10
Source File: Snippet.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
public ICompletionProposal convertToCompletionProposal(int offset, LSPDocumentInfo info, String prefix,
		String lineIndentation, Range textRange) {
	CompletionItem item = new CompletionItem();
	item.setLabel(display);
	item.setKind(kind);
	item.setInsertTextFormat(InsertTextFormat.Snippet);

	IDocument document = info.getDocument();
	// if there is a text selection, take it, since snippets with $TM_SELECTED_TEXT
	// will want to wrap the selection.
	item.setTextEdit(new TextEdit(textRange, createReplacement(lineIndentation)));
	return new LSCompletionProposal(document, offset, item, getLanguageClient(info));
}
 
Example 11
Source File: ContentAssistService.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition,
		Document document) {
	CompletionItem completionItem = new CompletionItem();
	String label = entry.getLabel();
	if (label == null) {
		label = entry.getProposal();
	}
	completionItem.setLabel(label);
	completionItem.setDetail(entry.getDescription());
	completionItem.setDocumentation(entry.getDocumentation());
	String prefix = entry.getPrefix();
	if (prefix == null) {
		prefix = "";
	}
	int prefixOffset = caretOffset - prefix.length();
	Position prefixPosition = document.getPosition(prefixOffset);
	completionItem.setTextEdit(new TextEdit(new Range(prefixPosition, caretPosition), entry.getProposal()));
	completionItem.setKind(translateKind(entry));
	if (!entry.getTextReplacements().isEmpty()) {
		if (completionItem.getAdditionalTextEdits() == null) {
			completionItem.setAdditionalTextEdits(new ArrayList<>(entry.getTextReplacements().size()));
		}
		entry.getTextReplacements().forEach(
				(ReplaceRegion it) -> completionItem.getAdditionalTextEdits().add(toTextEdit(it, document)));
	}
	if (ContentAssistEntry.KIND_SNIPPET.equals(entry.getKind())) {
		completionItem.setInsertTextFormat(InsertTextFormat.Snippet);
	}
	return completionItem;
}
 
Example 12
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 13
Source File: HTMLCompletionExtensionsTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onAttributeName(boolean generateValue, ICompletionRequest completionRequest,
		ICompletionResponse completionResponse) {
	String tag = completionRequest.getCurrentTag();
	HTMLTag htmlTag = HTMLTag.getHTMLTag(tag);
	if (htmlTag != null) {
		String[] attributes = htmlTag.getAttributes();
		if (attributes != null) {
			Range replaceRange = completionRequest.getReplaceRange();
			for (String attribute : attributes) {
				int index = attribute.indexOf(":");
				if (index != -1) {
					attribute = attribute.substring(0, index);
				}
				if (!completionResponse.hasAttribute(attribute)) {
					CompletionItem item = new CompletionItem();
					item.setLabel(attribute);
					item.setKind(CompletionItemKind.Value);
					String value = generateValue ? "=\"$1\"" : "";
					item.setTextEdit(new TextEdit(replaceRange, attribute + value));
					item.setInsertTextFormat(InsertTextFormat.Snippet);
					completionResponse.addCompletionAttribute(item);
				}
			}
		}
	}
}
 
Example 14
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);
}
 
Example 15
Source File: XMLAssert.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
public static CompletionItem c(String label, TextEdit textEdit, String filterText, String documentation,
		String kind) {
	CompletionItem item = new CompletionItem();
	item.setLabel(label);
	item.setFilterText(filterText);
	item.setTextEdit(textEdit);
	if (kind == null) {
		item.setDocumentation(documentation);
	} else {
		item.setDocumentation(new MarkupContent(kind, documentation));
	}
	return item;
}
 
Example 16
Source File: XContentAssistService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 17
Source File: XMLCompletions.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private void collectionRegionProposals(ICompletionRequest request, ICompletionResponse response) {
	// Completion for #region
	try {
		int offset = request.getOffset();
		TextDocument document = request.getXMLDocument().getTextDocument();
		Position pos = document.positionAt(offset);
		String lineText = document.lineText(pos.getLine());
		String lineUntilPos = lineText.substring(0, pos.getCharacter());
		Matcher match = regionCompletionRegExpr.matcher(lineUntilPos);
		if (match.find()) {
			InsertTextFormat insertFormat = request.getInsertTextFormat();
			Range range = new Range(new Position(pos.getLine(), pos.getCharacter() + match.regionStart()), pos);

			String text = request.isCompletionSnippetsSupported() ? "<!-- #region $1-->" : "<!-- #region -->";
			CompletionItem beginProposal = new CompletionItem("#region");
			beginProposal.setTextEdit(new TextEdit(range, text));
			beginProposal.setDocumentation("Insert Folding Region Start");
			beginProposal.setFilterText(match.group());
			beginProposal.setSortText("za");
			beginProposal.setKind(CompletionItemKind.Snippet);
			beginProposal.setInsertTextFormat(insertFormat);
			response.addCompletionAttribute(beginProposal);

			CompletionItem endProposal = new CompletionItem("#endregion");
			endProposal.setTextEdit(new TextEdit(range, "<!-- #endregion-->"));
			endProposal.setDocumentation("Insert Folding Region End");
			endProposal.setFilterText(match.group());
			endProposal.setSortText("zb");
			endProposal.setKind(CompletionItemKind.Snippet);
			endProposal.setInsertTextFormat(InsertTextFormat.PlainText);
			response.addCompletionAttribute(endProposal);
		}
	} catch (BadLocationException e) {
		LOGGER.log(Level.SEVERE, "While performing collectRegionCompletion", e);
	}
}
 
Example 18
Source File: JavadocCompletionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public List<CompletionItem> getProposals(ICompilationUnit cu, int offset, CompletionProposalRequestor collector, IProgressMonitor monitor) throws JavaModelException {
	if (cu == null) {
		throw new IllegalArgumentException("Compilation unit must not be null"); //$NON-NLS-1$
	}
	List<CompletionItem> result = new ArrayList<>();
	IDocument d = JsonRpcHelpers.toDocument(cu.getBuffer());
	if (offset < 0 || d.getLength() == 0) {
		return result;
	}
	try {
		int p = (offset == d.getLength() ? offset - 1 : offset);
		IRegion line = d.getLineInformationOfOffset(p);
		String lineStr = d.get(line.getOffset(), line.getLength()).trim();
		if (!lineStr.startsWith("/**")) {
			return result;
		}
		if (!hasEndJavadoc(d, offset)) {
			return result;
		}
		String text = collector.getContext().getToken() == null ? "" : new String(collector.getContext().getToken());
		StringBuilder buf = new StringBuilder(text);
		IRegion prefix = findPrefixRange(d, line);
		String indentation = d.get(prefix.getOffset(), prefix.getLength());
		int lengthToAdd = Math.min(offset - prefix.getOffset(), prefix.getLength());
		buf.append(indentation.substring(0, lengthToAdd));
		String lineDelimiter = TextUtilities.getDefaultLineDelimiter(d);
		ICompilationUnit unit = cu;
		try {
			unit.reconcile(ICompilationUnit.NO_AST, false, null, null);
			String string = createJavaDocTags(d, offset, indentation, lineDelimiter, unit);
			if (string != null && !string.trim().equals(ASTERISK)) {
				buf.append(string);
			} else {
				return result;
			}
			int nextNonWS = findEndOfWhiteSpace(d, offset, d.getLength());
			if (!Character.isWhitespace(d.getChar(nextNonWS))) {
				buf.append(lineDelimiter);
			}
		} catch (CoreException e) {
			// ignore
		}
		final CompletionItem ci = new CompletionItem();
		Range range = JDTUtils.toRange(unit, offset, 0);
		boolean isSnippetSupported = JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isCompletionSnippetsSupported();
		String replacement = prepareTemplate(buf.toString(), lineDelimiter, isSnippetSupported);
		ci.setTextEdit(new TextEdit(range, replacement));
		ci.setFilterText(JAVA_DOC_COMMENT);
		ci.setLabel(JAVA_DOC_COMMENT);
		ci.setSortText(SortTextHelper.convertRelevance(0));
		ci.setKind(CompletionItemKind.Snippet);
		ci.setInsertTextFormat(isSnippetSupported ? InsertTextFormat.Snippet : InsertTextFormat.PlainText);
		String documentation = prepareTemplate(buf.toString(), lineDelimiter, false);
		if (documentation.indexOf(lineDelimiter) == 0) {
			documentation = documentation.replaceFirst(lineDelimiter, "");
		}
		ci.setDocumentation(documentation);
		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);
		result.add(ci);
	} catch (BadLocationException excp) {
		// stop work
	}
	return result;
}
 
Example 19
Source File: CompletionProposalReplacementProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private void updateReplacement(CompletionProposal proposal, CompletionItem item, char trigger, boolean isResolving) {
	// reset importRewrite
	this.importRewrite = TypeProposalUtils.createImportRewrite(compilationUnit);

	List<org.eclipse.lsp4j.TextEdit> additionalTextEdits = new ArrayList<>();

	StringBuilder completionBuffer = new StringBuilder();
	Range range = null;
	if (isSupportingRequiredProposals(proposal)) {
		CompletionProposal[] requiredProposals = proposal.getRequiredProposals();
		if (requiredProposals != null) {
			for (CompletionProposal requiredProposal : requiredProposals) {
				switch (requiredProposal.getKind()) {
				case CompletionProposal.TYPE_IMPORT:
				case CompletionProposal.METHOD_IMPORT:
				case CompletionProposal.FIELD_IMPORT:
					appendImportProposal(completionBuffer, requiredProposal, proposal.getKind());
					break;
				case CompletionProposal.TYPE_REF:
					org.eclipse.lsp4j.TextEdit edit = toRequiredTypeEdit(requiredProposal, trigger, proposal.canUseDiamond(context));
					if (proposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION
						|| proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION
						|| proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_DECLARATION) {
							completionBuffer.append(edit.getNewText());
							range = edit.getRange();
					} else {
						additionalTextEdits.add(edit);
					}
					break;
				default:
					/*
					 * In 3.3 we only support the above required proposals, see
					 * CompletionProposal#getRequiredProposals()
					 */
					Assert.isTrue(false);
				}
			}
		}
	}

	if (range == null) {
		boolean completionOverwrite = preferences.isCompletionOverwrite();
		if (!completionOverwrite && (proposal.getKind() == CompletionProposal.METHOD_REF || proposal.getKind() == CompletionProposal.LOCAL_VARIABLE_REF || proposal.getKind() == CompletionProposal.FIELD_REF)) {
			// See https://github.com/redhat-developer/vscode-java/issues/462
			int end = proposal.getReplaceEnd();
			if (end > offset) {
				proposal.setReplaceRange(proposal.getReplaceStart(), offset);
			}
		}
		range = toReplacementRange(proposal);
	}
	if (proposal.getKind() == CompletionProposal.METHOD_DECLARATION) {
		appendMethodOverrideReplacement(completionBuffer, proposal);
	} else if (proposal.getKind() == CompletionProposal.POTENTIAL_METHOD_DECLARATION && proposal instanceof GetterSetterCompletionProposal) {
		appendMethodPotentialReplacement(completionBuffer, (GetterSetterCompletionProposal) proposal);
	} else if (proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION || proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_DECLARATION) {
		appendAnonymousClass(completionBuffer, proposal, range);
	} else {
		appendReplacementString(completionBuffer, proposal);
	}
	//select insertTextFormat.
	if (client.isCompletionSnippetsSupported()) {
		item.setInsertTextFormat(InsertTextFormat.Snippet);
	} else {
		item.setInsertTextFormat(InsertTextFormat.PlainText);
	}
	String text = completionBuffer.toString();
	if (range != null) {
		item.setTextEdit(new org.eclipse.lsp4j.TextEdit(range, text));
	} else {
		// fallback
		item.setInsertText(text);
	}

	if (!client.isResolveAdditionalTextEditsSupport() || isResolving) {
		addImports(additionalTextEdits);
		if(!additionalTextEdits.isEmpty()){
			item.setAdditionalTextEdits(additionalTextEdits);
		}
	}
}
 
Example 20
Source File: CamelComponentOptionEnumerationValuesTest.java    From camel-language-server with Apache License 2.0 4 votes vote down vote up
private CompletionItem createExpectedCompletionItem(String enumOption) {
	CompletionItem completionItem = new CompletionItem(enumOption);
	completionItem.setTextEdit(new TextEdit(new Range(new Position(0, 43), new Position(0, 43)), enumOption));
	return completionItem;
}