11
11
using Microsoft . VisualStudio . Threading ;
12
12
using Path = System . IO . Path ;
13
13
using static System . Diagnostics . Debug ;
14
+ using static Microsoft . CodeAnalysis . Rename . Renamer ;
14
15
15
16
namespace Microsoft . VisualStudio . ProjectSystem . VS . Rename
16
17
{
@@ -30,7 +31,7 @@ internal class FileMoveNotificationListener : IFileMoveNotificationListener
30
31
private readonly IRoslynServices _roslynServices ;
31
32
private readonly IVsService < SVsSettingsPersistenceManager , ISettingsManager > _settingsManagerService ;
32
33
33
- private readonly Dictionary < string , Renamer . RenameDocumentActionSet > _renameActionSets = new ( ) ;
34
+ private readonly Dictionary < string , RenameDocumentActionSet > _renameActionSets = new ( ) ;
34
35
private string ? _renameMessage ;
35
36
36
37
[ ImportingConstructor ]
@@ -59,6 +60,7 @@ public async Task OnBeforeFilesMovedAsync(IReadOnlyCollection<IFileMoveItem> ite
59
60
{
60
61
// Always start with an empty collection when activated.
61
62
_renameActionSets . Clear ( ) ;
63
+
62
64
Project ? project = _workspace . CurrentSolution . Projects . FirstOrDefault ( p => StringComparers . Paths . Equals ( p . FilePath , _unconfiguredProject . FullPath ) ) ;
63
65
if ( project is null )
64
66
{
@@ -75,22 +77,23 @@ public async Task OnBeforeFilesMovedAsync(IReadOnlyCollection<IFileMoveItem> ite
75
77
76
78
// Get the relative folder path from the project to the destination.
77
79
string destinationFolderPath = Path . GetDirectoryName ( _unconfiguredProject . MakeRelative ( itemToMove . Destination ) ) ;
78
- string [ ] documentFolders = destinationFolderPath . Split ( Delimiter . Path , StringSplitOptions . RemoveEmptyEntries ) ;
80
+ string [ ] destinationFolders = destinationFolderPath . Split ( Delimiter . Path , StringSplitOptions . RemoveEmptyEntries ) ;
79
81
80
82
// Since this rename only moves the location of the file to another directory, it will use the SyncNamespaceDocumentAction in Roslyn as the rename action within this set.
81
83
// The logic for selecting this rename action can be found here: https://github.com/dotnet/roslyn/blob/960f375f4825a189937d4bfd9fea8162ecc63177/src/Workspaces/Core/Portable/Rename/Renamer.cs#L133-L136
82
- Renamer . RenameDocumentActionSet renameActionSet = await Renamer . RenameDocumentAsync ( currentDocument , s_renameOptions , null , documentFolders ) ;
83
-
84
- if ( renameActionSet . ApplicableActions . IsEmpty || renameActionSet . ApplicableActions . Any ( a => a . GetErrors ( ) . Any ( ) ) )
84
+ RenameDocumentActionSet renameActionSet = await RenameDocumentAsync ( currentDocument , s_renameOptions , null , destinationFolders ) ;
85
+ if ( renameActionSet . ApplicableActions . IsEmpty || renameActionSet . ApplicableActions . Any ( aa => aa . GetErrors ( ) . Any ( ) ) )
85
86
{
86
87
continue ;
87
88
}
88
- // Getting the rename message requires an instance of Renamer.RenameDocumentAction.
89
+
90
+ // Getting the rename message requires an instance of RenameDocumentAction.
89
91
// We only need to set this message text once for the lifetime of the class, since it isn't dynamic.
90
92
// Even though it isn't dynamic, it does get localized appropriately in Roslyn.
91
93
// The text in English is "Sync namespace to folder structure".
92
94
_renameMessage ??= renameActionSet . ApplicableActions . First ( ) . GetDescription ( ) ;
93
- _renameActionSets . Add ( itemToMove . Destination , renameActionSet ) ;
95
+
96
+ _renameActionSets . Add ( itemToMove . Source , renameActionSet ) ;
94
97
}
95
98
96
99
return ;
@@ -153,14 +156,13 @@ async Task ApplyRenamesAsync(IWaitContext context)
153
156
// After waiting, a "new" published Solution is available.
154
157
Solution solution = _workspace . CurrentSolution ;
155
158
156
- for ( int i = 0 ; i < _renameActionSets . Count ; i ++ )
159
+ int currentStep = 1 ;
160
+ foreach ( KeyValuePair < string , RenameDocumentActionSet > renameActionSet in _renameActionSets )
157
161
{
158
- string destinationPath = _renameActionSets . Keys . ElementAt ( i ) ;
159
162
// Display the filename being updated to the user in the progress dialog.
160
- context . Update ( currentStep : i + 1 , progressText : Path . GetFileName ( destinationPath ) ) ;
163
+ context . Update ( currentStep : currentStep ++ , progressText : Path . GetFileName ( renameActionSet . Key ) ) ;
161
164
162
- Renamer . RenameDocumentActionSet renameActionSet = _renameActionSets [ destinationPath ] ;
163
- solution = await renameActionSet . UpdateSolutionAsync ( solution , token ) ;
165
+ solution = await renameActionSet . Value . UpdateSolutionAsync ( solution , token ) ;
164
166
}
165
167
166
168
await _threadingService . SwitchToUIThread ( token ) ;
0 commit comments