Doing code annotation the other way around

So I'm working on a custom language plugin which fetches all code diagnostics from an external analyser process. The returned diagnostics are simply a list of ranges each with an error/warning/info/... message.

Given that both `LocalInspectionTool` and `Annotator` will visit every PSI element in a file (with a `PsiElementVisitor` in the case of `LocalInspectionTool` and a call to `annotate(...)` on every element in the case of `Annotator`) I am forced to look for a diagnostic for every single element, which is very inefficient especially that generally most elements will not have a diagnostic. I could implement some sort of smart consumer that tries to find diagnostics faster and removes those that were found to speed up subsequent lookups, but I doubt it would be significantly better since it wouldn't change the fact that every element will be visited and checked.

So my question is: does the API currently provide a way to do code annotation "the other way around"? Ideally, I would like to be able to just tell the IDE: "there, put an error from this offset to this offset with this message, a warning from that offset to that offset with that message, etc."

Thanks :)

Comment actions Permalink

ExternalAnnotator sounds like a better choice for you since you can provide the annotation ranges for the file, not by element.

Create your own class extending from ExternalAnnotator 

In my case I use it for syntax highlighting from lexer data:

public class MultiMarkdownExternalAnnotator extends ExternalAnnotator<MultiMarkdownExternalAnnotator.ProjectCharSequence, LexerToken[]> {

and add the line to your plugin.xml, adjusting the parameters for your plugin:

<externalAnnotator language="Markdown" implementationClass="com.vladsch.idea.multimarkdown.annotator.MultiMarkdownExternalAnnotator"/>






Comment actions Permalink

That's exactly what I need, thanks!

@Yann Cebron sorry I read the "Annotator" section just above and somehow I totally missed that one :p


Please sign in to leave a comment.