Need help with CompilerErrorSpanIndicator

SyntaxEditor for Windows Forms Forum

Posted 18 years ago by Bob Puckett
Version: 4.0.0250
Platform: .NET 2.0
Environment: Windows XP (32-bit)
Avatar
My compiler reports the starting and ending offset of each token and when an error occurs, I want to indicate the position in the edtor. Here is my code:
                CompilerErrorSpanIndicator indicator = new CompilerErrorSpanIndicator();
                myDocumentEditor.Document.SpanIndicatorLayers[0].Add(indicator, new TextRange(sender.OffendingToken.StartPosition, sender.OffendingToken.EndPosition));
However, the squiggle doesn't appear where I expect it to. It appears to be drawn several spaces farther in the text that I expected. It appears that the offset is farther depending on what line the the document it is on.

Is it possible that the editor is counting characters that my scanner does not see? This worked correctly before updating my code to 4.0. I count the characters in the editor and my offsets appear to be correct.

Is there a property that I have set incorrectly?

It also appears that the length of the span is 1 less than it should be. If the starting offset is 19 and the end is 22, it appears to underline just 3 characters. If the error starts and ends at the same spot becuase it is only 1 character, the indicator does not appear at all.

The same behavior is true for WaveLineSpanIndicator.

Comments (2)

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

Note that there were several breaking changes in v4.0 (which are described in the Readme and in the Converting to 4.0 topic in the docs) that might be causing you issues here.

In v3.1 there was some inconsistency of what end offsets meant. In a couple places the "end" offset was the character that ended the range and in most others, it was the offset after the last character in the range. In v4.0 end offset are always the offset AFTER the last character in the range. This is probably your off by one issue.

The other one sounds like something to do with line ends. It seems like you might be getting offsets for text with CRLF but then updating it in the document which is only LF-based internally. That would cause a larger slide the farther down in the docs. I'm not aware of this happening anywhere in our code but it might be in your code if you are accessing the Document.Text or Document.Substring or EditorView.SelectedText methods since in v4.0, those changed to include CRLF line ends instead of LF-only. If you need the LF-only variations there are GetText, GetSubstring overload, and GetSelectedText methods that let you specify you want LF-only.

Hope that helps.


Actipro Software Support

Posted 18 years ago by Bob Puckett
Avatar
Thank you - that did it. I added one to the ending offset to point beyond the token and used GetText(LineTerminator.Newline) instead of .Text. Thanks again.
The latest build of this product (v24.1.1) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.