ParserBase gets the range of text changes

SyntaxEditor for WPF Forum

Posted 2 years ago by SPF - Appeon
Version: 22.1.2
Avatar

We implemented "ParserBase". And the "Parse (IParseRequest request)" method of paserbase.

In this method, I need to know the change content of the text changed each time (from which line to change, the changed content, etc.), and how to do it?

Comments (1)

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

Hello,

The IParseRequest.Snapshot property returns the immutable ITextSnapshot that contains the text to parse.  ITextSnapshot.Version tells you the ITextVersion associated with the snapshot, where each document text change increments a version.  Each ITextVersion has an Operations collection that tells the changes between versions.  ITextSnapshot.Document tells you the ITextDocument associated with the snapshot. 

If you have two ITextSnapshot instances for the same ITextDocument, then you can translate between them, and also examine the change operations made between each snapshot's versions.  But as mentioned, you must have reference to both snapshots since snapshots fall out of memory once they are no longer referenced.

When parsing, you could probably look at the ITextSnapshot in the parse request, examine its Document property to see if it is an ICodeDocument, and if so, look at its ParseData property.  If the parse data there (returned by the parser) includes the snapshot, then that would be the last snapshot parsed by your parser.  This only works of course after the first parsing is completed because no parse data would be there otherwise.  At this point you have the previously-parsed ITextSnapshot and the current ITextSnapshot (via the parse request). 

You can do any snapshot text range translation between them now.  Or if you want to examine the changes between each snapshot, you can start with the previously-parsed ITextSnapshot, can examine its snapshot.Version.Operations to see what changed between it and the next ITextSnapshot.  The snapshot.Version.Next property gives access to the next ITextVersion, and you can keep repeating this process until you reach the version for the ITextSnapshot currently being parsed.

This documentation topic covers a lot of the basics of snapshots and versioning.


Actipro Software Support

The latest build of this product (v24.1.1) 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.