Cannot figure out intra-line adornment problem.

SyntaxEditor for WPF Forum

Posted 4 years ago by Peter Yurkosky
Version: 19.1.0684
Platform: .NET 4.8
Environment: Windows 10 (64-bit)
Avatar

I use SyntaxEditor for a SQL editor that we offer in our application. I use adornments to show a custom, inline editor for certain special variable types, directly underneath the variable name in the code. I used to use "intra-text" adornments, because they were all that were available when I wrote the functionality. But these broke badly when I moved to verson 2019. It was difficult to figure out why, but instead of fixing it, I moved to "intra-line" adornments because they seemed to fit my requirements better anyway.

These work fine - usually. I've got a CollectionTagger that I add tags to, whenever a user clicks a small button that appears next to the variable name. Sometimes, though, when I edit code ahead of the variable, the TagVersionRange that I've stored in my tagger does not seem to 'adjust' correctly to the edits. I know this because when I click the little button to show my adornment, my GetTags override returns nothing, because the updated snapshot ranges don't intersect my tag. It's like it's been "left behind" somehow. Here's how I create my TagVersionRange, when the user clicks the little variable button to bring up the editor:

var snapshotRange = new TextSnapshotRange(_syntaxEditor.Document.CurrentSnapshot, tokenTuple.Item3.TextRange);
tagger.Add(snapshotRange, tag);

Does all this sound right? Do you have a sample that combines a CollectionTagger with an intra-line adornment? I've read the CodeLens sample, but it seems different enough from my case, that I can't get useful wisdom from it. I can't figure out what I'm doing wrong.

[Modified 4 years ago]

Comments (6)

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

Hi Peter,

We don't have a sample for intra-line adornments that use a CollectionTagger.  It sounds like the CodeLens one would be closest to what you're trying to do.  Perhaps make a new sample project that clones that sample but change the tagger to be a CollectionTagger instead and reproduce the problem in that sample project.  Then send it (with the bin/obj folders excluded) in a ZIP to our support address and reference this thread.  Also rename the .zip file extension to help prevent it from being spam blocked.  We'll debug it and will have a look to see what's going on.


Actipro Software Support

Posted 4 years ago by Peter Yurkosky
Avatar

Thanks for responding.

I wish your suggestion would work, but the CodeLens example is different enough that I can't adapt it to my purposes. I don't even know if my use of the CollectionTagger is really the problem.

This is a hail-mary, but maybe it will help: here's what I see in the debugger when I reproduce a simple version of the problem. I add a newline in front of my variable name, and then delete that newline.

  1. Before any edits, if I click the variable button: Tag is added to Tagger at 248-262, version 2. GetTags returns it as intersecting 240-263, version 2, AddAdornment called for line at range 240-263. This is fine.
  2. Add a newline before our variable name.
  3. Click the button again. Tag is added to Tagger at 252-266, version 3. GetTags returns it as intersecting 244-267, version 3, AddAdornment called for an ITextViewLine at range 244-267. This seems fine, too: my variable's range was advanced by 4 characters (a newline and three tabs, I think)
  4. Hit undo (the newline goes away).
  5. Click the button: Tag is added to Tagger at 252-266, version 4. GetTags returns it as intersecting 240-263, version 4, AddAdornment not called at all. This is weird. Why, when I hit "undo" did the text range associated with my variable not seem to update?

I'm really just looking for ideas here. I've spent several days on this problem now, and I'm not making progress, just kind of blindly stabbing at different solutions, hoping they'll work.

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

Hi Peter,

I would expect undo edits to follow through with the same tagging/adornment sequence in general since they are text changes themselves.

It's hard for us to say what's happening without being able to debug a simple example showing it.  Per our previous reply, it would be most time efficient if you can send us a sample that we can work with to see the issue.  Then we can report back where things may be going wrong and can make any required code changes if some are needed.


Actipro Software Support

Posted 4 years ago by Peter Yurkosky
Avatar

Hi. Thanks for the help so far. Perhaps a new approach will help here. I've noticed something that I think is at the root of my trouble.

I have a MergableToken representing my SQL variable (in bold, below).

select * from StreamGages

 where AGENCY_CD IN ::MyVariable

When I type in front of ::MyVariable, my MergableToken is advanced: I can see its text range and position values increase, and all is well. But when I insert text on the preceding line, my token is not advanced, and its text range and position remain the same. Can you think of any reason why this might be? I think this is what's getting me mixed up.

Posted 4 years ago by Peter Yurkosky
Avatar

Oh lordy I solved it! Writing out that last post got me thinking about what I read about snapshot ranges, and I realized I wasn't translating the text range from the version it was created at, to the version in which it was actually used. Once I did that, everything fell into place. Thanks for all the responses. I'm going to go pop the champagne.

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

Hi Peter,

Yes, you got it.  If you use a TextSnapshotRange to track the token location, make sure you are translating that range to the current document snapshot.  That result should then tell you the range relative to the current document snapshot.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.