IntelliJ Platform Plugin SDK Help

Inlay Hints

Inlay Hints render small pieces of information directly into the editor and give developers additional code insight without disturbing the workflow. A well-known example is parameter hints that usually display the name of the function parameters as given in its declaration. They are closely related to Parameter Info which shows parameter types for all possible overloads of a function but opens as a popup overlaying the code.

Inlay hints are flexible and have a wide range of applications in the IntelliJ Platform. For instance, the following are well-known examples where inlay hints are used:

  • Java uses inlays to display type annotations in Java chained calls.

  • In version-controlled projects, the author of the code is shown using inlay hints.

  • Kotlin uses inlays in range expressions to show, e.g. less-than, or less-than-or-equal signs to let developers know if intervals are inclusive or exclusive.

The IntelliJ Platform offers two extension points (EP) that plugin developers can implement to create inlay hints:

  • The com.intellij.codeInsight.parameterNameHints EP is used to provide simple text inlays for, e.g., parameter names in method and function calls.

  • The com.intellij.codeInsight.inlayProvider EP is used for more general cases where plugin developers need extended control or want to implement interactive features for inlay hints.

The main difference between both EPs is that the first one only lets you place string inlays while the second one allows for the placement of inline and block inlays with customizable representation.

Implementation

Simple Text Inlay Hints

Implement InlayParameterHintsProvider and register it as com.intellij.codeInsight.parameterNameHints EP. The API documentation of InlayParameterHintsProvider explains in detail the rationale behind all methods.

Examples can be found in the following IntelliJ Platform plugins:

Advanced Inlay Hints

Implement InlayHintsProvider and register it as com.intellij.codeInsight.inlayProvider EP. The API documentation of InlayHintsProvider explains in detail the rationale behind all methods.

Examples can be found in the following IntelliJ Platform plugins:

Further Tips

  1. Go to Settings | Editor | Inlay Hints and check out inlays that have already been implemented. It gives insight into what’s possible.

  2. If you want to support multiple languages with a single type of inlay hints, please see InlayHintsProviderFactory

  3. If you want to suppress inlay hints in specific places, please implement ParameterNameHintsSuppressor and register it as com.intellij.codeInsight.parameterNameHintsSuppressor EP.

  4. For testing inlay hints, see InlayHintsProviderTestCase and InlayParameterHintsTest.

  5. If you need to force inlay hints to update when using DaemonCodeAnalyzer#restart(), please use ParameterHintsPassFactory#forceHintsUpdateOnNextPass() before you call restart(). If you want to force an update on a specific editor, note that the method also has an overload that takes an editor instance.

Last modified: 29 九月 2022