Posted 15 years ago
by Phil Devaney
-
Senior Software Engineer,
Serck Controls Ltd
Version: 9.1.0503
Platform: .NET 3.5
Environment: Windows Vista (64-bit)
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: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.
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();
}