How to add description to Annotator?


if implementing a LocalInspectionTool I can use getStaticDescription. This way I can press (Ctrl+F1) and see a more extended explanation of the hint in the editor.

public class MyLocalInspectionTool extends LocalInspectionTool {
     // ...
     public String getStaticDescription() {
          return "my desc";
     // ...

The result in editor looks like this:
Bildschirmfoto 2014-08-28 um 17.49.26.png

If implementing ExternalAnnotator I specifiy a tooltip like this:

Annotation annotation = holder.createWarningAnnotation(textRange, message);

The result in editor then looks like this:
Bildschirmfoto 2014-08-28 um 17.56.25.png
But I would like to provide a description as well and use Ctrl+F1 to open it (Note: the descripton can be very long 20+ lines with code examples, putting it into the message is not an option)

Is there a way to add the "Description Functionality" to an Annotation without using the LocalInspectionTool ?

Thank you.

Comment actions Permalink

No, annotator is not designed for additional long descriptions.

Comment actions Permalink

This was a fast answer, Thank you!

IntelliJ calls this method if hover mouse over an annotation:


But it fails to call the dressDescription(editor):

final boolean expanded = myCurrentWidth > 0 && dressDescription(editor);

because myCurrentWidth is -1 (always)

dressDescription seems to contain the logic for showing the description.

Really no way to provide something like my own implementation of TooltipLinkHandlerEP ?

Comment actions Permalink

You seem to dig deep in the code :)
Well, the functionality you request was not designed. If you find some hacky way to get it - you are lucky.

Comment actions Permalink

looking deep into intellij code and stress google is most normal in the live of a intellij plugin developer, isn't that so? ;)

After googling and looking at LocalInspectionsPass I came up with following code fragment:

    String myShortcutText;
    final KeymapManager keymapManager = KeymapManager.getInstance();
    if (keymapManager != null) {
      final Keymap keymap = keymapManager.getActiveKeymap();
      myShortcutText = keymap == null ? "" : "(" + KeymapUtil.getShortcutsText(keymap.getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)) + ")";
    else {
      myShortcutText = "";
    @NonNls final String link = " <a "
        + (UIUtil.isUnderDarcula() ? " color=\"7AB4C9\" " : "")
        +">" + DaemonBundle.message("inspection.extended.description")
        +"</a> " + myShortcutText;
    String tooltip = XmlStringUtil.wrapInHtml(XmlStringUtil.escapeString(message) + link);


additionaly I had to register the linkHandler in the extensions section of plugin.xml:

<codeInsight.linkHandler prefix="#sonarissue/" handlerClass=""/>

which at the moment has no logic:

public class MyDescriptionLinkHandler extends TooltipLinkHandler {

  public String getDescription(@NotNull String refSuffix, @NotNull Editor editor) {
    return "my desc "+refSuffix;

It seems to work, but I found a minor issue :
If I use the shortcut (Ctrl+F1), then the annotation disappears instead of get expanded, but only first time.
If I get managed to click on the "more..." or use the shortcut on any other inspection at least once, then it starts working on my annotation as well.

Any ideas what I am missing to get the shortcut working also at first time?

Comment actions Permalink

small update:
at first time IntelliJ executes:


but following condition fails:

private static void changeState() {
    if (Comparing.strEqual(ActionManagerEx.getInstanceEx().getPrevPreformedActionId(), IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)) {
      shouldShowDescription = descriptionShown;
    } else {
      shouldShowDescription = false;
      descriptionShown = true;

// ActionManagerEx.getInstanceEx().getPrevPreformedActionId() is always null

If execute the same shortcut action on some other code inspaction (in my case it was "package name mismatch")
then intellij execute a different class LineTooltipRenderer


actionRef.set(new AnAction() {
      // an action to expand description when tooltip was shown after mouse move; need to unregister from editor component
          new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)),

      public void actionPerformed(final AnActionEvent e) {
        expand(hint, editor, p, pane, alignToRight, group, hintHint); // this do the expand magic correctly

If again execute the same shortcut on my own annotation, then the last one is used and ShowErrorDescriptionAction is not invoked any more.
Very strange.

UPDATE: works fine, I just failed to click into the editor and get the focus.


Please sign in to leave a comment.