Search code examples
c#visual-studiovisual-studio-2015visual-studio-extensionsvsix

How to programmatically refresh VS code editor in VSIX extension


How can I enforce refresh of the Visual Studio's code editor?

I have a VSIX extension which implements custom coloring via VS tagging mechanism. The extension has some settings, for example to turn off coloring. They are integrated into VS settings via DialogPage mechanism, just like in the MSDN example. I use them in my ITaggerProvider CreateTagger implementation to decide if I should use tagger.

When I change the coloring settings the coloring of the opened documents isn't refreshed. But I can close and reopen them and then the documents are colored according to the new setting's value. Is there a way to tell Visual Studio to refresh the code editor and recreate taggers for it?


Solution

  • You may try to close the document and open it again.

        string path = dte.ActiveDocument.FullName;
        dte.ActiveDocument.Save();
        dte.ActiveDocument.Close();
        dte.ItemOperations.OpenFile(path);
    

    Edit: A much better way is to raise the event declared in your tagger class (which implements ITagger interface).