Java Code Examples for org.eclipse.lsp4j.CompletionItemKind#Keyword

The following examples show how to use org.eclipse.lsp4j.CompletionItemKind#Keyword . 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: EditorEventManager.java    From lsp4intellij with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a LookupElement given a CompletionItem
 *
 * @param item The CompletionItem
 * @return The corresponding LookupElement
 */
@SuppressWarnings("WeakerAccess")
public LookupElement createLookupItem(CompletionItem item) {
    Command command = item.getCommand();
    String detail = item.getDetail();
    String insertText = item.getInsertText();
    CompletionItemKind kind = item.getKind();
    String label = item.getLabel();
    TextEdit textEdit = item.getTextEdit();
    List<TextEdit> addTextEdits = item.getAdditionalTextEdits();
    String presentableText = StringUtils.isNotEmpty(label) ? label : (insertText != null) ? insertText : "";
    String tailText = (detail != null) ? detail : "";
    LSPIconProvider iconProvider = GUIUtils.getIconProviderFor(wrapper.getServerDefinition());
    Icon icon = iconProvider.getCompletionIcon(kind);
    LookupElementBuilder lookupElementBuilder;

    String lookupString = null;
    if (textEdit != null) {
        lookupString = textEdit.getNewText();
    } else if (StringUtils.isNotEmpty(insertText)) {
        lookupString = insertText;
    } else if (StringUtils.isNotEmpty(label)) {
        lookupString = label;
    }
    if (StringUtils.isEmpty(lookupString)) {
        return null;
    }
    // Fixes IDEA internal assertion failure in windows.
    lookupString = lookupString.replace(DocumentUtils.WIN_SEPARATOR, DocumentUtils.LINUX_SEPARATOR);
    if (item.getInsertTextFormat() == InsertTextFormat.Snippet) {
        lookupElementBuilder = LookupElementBuilder.create(convertPlaceHolders(lookupString));
    } else {
        lookupElementBuilder = LookupElementBuilder.create(lookupString);
    }

    lookupElementBuilder = addCompletionInsertHandlers(item, lookupElementBuilder, lookupString);

    if (kind == CompletionItemKind.Keyword) {
        lookupElementBuilder = lookupElementBuilder.withBoldness(true);
    }

    return lookupElementBuilder.withPresentableText(presentableText).withTypeText(tailText, true).withIcon(icon)
            .withAutoCompletionPolicy(AutoCompletionPolicy.SETTINGS_DEPENDENT);
}
 
Example 2
Source File: XContentAssistService.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Translate to a completion item kind.
 */
protected CompletionItemKind translateKind(ContentAssistEntry entry) {
	CompletionItemKind result = null;
	if (entry.getKind() != null) {
		switch (entry.getKind()) {
		case ContentAssistEntry.KIND_CLASS:
			result = CompletionItemKind.Class;
			break;
		case ContentAssistEntry.KIND_COLOR:
			result = CompletionItemKind.Color;
			break;
		case ContentAssistEntry.KIND_CONSTRUCTOR:
			result = CompletionItemKind.Constructor;
			break;
		case ContentAssistEntry.KIND_ENUM:
			result = CompletionItemKind.Enum;
			break;
		case ContentAssistEntry.KIND_FIELD:
			result = CompletionItemKind.Field;
			break;
		case ContentAssistEntry.KIND_FILE:
			result = CompletionItemKind.File;
			break;
		case ContentAssistEntry.KIND_FUNCTION:
			result = CompletionItemKind.Function;
			break;
		case ContentAssistEntry.KIND_INTERFACE:
			result = CompletionItemKind.Interface;
			break;
		case ContentAssistEntry.KIND_KEYWORD:
			result = CompletionItemKind.Keyword;
			break;
		case ContentAssistEntry.KIND_METHOD:
			result = CompletionItemKind.Method;
			break;
		case ContentAssistEntry.KIND_MODULE:
			result = CompletionItemKind.Module;
			break;
		case ContentAssistEntry.KIND_PROPERTY:
			result = CompletionItemKind.Property;
			break;
		case ContentAssistEntry.KIND_REFERENCE:
			result = CompletionItemKind.Reference;
			break;
		case ContentAssistEntry.KIND_SNIPPET:
			result = CompletionItemKind.Snippet;
			break;
		case ContentAssistEntry.KIND_TEXT:
			result = CompletionItemKind.Text;
			break;
		case ContentAssistEntry.KIND_UNIT:
			result = CompletionItemKind.Unit;
			break;
		case ContentAssistEntry.KIND_VALUE:
			result = CompletionItemKind.Value;
			break;
		case ContentAssistEntry.KIND_VARIABLE:
			result = CompletionItemKind.Variable;
			break;
		default:
			result = CompletionItemKind.Value;
			break;
		}
	} else {
		result = CompletionItemKind.Value;
	}
	return result;
}
 
Example 3
Source File: CompletionProposalRequestor.java    From java-debug with Eclipse Public License 1.0 4 votes vote down vote up
private CompletionItemKind mapKind(final int kind) {
    // When a new CompletionItemKind is added, don't forget to update
    // SUPPORTED_KINDS
    switch (kind) {
        case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
        case CompletionProposal.CONSTRUCTOR_INVOCATION:
            return CompletionItemKind.Constructor;
        case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
        case CompletionProposal.TYPE_REF:
            return CompletionItemKind.Class;
        case CompletionProposal.FIELD_IMPORT:
        case CompletionProposal.METHOD_IMPORT:
        case CompletionProposal.METHOD_NAME_REFERENCE:
        case CompletionProposal.PACKAGE_REF:
        case CompletionProposal.TYPE_IMPORT:
            return CompletionItemKind.Module;
        case CompletionProposal.FIELD_REF:
        case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
            return CompletionItemKind.Field;
        case CompletionProposal.KEYWORD:
            return CompletionItemKind.Keyword;
        case CompletionProposal.LABEL_REF:
            return CompletionItemKind.Reference;
        case CompletionProposal.LOCAL_VARIABLE_REF:
        case CompletionProposal.VARIABLE_DECLARATION:
            return CompletionItemKind.Variable;
        case CompletionProposal.METHOD_DECLARATION:
        case CompletionProposal.METHOD_REF:
        case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
        case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
            return CompletionItemKind.Function;
        // text
        case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
        case CompletionProposal.JAVADOC_BLOCK_TAG:
        case CompletionProposal.JAVADOC_FIELD_REF:
        case CompletionProposal.JAVADOC_INLINE_TAG:
        case CompletionProposal.JAVADOC_METHOD_REF:
        case CompletionProposal.JAVADOC_PARAM_REF:
        case CompletionProposal.JAVADOC_TYPE_REF:
        case CompletionProposal.JAVADOC_VALUE_REF:
        default:
            return CompletionItemKind.Text;
    }
}
 
Example 4
Source File: CompletionProposalRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private CompletionItemKind mapKind(final CompletionProposal proposal) {
	//When a new CompletionItemKind is added, don't forget to update SUPPORTED_KINDS
	int kind = proposal.getKind();
	int flags = proposal.getFlags();
	switch (kind) {
	case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
	case CompletionProposal.CONSTRUCTOR_INVOCATION:
		return CompletionItemKind.Constructor;
	case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
	case CompletionProposal.TYPE_REF:
		if (Flags.isInterface(flags)) {
			return CompletionItemKind.Interface;
		} else if (Flags.isEnum(flags)) {
			return CompletionItemKind.Enum;
		}
		return CompletionItemKind.Class;
	case CompletionProposal.FIELD_IMPORT:
	case CompletionProposal.METHOD_IMPORT:
	case CompletionProposal.METHOD_NAME_REFERENCE:
	case CompletionProposal.PACKAGE_REF:
	case CompletionProposal.TYPE_IMPORT:
	case CompletionProposal.MODULE_DECLARATION:
	case CompletionProposal.MODULE_REF:
		return CompletionItemKind.Module;
	case CompletionProposal.FIELD_REF:
		if (Flags.isEnum(flags)) {
			return CompletionItemKind.EnumMember;
		}
		if (Flags.isStatic(flags) && Flags.isFinal(flags)) {
			return CompletionItemKind.Constant;
		}
		return CompletionItemKind.Field;
	case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
		return CompletionItemKind.Field;
	case CompletionProposal.KEYWORD:
		return CompletionItemKind.Keyword;
	case CompletionProposal.LABEL_REF:
		return CompletionItemKind.Reference;
	case CompletionProposal.LOCAL_VARIABLE_REF:
	case CompletionProposal.VARIABLE_DECLARATION:
		return CompletionItemKind.Variable;
	case CompletionProposal.METHOD_DECLARATION:
	case CompletionProposal.METHOD_REF:
	case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
	case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
		return CompletionItemKind.Method;
		//text
	case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
	case CompletionProposal.JAVADOC_BLOCK_TAG:
	case CompletionProposal.JAVADOC_FIELD_REF:
	case CompletionProposal.JAVADOC_INLINE_TAG:
	case CompletionProposal.JAVADOC_METHOD_REF:
	case CompletionProposal.JAVADOC_PARAM_REF:
	case CompletionProposal.JAVADOC_TYPE_REF:
	case CompletionProposal.JAVADOC_VALUE_REF:
	default:
		return CompletionItemKind.Text;
	}
}
 
Example 5
Source File: ContentAssistService.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected CompletionItemKind translateKind(ContentAssistEntry entry) {
	if (entry.getKind() != null) {
		switch (entry.getKind()) {
		case ContentAssistEntry.KIND_CLASS:
			return CompletionItemKind.Class;
		case ContentAssistEntry.KIND_COLOR:
			return CompletionItemKind.Color;
		case ContentAssistEntry.KIND_CONSTRUCTOR:
			return CompletionItemKind.Constructor;
		case ContentAssistEntry.KIND_ENUM:
			return CompletionItemKind.Enum;
		case ContentAssistEntry.KIND_FIELD:
			return CompletionItemKind.Field;
		case ContentAssistEntry.KIND_FILE:
			return CompletionItemKind.File;
		case ContentAssistEntry.KIND_FUNCTION:
			return CompletionItemKind.Function;
		case ContentAssistEntry.KIND_INTERFACE:
			return CompletionItemKind.Interface;
		case ContentAssistEntry.KIND_KEYWORD:
			return CompletionItemKind.Keyword;
		case ContentAssistEntry.KIND_METHOD:
			return CompletionItemKind.Method;
		case ContentAssistEntry.KIND_MODULE:
			return CompletionItemKind.Module;
		case ContentAssistEntry.KIND_PROPERTY:
			return CompletionItemKind.Property;
		case ContentAssistEntry.KIND_REFERENCE:
			return CompletionItemKind.Reference;
		case ContentAssistEntry.KIND_SNIPPET:
			return CompletionItemKind.Snippet;
		case ContentAssistEntry.KIND_TEXT:
			return CompletionItemKind.Text;
		case ContentAssistEntry.KIND_UNIT:
			return CompletionItemKind.Unit;
		case ContentAssistEntry.KIND_VALUE:
			return CompletionItemKind.Value;
		case ContentAssistEntry.KIND_VARIABLE:
			return CompletionItemKind.Variable;
		default:
			return CompletionItemKind.Value;
		}
	} else {
		return CompletionItemKind.Value;
	}
}