How to trigger highlighter in selected parts of a document

Hi everyone,

When the text of a file changes, the highlighter is going to parse only the part of the text that changed, but lets suppose that I'm implementing a language with preprocesing directives like C/C++, and that I have a text like this:

#define Z


var var1: Integer
var var2: Integer


let var1 := 10

let var2 := 42



#if_defined Z


let var1 := var1 + 256


#else


let var2 := var2 + 256


#end_if

then the line "let var2 := var2 + 256" should be highlighted with, say, "ignored" color.

But, if I change the first line to "#define NOT_Z" the highlighter will only parse the first line and will leave the rest untouched. How can I have the highlighter to redraw also the portions of the file between #if_defined Z and #end_if ?

I guess is something the dispatch thread should do (with ApplicationManager.getApplication().invokeLater()) but I'm just missing the object with a method like "object.triggerDocumentChanged(doc, (int)start, (int)end)" Is there such a method?

Thanks.

0

Probably You need to use this:

com.intellij.codeInsight.daemon.DaemonCodeAnalyzer.restart(psiFile)

or referer its implementation.

0
Avatar
Permanently deleted user

Thanks for your anser Marcin, but I tried that and still no luck... I'll post a possible solution if I ever find one.

0

You use TextEditorHighlightingPass for that? If You want to remove highlighting for some text range that is already highlighted, You need to apply text attribute for that range - com.intellij.openapi.editor.markup.TextAttributes#ERASE_MARKER

0
Avatar
Permanently deleted user

You were right Marcin, I rephrased my question in https://devnet.jetbrains.com/thread/458863 . I was trying to use highlighting at lexer level, this solution should be used at annotator level.

0

请先登录再写评论。