When you annotate an annotation class in Kotlin with @DslMarker, an icon appears in the gutter indicating the DSL style
When I try to change the style to a different color it doesn't do anything. How does Kotlin choose the DSL style, and how do I enforce a particular style?
There are only four predefined DSL styles for which you can customize the display options.
For each @DslMarker
annotation, the IDE chooses one of the predefined styles using a hash function of the annotation's fully qualified name. This style is then used for highlighting the usages of functions marked with the annotation. The purpose of the different styles is that different DSLs (marked by different @DslMarker
annotations) are less likely to visually clash.
Moving an annotation's declaration in the source file relative to the other annotations won't affect its chosen style, but renaming it may lead to a different style being chosen for the annotation.
This style is selected in the settings dialog when you click the gutter icon of a @DslMarker annotation class
.
Here's an example of how it works.
You can see that the Style3
is chosen for two annotation classes at once. There's currently no way to force the IDE to choose a particular style for an annotation class.
UPD: the implementation sources in the Kotlin IDE plugin code can be found here and here.