5

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

2 Answers 2

1

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)); }); } 
Sign up to request clarification or add additional context in comments.

Comments

0

You can try specifying explicit high priority for your lookup elements via PrioritizedLookupElement#withPriority.

2 Comments

I just try but position are the same, they doesn't move at all with PrioritizedLookupElement.withPriority(lookup, LookupValueWithPriority.HIGHER) or HIGH
Then more information is needed. For example, item weights as printed by DumpLookupElementWeights action (ctrl/command+alt+shift+w when lookup list is open)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.