Custom Language: using PSI elements to get data for intellisense

 
 

We have already developed a plugin which handles our custom language.

Now we would like to get some data from the language in order to use it as code completion for another part of the language. 
Right now we achived this task, getting all the module VirtualFiles and for each one the PSI File. Then for every PSI File we look for the PSIElement we need. 
All this work is done on the beforeCompletion function on our CompletionContributor class.

We wonder if this is the best way or if there is a more efficient way to do it.

Thanks for the hint. 
Marco

0
3 comments
Official comment

beforeCompletion should be fast, so is definitely not the best place to iterate over whole project. Normally completion produces its suggestions inside CompletionContributor#fillCompletionVariants

Hi Peter,

thanks for your reply.

My two main concern are: 1) where to place my code 2) how to do it.

For concern 1) I'll try to move out from beforeCompletion, understood.

For concern 2) I still don't know if iterating VirtualFiles and getting every single PsiFile from them is the right thing to accomplish my task which is extracting some data from PsiFiles to use for other suggestions. Basically with some files we declare some stuff and with other files we use these stuff. I read "Stub Indexes" documentation but I don't understand if I can solve my problem with it or with something else.

Marco

 

0

Iterating over files is most likely going to be slow for larger projects. Some kinds of index (usually stub-based one, yes) is normally used to drastically improve the performance: you index all the declarations and then can easily get the needed ones from index. But it all depends on the specific task you're solving, and it's hard to give advice without knowing that task.

0

Please sign in to leave a comment.