Inlay Hint using WithAttributesPresentation disables OnHoverPresentation

Answered

If I have an InlayPresentation which just displays some text in red, for example:

val errorTextPresentation = WithAttributesPresentation(factory.smallText("Uh oh..."), CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES, editor)

And then want to be able to hover and click on that text, I use this:

factory.referenceOnHover(errorTextPresentation) { event, _ ->
...
}

And I'd expect the red text to turn blue on hover. This works if I use:

val errorTextPresentation = factory.smallText("Uh oh...")

But with that, the small text won't start red. Is it possible to have the hover effect when using AttributesPresentation or is that not supported?

I'm testing on PHPStorm 2022.3 (using the new UI)

Thanks!

0
2 comments

Please do not crosspost the exact same question.

0

Hello!
It is possible to achieve what you want using flags:

  val flags = WithAttributesPresentation.AttributesFlags()
flags.isDefault = true
val errorTextPresentation = WithAttributesPresentation(factory.smallText("Uh oh..."),
TextAttributesKey.createTextAttributesKey("WRONG_REFERENCES_ATTRIBUTES"), editor,
flags)
sink.addInlineElement(0, true, factory.referenceOnHover(errorTextPresentation) { a, b ->
...
})
}
1

Please sign in to leave a comment.