Java Code Examples for org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry#getLabel()

The following examples show how to use org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry#getLabel() . 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: 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 2
Source File: UiToIdeContentProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected StyledString getDisplayString(ContentAssistEntry entry) {
	StyledString result = new StyledString(entry.getLabel() != null ? entry.getLabel() : entry.getProposal());
	if (!Strings.isNullOrEmpty(entry.getDescription())) {
		result.append(new StyledString(" \u2013 " + entry.getDescription(), StyledString.QUALIFIER_STYLER));
	}
	return result;
}
 
Example 3
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;
}