How to get the results of a specific (default) annotation/inspection process inside a (custom) toolWindow
Hi,
I have seen a question that deals with my problem, but only in part.
I would like to populate a toolWindow of my own with the results of some specific annotation process done by the IDE. This process is not included/handled by my own plugin.
Is there API to provide the results of an inspection on the current editor/file?
I have posted a similar question on SO (not answered at the time I post here). I think I should have posted that one here.
Thank you in advance for any help,
Andrei
Please sign in to leave a comment.
Hi Andrei,
there is com.intellij.openapi.editor.markup.MarkupModel which provides you with all highlighters provided on the document (which is open in the editor). You may want to distinguish different types of highlighters, e.g.
```
```
and see if severity is error or warning then add a toolwindow entry.
In order to follow the changes you may use the following listner: com.intellij.openapi.editor.ex.MarkupModelEx#addMarkupModelListener
Anna
Hi Anna,
Thank you for the relpy.
I am looking into what you suggested.
But, I think I was not using the correct terms (sorry), I would also be interested to know what provides the info/markers, generated by annotators/inspectors, as indicated by the screenshot below. And also the inspect the problems themselves (like the HighlightInfo):
I am trying to see if the MarkupModel of the current editor makes that info (i.e. the problems highlighted in the scrollbar section) available.
Thank you again!
Andrei
com.intellij.codeInsight.daemon.impl.HighlightInfo#registerFix allows to specify key corresponding to the inspection which register the fix. Without the fix (as far as I know), there is no direct information about the source of the "problem".
Hi Anna,
Thank you again for the help. I tried some more specific scenarios after reading your replies in order to get the annotation results (as they come in the validation/marker bar).
After your reply and a reply on SO, from someone from WebStorm, this is what i have tried:
At this point, my use case is really not triggering an inspection, but getting the "on-the-fly" results of the annotation process of an ExternalAnnotator. I am sorry for maybe mixing up terms, but I am still learning.
The fifth approach was to really use the ExternalAnnotator, and was more promising in the end.
But, the externalAnnotator does not have API to provide the annotation results (no getResults...). I am using a com.intellij.lang.javascript.linter.JSLinterExternalAnnotator. (The "apply" method gets the annotation results as a parameter, but there is no "get", to show the results, outside of the annotator).
At this point, my most specific problem is, having an instance of the annotator (via the code above), to get the annotation results. I know the results are added asynchronously (and a lost of API is in the closed part of Intellij :D), but it would be useful to add a listener to the annotation process.
Would there be any way to get this?
Andrei, you wrote that you want to collect highlights from already running tools, isn't it contradict with the last comment? Please describe what you want to achieve from the end-user view, do you want to present some problems from jslint in separate view?
Anna
P.S. JSLinterExternalAnnotator is not public api, I am not sure if there some api is planned.
Hi Anna,
Sorry, maybe I did not explain correctly. It's like I wrote in my initial question, I would like to collect (live) annotation process results. And I do this for the purpose you wrote above: I would like to present some problems (live/on-the-fly) in a separate (tool) window.
Thank you,
Andrei
P.S. I understand it's not public api, so I also tried to create a separate extension (my own external annotator, specified in the plugin.xml), to subclass the JSLinterExternalAnnotator (so that I can get the annotation results). But somehow my external annotator does not get called. Not sure what else I would need besides an extension in the plugin.xml and a Java class.
As far as I can see there, you need to implement and register com.intellij.lang.javascript.linter.JSLinterInspection to have the results in the editor.
But actually I don't see why my suggestion didn't work. Do you mean that you can't align highlightInfo to the inspection or what was the problem? What are "annotation results" then?
Hi Anna,
Longer reply follows :-). The problem I was initially facing was that I needed to get a list of problems, as returned by a JsLint/JsHint/ESLint tool, and place these results for the user in a new view. These results are already displayed in the validation/marker bar, to the left of the current editor.
I understand these tools (JsLint etc.) perform inspection and/or annotation processes. Probably I do not understand the difference between the inspector vs annotator. I saw that the annotation process was done "live" (on-the-fly), for ESLint for instance, by an ExternalAnnotator tool instance. I am not sure how the inspection processes work (if it can be done on-the-fly also, or can only be triggered manually by the user).
Trying the external annotation approach (and code debug): after the externalAnnotator does an ExternalToolPass, I see that the ExternalAnnotator.apply gets a JSLinterAnnotationResult, which has a list of problems (getErrors() call). I was not aware of another way/API to get the list of problems, discovered by an (external) tool.
I was able to create an externalAnnotator extension along with an implementation class of my own which subclasses a JSLint**ExternalAnnotator. And I was able to get the results and provide them to a custom tool window. The big downside is that my subclasses does a second (duplicate) running of the external annotator, which lead (at least) to some performance impact.
I tried the RangeHighlighter - the first thing I tried :-) - and I get a list of rangeHighlighters. But it does not provide the info I needed, like problem description, severity, line number (I got no HighlighInfo, because the higlighter.getErrorStripTooltip and other info on the highlighter is null). I tried it again, to see if, having a list of known "lines with problems", I could get a correspondence between the higlighters and my problems. But did not find any API to (quickly) get the line number.
I will still dig deeper, but for now, the custom external annotator seems to, at least, provide the list of problems. I don't think this is the best solution, but the only way I got hold of annotation results.
If you think of another way, I am very open to suggestions.
Thank you again for your help,
Andrei
I never took a precise look at lint tools so I can't provide feedback here.
Ok, no problem. As mentioned, I will take a look further at the editor markup (or other related suggestions), as my current solution is not the best.
Thank you for your help!
Andrei.