Visual Studio MEF Extension - Force Margin Glyphs To Be Updated or Redraw
Asked Answered
O

1

9

The extension I am writing started life from the Walkthrough: Creating a Margin Glyph example provided by Microsoft: https://msdn.microsoft.com/en-us/library/ee361745.aspx

Everything works fine, except I am trying to trigger the redrawing or updating of the margin glyphs whenever the data I use for deciding which line to draw a glyph on changes.

Basically I have a button in a tool window, when the user clicks the button, I want a glyph to appear in the margin. Right now, it does not appear until you scroll away and back, or obviously close and reload the document.

I have researched this, and have seen some code samples that use IViewTaggerProvider instead of ITaggerProvider. In those cases it appeared that a handler for a LayoutChanged event is able to be added to the ITagger derived class which also contains the GetTags method. However I was unable to successfully switch the code from using ITaggerProvider to IViewTaggerProvider, the extension crashed when run. I don't know if this is a change that will lead to the solution, or if it's unnecessary.

How can I force the glyph to get rendered? Can I raise an event of some kind to force the GetTags code to be exercised? How would I raise that event from outside of the class? From the tool window for example?

Oftentimes answered 21/4, 2016 at 6:2 Comment(1)
I have the same question now. Could you please mention whether you have found any workaround for this issue. Exception coming for layout change can be overcome by deleting the ComponentModelCache files.Idle
T
1

You were on the right path, changing from ITaggerProvider to IViewTaggerProvider allowed me to redraw the glyphs. I used the Implementing a Brace Matching Tagger Provider section in Walkthrough: Displaying Matching Braces example to make these changes.

Using the IViewTaggerProvider, you can then call

TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(
                              new SnapshotSpan(
                                      SourceBuffer.CurrentSnapshot,
                                      0, 
                                      SourceBuffer.CurrentSnapshot.Length)));

in your functions to explicitly call GetTags and go over the spans in the current snapshot.

Trepidation answered 20/7, 2017 at 23:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.