Open ramiabughazaleh opened 7 years ago
Marking this blocked because there is no proper document rename API in Roslyn to achieve this behavior.
There already is an issue filed (dotnet/roslyn#6261) for this.
Any news on this?
@ClassTerr At this time I'm not aware of anyone pursuing this issue. If you find a solution please consider submitting a pull request for it.
Looks like something like this might work (although I have not actually tried it):
Microsoft.CodeAnalysis.Rename.Renamer.RenameDocumentActionSet actionSet =
await Microsoft.CodeAnalysis.Rename.Renamer.RenameDocumentAsync(
document,
newDocumentName,
newDocumentFolders: null,
optionSet: null,
cancellationToken).ConfigureAwait(false);
solution = await actionSet.UpdateSolutionAsync(solution, cancellationToken).ConfigureAwait(false);
But this is only available in later Roslyn versions. I feel unsure about how to add "light up" support for this in a good way. Compiling expression trees does not sound fun, due to the return type Task<Microsoft.CodeAnalysis.Rename.Renamer.RenameDocumentActionSet>
. Generate source code and compile it at runtime?
This same problem also causes the file to be closed when applying the fix.
"SA1649: File name must match first type name." fix "Rename file to match first type name" will delete and add new file instead of just renaming the file which breaks TFS version control server file history.
Test.cs
Produces warning "SA1649: File name must match first type name." as expected.
However, if I let DotNetAnalyzers fix this by selecting "Rename file to match first type name" from the list of potential fixes,
Test.cs
shows up as deleted andMyTest.cs
shows up as added in Visual Studio's "Pending Changes" window.In contrast, if I just manually rename the file in the "Solution Explorer" window, the file shows up as rename in Visual Studio's "Pending Changes" window.
If I go ahead and check in the changes performed by DotNetAnalyzers, then I cannot view the history on the new file in TFS; whereas the history is maintained if I check in the changes performed when manually renaming the file.
Visual Studio 2015 Update 3 DotNetAnalyzers 1.0.0 TFS 2015 Update 3
Thank you.