Best way to implement code highlighting/annotation by file+line number? Follow
Is there a way to highlight code given line and filename, using the plugin API.
Such that a small snippet of information is displayed in conjunction with that line, ( from an external source.)
I have looked into the available methods, and it seems to be based on parsing rather than arbitrary line numbers.
thanks
Please sign in to leave a comment.
It seems com.intellij.lang.annotation.ExternalAnnotator might be suitable here. You can then register highlighting without PSI using com.intellij.lang.annotation.AnnotationHolder with TextRange parameter, which can be calculated to match certain line(s) in editor.
Thanks for the reply @yannc76, will investigate.
I have the same requirements. Could you provide some more details?
The documentation seems out of date, com.intellij.lang.annotation.ExternalAnnotator is no longer an interface. How can I use the com.intellij.lang.annotation.AnnotationHolder for this? Is there any documentation beside the source code?
My plugin loads information from a server. The information contains the exact position of the text (line number/character), which has to be annotated. How would I do that?
Thanks for noting, we're going to update this part.
Still using ExternalAnnotator seems a solution for your problem here. Unfortunately there are not too many examples in Community Edition sources.
You'll have to map line/col information from server to a TextRange (full line or specific elements at that position) to map the results to the current file.
See DartAnalysisServerAnnotator.java in contrib repository.
I can't find any file called DartAnalysisServerAnnotator.java. Could you provide me with a link?
You can find the Dart plugin sources in /contrib repository
https://github.com/JetBrains/intellij-plugins/tree/master/Dart
When I extend ExternalAnnotator, a PluginException is thrown, which says: "No key specified for extension of class FindingsAnnotator"
Do I have to declare a language like it is done in the plugin.xml for DartAnalysisServerAnnotator? My plugin is independent of the used language.
Currently you'll have to register your annotator for every supported language explicitly. What kind of data do you provide that language/filetype does not matter at all?
The data holds information about the code, which should be displayed at the according line. Several languages are currently supported, but constantly extended on the server-side. Therefore, it would be best, if the plugin was language independent, so it would not have to be maintained for that matter.
Hi! I'm having the same problem that @Benedikt had. I need to annotate a specific line in the document but it must be language agnostic, I just want to highlight it and have a tooltip with some information about the Warning/Error on the UI. How can I do this?
@Bmibferreira I am using a SideBarFactory to create a sidebar with annotations:
Implement the createSideBar method and determine the open file:
Do the painting in MySideBarComponent:
//EDIT:
Don't forget to register the SideBarFactory in your layer.xml:
Hi @Benedikt, thanks for your answer. I searched for SideBarFactory but I didn't found it. Is your example valid for IntelliJ? Because it seems that SideBarFactory is from Netbeans (http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-editor-lib2/org/netbeans/spi/editor/SideBarFactory.html?is-external=true)
@BmiBferreira You are totally right... I completely mixed it up. So if you plan to develop your plugin for Netbeans as well, you already know how to do it ;)
For Intellij IDEA, you can use an ActionGutterRenderer:
First you need to implement a FileEditorManagerListener and register it to the MessageBus, in order to get notified, when the file of the editor is changed:
Second you need to implement your renderer:
Implement the required methods:
Now you need to register both classes as ProjectComponents in your plugin.xml:
Hope this helps.