Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin - DSL Color Style

When you annotate an annotation class in Kotlin with @DslMarker, an icon appears in the gutter indicating the DSL style

enter image description here

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?

like image 974
Matthew Layton Avatar asked Oct 19 '25 03:10

Matthew Layton


1 Answers

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.

enter image description here

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.

like image 78
hotkey Avatar answered Oct 21 '25 19:10

hotkey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!