How to add items from a CompletionProvider asynchronously?

Answered

We are implementing a custom completion provider which needs to run for multiple seconds before it can provide its elements to the result set. I already read on the forum about the issue of long-running `CompletionProvider#addCompletions` implementations:
- https://intellij-support.jetbrains.com/hc/en-us/community/posts/206106529-How-to-create-an-auto-complete-text-field-which-adds-items-async-
- https://intellij-support.jetbrains.com/hc/en-us/community/posts/206757935-Async-autocompletion-CompletionContribitor-

From those posts I take it that long-running completion providers are required to invoke `ProgressManager.checkCanceled()` periodically and running the actual computation in a separate thread. This seems to have the desired effect of not freezing the UI while the results are calculated, but it prevents completion suggestions from other completion provides to be shown to the user in the meantime before our own completion provider finishes.

Is there a way to properly populate the list of completion suggestions asynchronously, i.e. let the results of other providers be displayed to the user immediately, and ours will be added at the top of the completion suggestions once our completion provider is done?

1 comment
Comment actions Permalink

Please try registering your CompletionProvider in plugin.xml using "order="last""

0

Please sign in to leave a comment.