SaarS
SaarS

Reputation: 71

Intellij plugin - How to create an action that fires on a specific text hover

I want to create a plugin for my company so that an action is fired on hover, and only in a specific case (a specific and partially constant string).

Example:

Say I have an XML/HTML file with some attributes:

<attribute someAction="something" fieldName="unknown"/>
<attribute width="10" fieldName="whoKnows"/>
<attribute fieldName="incognito" **resourceCode="007"**/>

I want that when hovering above the resourceCode="007" part, my action will be triggered. In all other cases, I don't want to do anything. The resourceCode= is constant, and the value itself is a variable that I need to use in my action.

I went over the Q&A here, and in other places, and tried the official documentation, but with no success.

Upvotes: 6

Views: 502

Answers (1)

Eskandar Abedini
Eskandar Abedini

Reputation: 2154

You can implement custom documentationProvider extension:

Custom languages can use the com.intellij.lang.documentationProvider extension point (EP) to show documentation for functions, methods, classes, or other constructs right inside the IDE. Accessing the documentation is done by calling View | Quick Documentation or hovering over a symbol, which will open a popup to show type information, parameters, usage descriptions, or examples. The source of the documentation contents can vary. Often it is extracted from comments (e.g. JavaDoc comments) in the source code, but it's also possible to access external resources like web pages.

Example implementation at PropertiesDocumentationProvider.java and ThemeJsonDocumentationProvider.java that you can customize it for your own needs

Inlay Hints and Code Inspections and Intentions may be useful too.

Upvotes: 3

Related Questions