11
11
using Microsoft . VisualStudio . Threading ;
12
12
using Path = System . IO . Path ;
13
13
using static System . Diagnostics . Debug ;
14
- //using System.Reflection;
15
14
16
15
namespace Microsoft . VisualStudio . ProjectSystem . VS . Rename
17
16
{
@@ -29,7 +28,6 @@ internal class FileMoveNotificationListener : IFileMoveNotificationListener
29
28
private readonly IVsService < SVsOperationProgress , IVsOperationProgressStatusService > _operationProgressService ;
30
29
private readonly IWaitIndicator _waitService ;
31
30
private readonly IRoslynServices _roslynServices ;
32
- private readonly IServiceProvider _serviceProvider ;
33
31
private readonly IVsService < SVsSettingsPersistenceManager , ISettingsManager > _settingsManagerService ;
34
32
35
33
private readonly Dictionary < string , Renamer . RenameDocumentActionSet > _renameActionSets = new ( ) ;
@@ -45,9 +43,6 @@ public FileMoveNotificationListener(
45
43
IVsService < SVsOperationProgress , IVsOperationProgressStatusService > operationProgressService ,
46
44
IWaitIndicator waitService ,
47
45
IRoslynServices roslynServices ,
48
- #pragma warning disable RS0030 // Do not used banned APIs
49
- [ Import ( typeof ( SVsServiceProvider ) ) ] IServiceProvider serviceProvider ,
50
- #pragma warning restore RS0030 // Do not used banned APIs
51
46
IVsService < SVsSettingsPersistenceManager , ISettingsManager > settingsManagerService )
52
47
{
53
48
_unconfiguredProject = unconfiguredProject ;
@@ -57,7 +52,6 @@ public FileMoveNotificationListener(
57
52
_operationProgressService = operationProgressService ;
58
53
_waitService = waitService ;
59
54
_roslynServices = roslynServices ;
60
- _serviceProvider = serviceProvider ;
61
55
_settingsManagerService = settingsManagerService ;
62
56
}
63
57
@@ -135,52 +129,29 @@ public async Task OnAfterFileMoveAsync()
135
129
136
130
_ = _threadingService . JoinableTaskFactory . RunAsync ( async ( ) =>
137
131
{
132
+ // The wait service requires the main thread to run.
138
133
await _threadingService . SwitchToUIThread ( ) ;
139
- RunningDocumentTable runningDocumentTable = new ( _serviceProvider ) ;
140
-
141
- //await ApplyRenamesAsync(CancellationToken.None, runningDocumentTable);
142
-
143
134
// Displays a dialog showing the progress of updating the namespaces in the files.
144
135
_waitService . Run (
145
136
title : string . Empty ,
146
137
message : _renameMessage ! ,
147
138
allowCancel : true ,
148
- asyncMethod : context => ApplyRenamesAsync ( context , runningDocumentTable ) ,
139
+ asyncMethod : ApplyRenamesAsync ,
149
140
totalSteps : _renameActionSets . Count ) ;
150
141
} ) ;
151
142
152
143
return ;
153
144
154
- async Task ApplyRenamesAsync ( IWaitContext context , RunningDocumentTable runningDocumentTable )
155
- //async Task ApplyRenamesAsync(CancellationToken token, RunningDocumentTable runningDocumentTable)
145
+ async Task ApplyRenamesAsync ( IWaitContext context )
156
146
{
157
147
CancellationToken token = context . CancellationToken ;
158
-
159
- //await _threadingService.SwitchToUIThread(token);
160
- //foreach (string destinationPath in _renameActionSets.Keys)
161
- //{
162
- // // Save the current file to disk if it contains unsaved changes.
163
- // // This guarantees that Roslyn will update the correct document contents when the rename actions are applied to the solution.
164
- // // This must be done prior to acquiring the latest solution.
165
- // // For more details, see: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1595580
166
- // runningDocumentTable.SaveFileIfDirty(destinationPath);
167
- //}
168
-
169
148
await TaskScheduler . Default ;
170
149
// WORKAROUND: We don't yet have a way to wait for the changes to propagate to Roslyn, tracked by https://github.com/dotnet/project-system/issues/3425
171
150
// Instead, we wait for the IntelliSense stage to finish for the entire solution.
172
151
IVsOperationProgressStatusService statusService = await _operationProgressService . GetValueAsync ( token ) ;
173
152
await statusService . GetStageStatus ( CommonOperationProgressStageIds . Intellisense ) . WaitForCompletionAsync ( ) . WithCancellation ( token ) ;
174
153
// After waiting, a "new" published Solution is available.
175
154
Solution solution = _workspace . CurrentSolution ;
176
- //_workspace.WorkspaceChanged += _workspace_WorkspaceChanged;
177
-
178
- //await _threadingService.SwitchToUIThread(token);
179
- //dynamic test = _workspace;
180
- //test.ProcessQueuedWorkOnUIThread();
181
-
182
- //await _threadingService.SwitchToUIThread(token);
183
- //typeof(Workspace).GetMethod("ProcessQueuedWorkOnUIThread").Invoke(_workspace, Array.Empty<object>());
184
155
185
156
for ( int i = 0 ; i < _renameActionSets . Count ; i ++ )
186
157
{
@@ -192,13 +163,6 @@ async Task ApplyRenamesAsync(IWaitContext context, RunningDocumentTable runningD
192
163
solution = await renameActionSet . UpdateSolutionAsync ( solution , token ) ;
193
164
}
194
165
195
- //await _threadingService.SwitchToUIThread(token);
196
- //dynamic test = _workspace;
197
- //test.ProcessQueuedWorkOnUIThread();
198
-
199
- //Thread.Sleep(2000);
200
- //_workspace.WorkspaceChanged -= _workspace_WorkspaceChanged;
201
-
202
166
await _threadingService . SwitchToUIThread ( token ) ;
203
167
bool areChangesApplied = _roslynServices . ApplyChangesToSolution ( _workspace , solution ) ;
204
168
Assert ( areChangesApplied , "ApplyChangesToSolution returned false" ) ;
@@ -229,11 +193,5 @@ async Task<bool> IsEnabledOrConfirmedAsync()
229
193
return isConfirmed ;
230
194
}
231
195
}
232
-
233
- //private void _workspace_WorkspaceChanged(object sender, WorkspaceChangeEventArgs e)
234
- //{
235
- // var test = e.ProjectId;
236
- // Assert(false, "_workspace_WorkspaceChanged");
237
- //}
238
196
}
239
197
}
0 commit comments