ReadTokenReverse misses last token when at end of snaphot

SyntaxEditor for WPF Forum

Posted 10 years ago by Phil Devaney - Senior Software Engineer, Serck Controls Ltd
Version: 9.1.0503
Platform: .NET 3.5
Environment: Windows Vista (64-bit)
Avatar
I am trying to use ISnapshotReader.ReadTokenReverse to find out some context information to help fill out a completion list. However, if the reader is positioned at the end of the snapshot, ReadTokenReverse doesn't return the last token, it returns the last but one token.

I am using a DataflowLexer, but if I call DynamicParser.GetTokens then the last token is included. This can also be seen using the SimpleLexer in the 'Getting Started: Simple Language' quickstart.

To reproduce in the sample app: modify SimpleSyntaxLanguage to implement ICompletionProvider, register the service, then add this implementation:

public void RequestSession( ActiproSoftware.Windows.Controls.SyntaxEditor.IEditorView view, bool canCommitWithoutPopup )
{
  var reader = view.GetReader();
  if ( reader.Length == 0 )
    return;

  reader.GoToSnapshotEnd();
  
  Console.Write( "Previous Tokens: " );
  while ( !reader.IsAtSnapshotStart )
  {
    var token = reader.ReadTokenReverse();
    if ( token != null )
      Console.Write( "'{0}' ", reader.Snapshot.GetSubstring( token.TextRange ) );
  }
  Console.WriteLine();
}
Run the sample in the debugger, display the quick start and invoke the completion list. It helps if you cut down the code in the editor, and ensure there's no trailing whitespace. Check the debug output window and you'll see the tokens listed don't include the final '}' token.

Comments (1)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Phil,

Thanks for the bug report. We found the problem and have it fixed for the next build.


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.