Multi-line Tagger

SyntaxEditor for WPF Forum

Posted 6 years ago by Scott Currie
Version: 13.1.0582
Avatar

I have a syntax language that uses the XML add-on as the primary language, and then uses control sequences to enable embedding of blocks of the DotNetSyntaxLanguage.  Think of it as being similar to ASP.NET, but with XML instead of HTML.

I want to provide a grey background for all of the .NET code blocks, similar to what Visual Studio does.  Unfortunately, I can't seem to override the background color for the DotNetSyntaxLanguage lexer.  So I implemented a classification tagger (via CodeDocumentTaggerProvider) to detect the start/end control sequence delimiters for the .NET code blocks, and then apply a highlight style to every token in between.  This works great for single-line code blocks.  However, multi-line code blocks aren't highlighted, because the GetTags override of  TaggerBase<ClassificationTag> is only ever being called with single line snapshotRanges.

What is the best way to move forward?  I see three options:

1) Can you tell me how to override the background color of all .NET lanage tokens without using a tagger?

2) Can you tell me how to get the GetTags method to supply multi-line ranges?

3) Should I instead look for a start/end delimiter on any range, and then look forward/backward outside of the supplied snapshotRange to construct a TagSnapshotRange that might be larger than the supplied snapshotRange?

 

Or is there another, better way to do it?

Thanks,

-Scott

Comments (1)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Scott,

We have a TODO item to make it easier to supply background highlighting for nested languages.  I'll add this request with that.

In regards to your options:

1) There isn't really a good way to do that because while you could override the style used for things like "Keyword", some other things like operators, etc. wouldn't get the background.

2) As each view line renders, it calls GetTags to see which additional classification tags apply to the line.  So it will only ever really be called line by line, although in the case where there is a collapsed outlining node, the view line might contain more than one document line.  You can return the appropriate classification tag for the nested language range in how it intersects the requested range.  I believe our TextRange class might have a method to do that sort of thing.

3) Offhand, I think you can return a snapshot range larger than the requested one, and it will just trim it.  But if that introduces any problems, then just return the intersection of those ranges instead.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.