LocalInspectionTool Results in ToolWindow

I have build a LocalInspectionTool that reports problems directly by highlighting parts of the code and offering quick fixes. However, I would like to extend this and offer more sophisticated options and descriptions of the problem in a separate ToolWindow.

Screen Shot 2015-02-20 at 19.15.40.png
All problems that are highlighted in the code should again be listed in the tool window – the right pane will offer more detailed descriptions of the problem and further more advanced options for refactoring. The problem I am facing now is that am unsure as to how to share data about problems between the LocalInspectionTool and the ToolWindow instances. Is there a standard pattern on how to do this in Intellij?

  1. Use a publish-subscribe model to publish problem desciptors from the Inspection Tool and subscribe to these from the ToolWindow? If so, are there already PubSub mechanisms available (I saw there is a project message bus)?
  2. Build a singleton cache that both objects have access to?
  3. Run the LocalInspectionTool manually via a PsiTreeChangeAdapter from ToolWindow itself (using this approach: https://devnet.jetbrains.com/message/5514826#5514826) (EDIT: This has the disadvantage that if the tool window is closed the problems will also no longer be highlighted in the code, which is undesireable)
  4. something else?

Both components (inspection tool and toolwindow) are currently set up via the plugin.xml file.

Thank you very much in advance,

Comment actions Permalink

Having had a further look at some other examples and the documentation it appears to me that Project:getUserData/Project:putUserData() are candidates for the data sharing opportunities that I am looking for.

It works but I wonder if there are any other ways of sharing data built into IntelliJ – could you enlighten me on this topic, please?

Comment actions Permalink

Hi Simon,

if you run your inspection in batch mode (Analyse|Inspect code), toolwindow with inspection results is shown. Does it suites your needs in general apart from that the view won't be updated on user typing? If so, we have plans to provide such mechanism inside IDEA Core.

Instead of sharing anything inside project user data, you may define ProjectComponent and store your data there. Please be sure that data is indeed shareable, e.g. what would be if user would change his profile and disable/enable your inspection, etc


Comment actions Permalink

Thank you, Anna!

In my case I would actually like the tool window to update its contents as the user types, thus basically acting similarly to the annotations in the editor but showing more information, e,g, examples and links to reading material.

ive now adapted my approach to your suggestion to use a ProjectComponent. this seems to work nicely. This project component then updates the tool window's contents by sending an update message via a MessageBus. This seems to be elegant enough for now.

Thanks for making me aware of the issue of the user disabling the annotation. I will have to cover that case.


Please sign in to leave a comment.