Poor documentation for custom language autocompletion.

I need to develop plugin for custom language support within our team. I built BNF and Lexer part pretty quickly. However, I stuck on autocompletion.

Jetbrains' tutorial[1] is very poor regarding this feature.
I also found golang plugin implementation and started exploring keyword autocompletion[2].

In golang GoKeywordCompletionProvider[2] I see wide usage of com.intellij.patterns.ElementPattern or com.intellij.patterns.PsiElementPattern.

It seems like those classes provide main functionality for autocompletion. But they are not documented mostly at all. CompletionProvider class contains some generic FAQ for autocompletion development. However, I would'n say that it is enough. Could you probably link to any other resources with more detailed documentation if there is such?

Because it seems like a whole code patterns recognition for autocompletion does not work.

Thank you!

 

[1] - http://www.jetbrains.org/intellij/sdk/docs/tutorials/custom_language_support_tutorial.html
[2] - https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/src/com/goide/completion/GoKeywordCompletionContributor.java

2
3 comments
Official comment

Have you seen https://github.com/JetBrains/intellij-community/blob/master/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java#L42 ? It's the most complete documentation on completion that there is.

ElementPattern is just one way of implementing PSI location checks necessary for completion, they're not necessary. You can override "fillCompletionVariants" in your contributor and write your completion there without any patterns.

Avatar
Permanently deleted user

@Peter,

Thank you for fast reply. Yes, I saw it. Hoped there is something else beside CContributor's FAQ. It gave me some insights and seems like I am going to continue work with it.

The tutorial[1] which you have, shows autocompletion for property's value. Unfortunately it doesn't cover the case when you started to write expected token and autocompletion frame appears(however, provided example may handle such case). In that case Lexer returns not id of expected token but some other value(in my case generic IDENTIFIER instead of expected to be in that place PROJECT_HEAD). Also, in my case IDENTIFIER's parent will be PsiErrorElement instance. Covering such case might be very helpful because I can not find how to handle it.

-Petr

[1] - http://www.jetbrains.org/intellij/sdk/docs/tutorials/custom_language_support_tutorial.html

0

Writing completion code in general is pretty straightforward.
1. when you have a use case, with specific code sample
2. then you should check which PSI structure corresponds to that situation
3. and write a condition that describes such PSI structure
4. and the lookup elements the completion should produce.

Usually the condition involves just the completion position PSI element (which is normally an identifier), and several its parents and maybe neighbours.

0

Please sign in to leave a comment.