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

The following examples show how to use org.eclipse.lsp4j.CompletionItem#setKind() . 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: FilePathCompletionParticipant.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
private void createFilePathCompletionItem(File f, Range replaceRange, ICompletionResponse response, String slash) {
	CompletionItem item = new CompletionItem();
	String fName = f.getName();
	if(isWindows && fName.isEmpty()) { // Edge case for Windows drive letter
		fName = f.getPath();
		fName = fName.substring(0, fName.length() - 1);
	}
	String insertText;
	insertText = slash + fName;
	item.setLabel(insertText);

	CompletionItemKind kind = f.isDirectory()? CompletionItemKind.Folder : CompletionItemKind.File;
	item.setKind(kind);
	
	item.setSortText(CompletionSortTextHelper.getSortText(kind));
	item.setFilterText(insertText);
	item.setTextEdit(new TextEdit(replaceRange, insertText));
	response.addCompletionItem(item);
}
 
Example 2
Source File: TableBodyCompletionProvider.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public CompletionItem getQueryExpressionSnippet(int data) {
    CompletionItem ci = new CompletionItem();
    ci.setLabel("AS SELECT * FROM ...");
    ci.setInsertText(" AS SELECT * FROM ${4:table_name};");
    ci.setKind(CompletionItemKind.Snippet);
    ci.setInsertTextFormat(InsertTextFormat.Snippet);
    ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText()));
    ci.setData(data);
    ci.setPreselect(true);
    return ci;
}
 
Example 3
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 4
Source File: TableBodyCompletionProvider.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public CompletionItem getColumnCompletionItem(int data) {
    CompletionItem ci = new CompletionItem();
    ci.setLabel("column definition");
    ci.setInsertText("${1:column_name} ${2:datatype}");
    ci.setKind(CompletionItemKind.Snippet);
    ci.setInsertTextFormat(InsertTextFormat.Snippet);
    ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText()));
    ci.setData(data);
    ci.setPreselect(true);
    ci.setSortText("1100");
    return ci;
}
 
Example 5
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public CompletionItem createOverrideMethodItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean implement) {
    CompletionItem item = new CompletionItem(elem.getSimpleName().toString() + " - override");
    item.setKind(elementKind2CompletionItemKind(elem.getKind()));
    setCompletionData(item, elem);
    return item;
}
 
Example 6
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 7
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public CompletionItem createExecutableItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean inImport, boolean addSemicolon, boolean smartType, int assignToVarOffset, boolean memberRef) {
    Iterator<? extends VariableElement> it = elem.getParameters().iterator();
    Iterator<? extends TypeMirror> tIt = type.getParameterTypes().iterator();
    StringBuilder label = new StringBuilder();
    String sep = "";
    label.append(elem.getSimpleName().toString());
    label.append("(");
    while(it.hasNext() && tIt.hasNext()) {
        TypeMirror tm = tIt.next();
        if (tm == null) {
            break;
        }
        label.append(sep);
        label.append(Utilities.getTypeName(info, tm, false, elem.isVarArgs() && !tIt.hasNext()).toString());
        label.append(' ');
        label.append(it.next().getSimpleName().toString());
        sep = ", ";
    }
    label.append(") : ");
    TypeMirror retType = type.getReturnType();
    label.append(Utilities.getTypeName(info, retType, false).toString());
    CompletionItem item = new CompletionItem(label.toString());
    item.setKind(elementKind2CompletionItemKind(elem.getKind()));
    item.setInsertText(elem.getSimpleName().toString());
    setCompletionData(item, elem);
    return item;
}
 
Example 8
Source File: DdlCompletionItemLoader.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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 9
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public CompletionItem createTypeItem(CompilationInfo info, TypeElement elem, DeclaredType type, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean insideNew, boolean addTypeVars, boolean addSimpleName, boolean smartType, boolean autoImportEnclosingType) {
    CompletionItem item = new CompletionItem(elem.getSimpleName().toString());
    item.setKind(elementKind2CompletionItemKind(elem.getKind()));
    setCompletionData(item, elem);
    return item;
}
 
Example 10
Source File: PatchedContentAssistService.java    From n4js 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 result = super.toCompletionItem(entry, caretOffset, caretPosition, 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 11
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 12
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 13
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 14
Source File: DdlCompletionItemLoader.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public CompletionItem getCreateViewUnionCompletionItem(int data, String sortValue) {
    CompletionItem ci = new CompletionItem();
    ci.setLabel("CREATE VIEW with UNION");
    ci.setInsertText(QueryExpressionHelper.CREATE_VIEW_UNION_INSERT_TEXT);
    ci.setKind(CompletionItemKind.Snippet);
    ci.setInsertTextFormat(InsertTextFormat.Snippet);
    ci.setDetail(" Union of two tables from single source");
    ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText()));
    ci.setData(data);
    ci.setPreselect(true);
    ci.setSortText(sortValue);
    return ci;
}
 
Example 15
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 16
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public CompletionItem createKeywordItem(String kwd, String postfix, int substitutionOffset, boolean smartType) {
    CompletionItem item = new CompletionItem(kwd);
    item.setKind(CompletionItemKind.Keyword);
    return item;
}
 
Example 17
Source File: CompletionProvider.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
private void addRootMXMLLanguageTagsToAutoComplete(IMXMLTagData offsetTag, String prefix, boolean includeOpenTagPrefix, boolean includeOpenTagBracket, CompletionList result)
{
    List<CompletionItem> items = result.getItems();
                        
    CompletionItem item = new CompletionItem();
    item.setKind(CompletionItemKind.Keyword);
    item.setLabel("fx:" + IMXMLLanguageConstants.SCRIPT);
    if (completionSupportsSnippets)
    {
        item.setInsertTextFormat(InsertTextFormat.Snippet);
    }
    item.setFilterText(IMXMLLanguageConstants.SCRIPT);
    item.setSortText(IMXMLLanguageConstants.SCRIPT);
    StringBuilder builder = new StringBuilder();
    if (includeOpenTagBracket)
    {
        builder.append("<");
    }
    if (includeOpenTagPrefix)
    {
        builder.append(prefix);
        builder.append(IMXMLCoreConstants.colon);
    }
    builder.append(IMXMLLanguageConstants.SCRIPT);
    builder.append(">");
    builder.append("\n");
    builder.append("\t");
    builder.append(IMXMLCoreConstants.cDataStart);
    builder.append("\n");
    builder.append("\t\t");
    if (completionSupportsSnippets)
    {
        builder.append("$0");
    }
    builder.append("\n");
    builder.append("\t");
    builder.append(IMXMLCoreConstants.cDataEnd);
    builder.append("\n");
    builder.append("<");
    builder.append(IMXMLCoreConstants.slash);
    builder.append(prefix);
    builder.append(IMXMLCoreConstants.colon);
    builder.append(IMXMLLanguageConstants.SCRIPT);
    builder.append(">");
    item.setInsertText(builder.toString());
    items.add(item);

    addMXMLLanguageTagToAutoComplete(IMXMLLanguageConstants.BINDING, prefix, includeOpenTagBracket, includeOpenTagPrefix, result);
    addMXMLLanguageTagToAutoComplete(IMXMLLanguageConstants.DECLARATIONS, prefix, includeOpenTagBracket, includeOpenTagPrefix, result);
    addMXMLLanguageTagToAutoComplete(IMXMLLanguageConstants.METADATA, prefix, includeOpenTagBracket, includeOpenTagPrefix, result);
    addMXMLLanguageTagToAutoComplete(IMXMLLanguageConstants.STYLE, prefix, includeOpenTagBracket, includeOpenTagPrefix, result);
}
 
Example 18
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public CompletionItem createVariableItem(CompilationInfo info, String varName, int substitutionOffset, boolean newVarName, boolean smartType) {
    CompletionItem item = new CompletionItem(varName);
    item.setKind(CompletionItemKind.Variable);
    return item;
}
 
Example 19
Source File: CompletionProvider.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
private void autoCompleteImport(String importName, ILspProject project, CompletionList result)
{
    List<CompletionItem> items = result.getItems();
    for (ICompilationUnit unit : project.getCompilationUnits())
    {
        if (unit == null)
        {
            continue;
        }
        Collection<IDefinition> definitions = null;
        try
        {
            definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions();
        }
        catch (Exception e)
        {
            //safe to ignore
            continue;
        }
        for (IDefinition definition : definitions)
        {
            String qualifiedName = definition.getQualifiedName();
            if (qualifiedName.equals(definition.getBaseName()))
            {
                //this definition is top-level. no import required.
                continue;
            }
            if (qualifiedName.startsWith(importName))
            {
                int index = importName.lastIndexOf(".");
                if (index != -1)
                {
                    qualifiedName = qualifiedName.substring(index + 1);
                }
                index = qualifiedName.indexOf(".");
                if (index > 0)
                {
                    qualifiedName = qualifiedName.substring(0, index);
                }
                CompletionItem item = new CompletionItem();
                item.setLabel(qualifiedName);
                if (definition.getBaseName().equals(qualifiedName))
                {
                    item.setKind(LanguageServerCompilerUtils.getCompletionItemKindFromDefinition(definition));
                }
                else
                {
                    item.setKind(CompletionItemKind.Text);
                }
                if (!items.contains(item))
                {
                    items.add(item);
                }
            }
        }
    }
}
 
Example 20
Source File: CompletionProvider.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
private void addLanguageAttributesToAutoCompleteMXML(TypeScope typeScope, ASScope otherScope, char nextChar, ILspProject project, CompletionList result)
{
    List<CompletionItem> items = result.getItems();

    CompletionItem includeInItem = new CompletionItem();
    includeInItem.setKind(CompletionItemKind.Keyword);
    includeInItem.setLabel(IMXMLLanguageConstants.ATTRIBUTE_INCLUDE_IN);
    if (completionSupportsSnippets
            && nextChar != '=')
    {
        includeInItem.setInsertTextFormat(InsertTextFormat.Snippet);
        includeInItem.setInsertText(IMXMLLanguageConstants.ATTRIBUTE_INCLUDE_IN + "=\"$0\"");
    }
    items.add(includeInItem);

    CompletionItem excludeFromItem = new CompletionItem();
    excludeFromItem.setKind(CompletionItemKind.Keyword);
    excludeFromItem.setLabel(IMXMLLanguageConstants.ATTRIBUTE_EXCLUDE_FROM);
    if (completionSupportsSnippets
            && nextChar != '=')
    {
        excludeFromItem.setInsertTextFormat(InsertTextFormat.Snippet);
        excludeFromItem.setInsertText(IMXMLLanguageConstants.ATTRIBUTE_EXCLUDE_FROM + "=\"$0\"");
    }
    items.add(excludeFromItem);

    Set<INamespaceDefinition> namespaceSet = ScopeUtils.getNamespaceSetForScopes(typeScope, otherScope, project);

    IDefinition idPropertyDefinition = typeScope.getPropertyByNameForMemberAccess((CompilerProject) project, IMXMLLanguageConstants.ATTRIBUTE_ID, namespaceSet);
    if (idPropertyDefinition == null)
    {
        CompletionItem idItem = new CompletionItem();
        idItem.setKind(CompletionItemKind.Keyword);
        idItem.setLabel(IMXMLLanguageConstants.ATTRIBUTE_ID);
        if (completionSupportsSnippets
                && nextChar != '=')
        {
            idItem.setInsertTextFormat(InsertTextFormat.Snippet);
            idItem.setInsertText(IMXMLLanguageConstants.ATTRIBUTE_ID + "=\"$0\"");
        }
        items.add(idItem);
    }

    if (frameworkSDKIsRoyale)
    {
        IDefinition localIdPropertyDefinition = typeScope.getPropertyByNameForMemberAccess((CompilerProject) project, IMXMLLanguageConstants.ATTRIBUTE_LOCAL_ID, namespaceSet);
        if (localIdPropertyDefinition == null)
        {
            CompletionItem localIdItem = new CompletionItem();
            localIdItem.setKind(CompletionItemKind.Keyword);
            localIdItem.setLabel(IMXMLLanguageConstants.ATTRIBUTE_LOCAL_ID);
            if (completionSupportsSnippets
                    && nextChar != '=')
            {
                localIdItem.setInsertTextFormat(InsertTextFormat.Snippet);
                localIdItem.setInsertText(IMXMLLanguageConstants.ATTRIBUTE_LOCAL_ID + "=\"$0\"");
            }
            items.add(localIdItem);
        }
    }
}