Simple way to get completion results programatically for an offset in a source file ?

Hi, I'm trying to go from a (PsiFile, offset) -> [list of completion results]. Essentially, I'm interested in seeing what Idea has to say about possible completion at a certain point in a file, in a "background" / programmatic manner.

I looked at existing open-source plugins, but I couldn't find any way of getting completion results, only

I also tried:

1. JavaCompletionUtil
2. JavaCompletionData

In both cases, the problem seems to be that:

1. It doesn't work.
2. I can't call the lower level APIs because I can't instantiate a CompletionParameters object

Is this possible ? Is there an example on how to do this ? Am I on the right track ?

Any help is appreciated.



The completion API is not designed to be used in this way, so there is no API to do what you need. What exactly do you want to accomplish?


I'm also trying to do something like this. In my case I want to report the possible completions to a speech engine so that a user can effectively code by voice using the words IDEA knows to be valid at any given point. What would be the best way to accomplish this?


I'm also trying to do something like this.  I chased my tail around the completion code for a couple hours today and ended up hitting the same wall as Andrei.  I can't call performCompletion because I can't create the CompletionParameters object, because its constructor isn't public.

My use case is that I'm trying to implement a Language Server Protocol[1] server using Intellij to serve requests, so we can edit in Vim/Emacs/etc and use Intellij's PSI framework to do the heavy lifting of parsing Java/Scala.  I've gotten things like Go To Definition working, but now I'm hitting a wall at tab completion.

What's the correct way to go about doing this?



To anyone who comes across this, I was able to do this following along with this plugin.


That’s great @Kyle. That’s a pretty big repo, could you point at the file(s) in there that helped you out?


Please sign in to leave a comment.