IntelliJ Plugin Development - How to set background color for code block?

247 Views Asked by At

I am making an IntelliJ plugin that detects certain code convention violations. What I would like to do is color code the background of a block of code where a violation has been detected (see example below). I have found plenty of documentation for change foreground text (Annotators, Customer language support etc...), but no documentation on how to change the background of a block of code.

What I need is quite simple, given a start and end char position, I simply need to color-code the background of that chunk in a given color (and be able to remove the color coding later)

Example:

enter image description here

If anyone could point me to the appropriate documentation, or code examples of how to do this, it would be much appreciated. Thanks in advance.

1

There are 1 best solutions below

0
yole On

An annotator allows you to change any attributes of a code block, including background color.

Also, if you're writing a tool that detects code convention violations, such tools are normally written as inspections. If you write an inspection, IntelliJ IDEA automatically highlights the code where you report a problem as a warning, by changing its background color.