Highlight code between line numbers given a file and also add marker on the gutter. Follow
I am trying to develop a plugin to highlight code given a file and line numbers of that file. I looked around and saw that I have to use Annotators but its still not clear. I also want to add markers on the gutter bar to jump to the line. Is it possible to even underline the file in the Project Explorer window?
Please sign in to leave a comment.
Plain annotator (http://www.jetbrains.org/intellij/sdk/docs/tutorials/custom_language_support/annotator.html) is more suited to on-the-fly (semantic) highlighting according to language structure.
If the highlighting information is obtained from some external process/input, consider using com.intellij.lang.annotation.ExternalAnnotator.
Presentation of nodes in Project/Packages View can be changed using com.intellij.ide.projectView.ProjectViewNodeDecorator, for underlining use com.intellij.ide.projectView.PresentationData#setAttributesKey with TextAttributes effectType set to com.intellij.openapi.editor.markup.EffectType#LINE_UNDERSCORE
Thanks for the response, Since Annotators are language specific, I want to be able to highlight any and all code between two line numbers and irrespective of the language. Is this possible?
If all supported files come with language support (PSI), then you could still use Annotator without specifying language, then use the PsiFile file instance passed into annotate() and install highlighting/gutters on specific TextRanges across the whole file.
Another option is to use com.intellij.codeHighlighting.TextEditorHighlightingPass that will work on any text editor, but it is much more low-level and requires more code.