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:
GroovyInlayParameterHintsProvider
implements inline hints for Groovy methods.KotlinInlayParameterHintsProvider
implements parameter hints for Kotlin language.
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:
Groovy provides several implementations of this EP that can serve as a reference:
GroovyParameterTypeHintsInlayProvider
,GroovyLocalVariableTypeHintsInlayProvider
, andGroovyImplicitNullArgumentHintProvider
.Markdown uses this EP for decorating tables in
MarkdownTableInlayProvider
.For a more complex example, see
KotlinLambdasHintsProvider
, its parent class and all implementations.
Further Tips
Go to Settings | Editor | Inlay Hints and check out inlays that have already been implemented. It gives insight into what’s possible.
If you want to support multiple languages with a single type of inlay hints, please see
InlayHintsProviderFactory
If you want to suppress inlay hints in specific places, please implement
ParameterNameHintsSuppressor
and register it ascom.intellij.codeInsight.parameterNameHintsSuppressor
EP.For testing inlay hints, see
InlayHintsProviderTestCase
andInlayParameterHintsTest
.If you need to force inlay hints to update when using
DaemonCodeAnalyzer#restart()
, please useParameterHintsPassFactory#forceHintsUpdateOnNextPass()
before you callrestart()
. If you want to force an update on a specific editor, note that the method also has an overload that takes an editor instance.