Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ plugin autocompletion

I'm making an IntelliJ plugin to support a nodeJS framework. I'm trying to implement autocompletion feature but don't know how to set autocompletion position on top of the list. First I have other autocompletion (mozilla ect..).

Here is my code :

LookupElementBuilder
                .create(completionString)
                .withBoldness(true)
                .withCaseSensitivity(false)
                .withIcon(SailsJSIcons.SailsJS)
                .withPresentableText("\t\t\t" + item)
                .withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE);

I suppose handleInsert can help me but can't find how use it

like image 292
jaumard Avatar asked Nov 09 '22 15:11

jaumard


1 Answers

You can set order="first" on your completion.contributor in the plugin.xml. Looks like it will make your contributor be called before contributors from other sources, resulting in your suggestions being first:

<extensions defaultExtensionNs="com.intellij">
    <completion.contributor order="first" language="PHP" implementationClass="org.klesun.deep_assoc_completion.entry.DeepKeysCbtr"/>

When your contributor is called first, you can also write the code to decide how to position following suggestions or to exclude some of them altogether using CompletionResultSet::runRemainingContributes() and the PrioritizedLookupElement::withPriority() suggested by @peter-gromov:

protected void addCompletions(CompletionParameters parameters, ProcessingContext processingContext, CompletionResultSet result) 
{
    // ... some of your code here ...

    result.runRemainingContributors(parameters, otherSourceResult -> {
        // 2000 is any number - make it smaller than on your suggestion to position this suggestion lower
        result.addElement(PrioritizedLookupElement.withPriority(otherSourceResult.getLookupElement(), 2000));
    });
}
like image 147
Klesun Avatar answered Nov 23 '22 07:11

Klesun