semantic highlighting

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Kelly Leahy - Software Architect, Milliman
Version: 4.0.0245
Avatar
Is there a safe way to do semantic highlighting in the editor? In other words, if I have three types of identifiers that can appear in my language and I want to highlight each of the three types differently, but I only the "type" of an identifier in the semantic analysis phase, is there a safe way for me to change the highlight of the identifier without worrying about threading issues?

Another idea, is "OnSemanticParseDataChanged" executed in the context of the thread that changed the parse data, or on the UI thread? If it's on the UI thread, then if I used a fast data structure that was thread-protected from the parser thread, I could do the highlighting there, couldn't I?

I know there are a couple of threads on the forum about this, but I didn't have much luck finding specifics that would help me on those - sorry if I'm repeating the question...

Kelly Leahy Software Architect Milliman, USA

Comments (7)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I looked at the code and the code that raises the SyntaxEditor.DocumentSemanticParseDataChanged event invokes it if required. So handlers of that event should be on the main UI thread.


Actipro Software Support

Posted 13 years ago by Kelly Leahy - Software Architect, Milliman
Avatar
Ok... that's a good start.

Now, is there any way for me to tell the control to update the highlighting on specific tokens one at a time, or must I tell the control to somehow refresh all highlighting by calling GetHighlightingStyle on the language for each token?

What I'm thinking is that I'll use the "OnSemanticParseDataChanged" event to determine which IToken(s) need to be updated due to changes in semantic meaning of those tokens. Once I've determined which need to be updated, I planned on setting the "HighlightingStyle" property on my IToken implementation to the appropriate style, and then somehow telling the control that this token needs updating.

The question is - how is best to "tell" the control that the token needs it's highlighting updated?

Kelly Leahy Software Architect Milliman, USA

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
If you are only updating colors, you can call Document.InvalidatePaint.


Actipro Software Support

Posted 13 years ago by Kelly Leahy - Software Architect, Milliman
Avatar
I would be setting a field on the IToken that would be returned by the HighlightingStyle accessor (property get). Would InvalidatePaint cause the control to go through all tokens and call GetHighlightingStyle on the language for them?

Kelly Leahy Software Architect Milliman, USA

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
InvalidatePaint just tells any attached SyntaxEditor to redraw. So you don't want to call it each time you update a token, just when your updates are complete.


Actipro Software Support

Posted 13 years ago by Kelly Leahy - Software Architect, Milliman
Avatar
Ok... I understood that. I just wanted to make sure that it would actually call GetHighlightingStyle again, rather than just reusing the result from the previous call.

Thanks.

Kelly Leahy Software Architect Milliman, USA

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes I believe it's calling it to get the colors on each rendering pass.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 10 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.