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
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));
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With