Title:
How can I invoke plugin functionality from the Description area of a LocalInspectionTool’s problem descriptor?
Body:
I am developing a custom IntelliJ plugin that defines a LocalInspectionTool.
The inspection works correctly, shows results in the editor, and my LocalQuickFix is invoked properly when selected.
However, I want to know whether it is possible to invoke any custom functionality from inside the inspection description area — specifically the text displayed in:
The popup tooltip when hovering a highlighted problem
The “Problem Description” panel inside Inspection Results
The static HTML file shown as the inspection description (from inspectionDescriptions/*.html)
For example, I want to embed a hyperlink or button inside the description, and when the user clicks it, I want to call a Java method from my plugin.
I tried looking at DaemonTooltipActionProvider, but it appears to be an internal API and not accessible from the open IntelliJ Platform SDK.
My question:
Is there any supported way in the IntelliJ Platform SDK to attach a clickable action inside the inspection description, or invoke plugin logic from the description area?
If not, is the recommended solution to rely solely on LocalQuickFix actions for interactive behavior?
Any official clarification or recommended pattern from JetBrains would be very helpful.
Inside the red box I want a button or hyperlink that could listen inside the code do perform the actions based on that buttons.
@jansorg is right, but to make it working, it is little bit more complex. On a positive note, in can be done with a public API.
Subclass a ProblemDescriptorBase and create your own Problem Descriptor.
In that descriptor, override the getTooltipTemplate function and return a HTML body of your tooltip. It is important to provide a wrap the tooltip text into <html><body> elements without any formatting, line-wrapping or pretty printing. You can reuse kotlinx-html or use the com.intellij.openapi.util.text.HtmlBuilder.
override fun getTooltipTemplate() = createHTML(prettyPrint = false).html {
body {
+"Only lower-case letters are allowed. "
a("#LowerCase/show-more-info") {
+"Show more info"
}
}
}
The hyperlink href, by convention, is a hash-starting prefix delimited by slash from the popup-specific parameters. This prefix should be genenrally mapped to the short name of the inspection.
Declare the LinkHandler extension. The prefix should match the one used in the Problem Descriptor.
class TooltipLinkHandler : TooltipLinkHandler() {
private val inspectionDescriptionLinkHandler = InspectionDescriptionLinkHandler()
override fun handleLink(refSuffix: String, editor: Editor): Boolean {
return if (refSuffix == "show-more-info") {
BrowserUtil.browse("https://www.jetbrains.com/help/rider/Toggling_Case.html")
true
} else {
false
}
}
override fun getDescription(
refSuffix: String,
editor: Editor
) = inspectionDescriptionLinkHandler.getDescription(INSPECTION_SHORT_NAME, editor)
}
Whenever this link handler is invoked on the tooltip, the refSuffix contains the part after the slash. The handleLink function should return true if the link was handled, false otherwise.
When the handleLink returns false, the link is considered to be not handled by the link handler and the getDescription method is invoked in turn-. Such a case occurs when there is a More link in the tooltip or when the user desires to show the inspection description via Cmd/Ctrl+F1 shortcut. To support the UI/UX conventions, we delegate to the default link handler (InspectionDescriptionLinkHandler in the IntelliJ Platform) that will properly load the inspection description from the HTML and display it in the popup. This default link handler requires the inspection short name as a parameter – otherwise the inspection description won’t be show at all.
Finally, when reporting inspection problems, use the ProblemDescriptor subclass instance as a parameter to the registerProblem function.