Using Visual Studio SDK Refactor Rename service in vsix extension project

109 Views Asked by At

I need to create an extension which behaves the same way as the native Refactor.Rename command in Visual Studio (i am interested only in renaming properties and methods names), but with additional functionality. Additional functionality is actually renaming of other properties or methods in other types, which i can locate using Roslyn API. Here comes the first problem. I know about Roslyn Renamer class, but when i tested in Visual Studio 2017 and 2019, even with renaming options: RenameInComments = true and RenameInStrings = true, documentation comments with cref="PropertyName" are not renamed. For some reason it works only in Visual Studio 2022. It would be great if i know how it is implemented in native Refactor.Rename command (maybe with some VS SDK RenamingService).
The perfect option would be if i can subscribe to some kind of event before or after the renaming operation would be applied, because i need to know not only the new property or method name, but also the supplied renaming options (include comments, include strings, include overloads) and eventually this info to be found in eventargs of that mysterious event (if it exists).
If there is no such event, is there any way to get access to the inline popup renaming window, try to read the textbox value for the new name, checkboxes for the renaming options and of cource whether the user has pressed the key Enter (here has to be considered if the user uses Shift + Enter for preview and then Apply button)?
At first i decided to implement my own renaming logic using Roslyn Renamer.RenameSymbolAsync method with my own window for new name and renaming options, but as i mentioned in Visual Studio 2017 and 2019 (earlier Roslyn Renamer versions) it is not renaming all of the references (e.g. inside documentation comments). Additionally, i do not know how to implement similar inline renaming popup window, i only know about dialog and tool windows.
Then i try to catch CommandEvents.AfterExecute event of Refactor.Rename command, but it rises after the popup renaming window appears, and i need such event after the renaming window's form is filled out and submitted for getting new member name and renaming options.
I know there are MEF components ICommandHandler<T> s and IChainedCommandHandler<T> s, but is it possible to implement my own handler and how to chain it after the native one? The problem with Renamer renaming logic remains (documentation comments - cref). Another problem is, i think, in earlier versions of Visual Studio 2017 MEF components cannot be used.
If it is important, i use Community.VisualStudio.Toolkit and extension will support only C#.

0

There are 0 best solutions below