Child pages
  • Developing Custom Language Plugins for IntelliJ IDEA

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The most common way to implement getVariants() is to use the same function for walking up the tree as in PsiReference.resolve(), and a different implementation of PsiScopeProcessor which collects all declarations passed to its processDeclarations() method and returns them as an array for filling the completion list.

Contributor-based Completion

Implementing the CompletionContributor interface gives you the greatest control over the operation of code completion for your language. Note that the JavaDoc of that class contains a detailed FAQ for implementing code completion.

The core scenario of using CompletionContributor consists of calling the extend() method and passing in the pattern specifying the context in which this completion variant is applicable, as well as a completion provider which generates the items to show in the completion list.

Example: CompletionContributor for completing keywords in MANIFEST.MF files

Items shown in the completion list are represented by instances of the LookupElement interface. These instances are normally created through the LookupElementBuilder class. For every lookup element, you can specify the following attributes:

  • Text, tail text and type text. Tail text is shown next to the main item text, is not used for prefix matching, and can be used, for example, to show the parameter list of the method. Type text is shown right-aligned in the lookup list and can be used to show the return type or containing class of a method, for example.
  • Icon
  • Text attributes (bold, strikeout etc.)
  • Insert handler. The insert handler is a callback which is called when the item is selected, and can be used to perform additional modifications of the text (for example, to put in the parentheses for a method call)

Find Usages

The Find Usages action in IDEA is a multi-step process, and each step of the process requires involvement from the custom language plugin. The language plugin participates in the Find Usages process by registering an implementation of FindUsagesProvider in the com.intellij.lang.findUsagesProvider extension point, and through the PSI implementation (PsiNamedElement and PsiReference interfaces).

...