@@ -35,6 +35,25 @@ public void SetsExactlySavedSelectionsOnRecoverSelections()
35
35
m => m . TrySetSelection ( _testModuleSelections [ 2 ] . QualifiedName , It . IsAny < Selection > ( ) ) , Times . Never ) ;
36
36
}
37
37
38
+ [ Test ]
39
+ [ Category ( "Rewriting" ) ]
40
+ public void SavesSelectionsOnlyForOpenCodePanes ( )
41
+ {
42
+ var selectionServiceMock = TestSelectionServiceMock ( ) ;
43
+ var parseManager = new Mock < IParseManager > ( ) . Object ;
44
+ var selectionRecoverer = new SelectionRecoverer ( selectionServiceMock . Object , parseManager ) ;
45
+
46
+ selectionServiceMock . Setup ( m => m . OpenModules ( ) )
47
+ . Returns ( ( ) => _testModuleSelections . Skip ( 1 ) . Select ( qs => qs . QualifiedName ) . ToList ( ) ) ;
48
+
49
+ selectionRecoverer . SaveSelections ( _testModuleSelections . Select ( qualifiedSelection => qualifiedSelection . QualifiedName ) . Take ( 2 ) ) ;
50
+
51
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 0 ] . QualifiedName ) , Times . Never ) ;
52
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 1 ] . QualifiedName ) , Times . Once ) ;
53
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 2 ] . QualifiedName ) , Times . Never ) ;
54
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 3 ] . QualifiedName ) , Times . Never ) ;
55
+ }
56
+
38
57
[ Test ]
39
58
[ Category ( "Rewriting" ) ]
40
59
public void SetsExactlyLastSavedSelectionsOnRecoverSelectionsAfterMultipleSaves ( )
@@ -97,41 +116,64 @@ public void SetsReplacementSelectionOnRecoverSelections_SelectionSavedPreviously
97
116
98
117
selectionRecoverer . SaveSelections ( _testModuleSelections
99
118
. Select ( qualifiedSelection => qualifiedSelection . QualifiedName ) . Take ( 2 ) ) ;
100
- selectionRecoverer . ReplaceSavedSelection ( _testModuleSelections [ 2 ] . QualifiedName , selectionReplacement ) ;
119
+ selectionRecoverer . ReplaceSavedSelection ( _testModuleSelections [ 0 ] . QualifiedName , selectionReplacement ) ;
101
120
selectionRecoverer . RecoverSavedSelections ( ) ;
102
121
103
- foreach ( var qualifiedSelection in _testModuleSelections . Take ( 2 ) )
104
- {
105
- selectionServiceMock . Verify (
106
- m => m . TrySetSelection ( qualifiedSelection . QualifiedName , qualifiedSelection . Selection ) , Times . Once ) ;
107
- }
108
-
109
122
selectionServiceMock . Verify (
110
- m => m . TrySetSelection ( _testModuleSelections [ 2 ] . QualifiedName , selectionReplacement ) , Times . Once ) ;
123
+ m => m . TrySetSelection ( _testModuleSelections [ 0 ] . QualifiedName , selectionReplacement ) , Times . Once ) ;
124
+ selectionServiceMock . Verify (
125
+ m => m . TrySetSelection ( _testModuleSelections [ 1 ] . QualifiedName , _testModuleSelections [ 1 ] . Selection ) ,
126
+ Times . Once ) ;
127
+ selectionServiceMock . Verify (
128
+ m => m . TrySetSelection ( _testModuleSelections [ 2 ] . QualifiedName , It . IsAny < Selection > ( ) ) , Times . Never ) ;
111
129
}
112
130
113
131
[ Test ]
114
132
[ Category ( "Rewriting" ) ]
115
- public void SetsReplacementSelectionOnRecoverSelections_SelectionNotSavedPreviously ( )
133
+ public void SetReplacementSelectionOnRecoverSelections_SelectionNotSavedPreviously_ModuleOpen ( )
116
134
{
117
135
var selectionServiceMock = TestSelectionServiceMock ( ) ;
118
136
var parseManager = new Mock < IParseManager > ( ) . Object ;
119
137
var selectionRecoverer = new SelectionRecoverer ( selectionServiceMock . Object , parseManager ) ;
120
138
121
139
var selectionReplacement = new Selection ( 22 , 2 , 44 , 5 ) ;
122
140
123
- selectionRecoverer . SaveSelections ( _testModuleSelections
124
- . Select ( qualifiedSelection => qualifiedSelection . QualifiedName ) . Take ( 2 ) ) ;
125
- selectionRecoverer . ReplaceSavedSelection ( _testModuleSelections [ 0 ] . QualifiedName , selectionReplacement ) ;
141
+ selectionRecoverer . SaveSelections ( _testModuleSelections . Select ( qualifiedSelection => qualifiedSelection . QualifiedName ) . Take ( 2 ) ) ;
142
+ selectionRecoverer . ReplaceSavedSelection ( _testModuleSelections [ 2 ] . QualifiedName , selectionReplacement ) ;
126
143
selectionRecoverer . RecoverSavedSelections ( ) ;
127
144
128
- selectionServiceMock . Verify (
129
- m => m . TrySetSelection ( _testModuleSelections [ 0 ] . QualifiedName , selectionReplacement ) , Times . Once ) ;
130
- selectionServiceMock . Verify (
131
- m => m . TrySetSelection ( _testModuleSelections [ 1 ] . QualifiedName , _testModuleSelections [ 1 ] . Selection ) ,
132
- Times . Once ) ;
133
- selectionServiceMock . Verify (
134
- m => m . TrySetSelection ( _testModuleSelections [ 2 ] . QualifiedName , It . IsAny < Selection > ( ) ) , Times . Never ) ;
145
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 0 ] . QualifiedName , _testModuleSelections [ 0 ] . Selection ) , Times . Once ) ;
146
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 1 ] . QualifiedName , _testModuleSelections [ 1 ] . Selection ) , Times . Once ) ;
147
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 2 ] . QualifiedName , selectionReplacement ) , Times . Once ) ;
148
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 3 ] . QualifiedName , It . IsAny < Selection > ( ) ) , Times . Never ) ;
149
+ }
150
+
151
+ [ Test ]
152
+ [ Category ( "Rewriting" ) ]
153
+ public void DoesNotSaveOrSetReplacementSelectionOnRecoverSelections_SelectionNotSavedPreviously_ModuleNotOpen ( )
154
+ {
155
+ var selectionServiceMock = TestSelectionServiceMock ( ) ;
156
+ var parseManager = new Mock < IParseManager > ( ) . Object ;
157
+ var selectionRecoverer = new SelectionRecoverer ( selectionServiceMock . Object , parseManager ) ;
158
+
159
+ selectionServiceMock . Setup ( m => m . OpenModules ( ) )
160
+ . Returns ( ( ) => _testModuleSelections . Take ( 2 ) . Select ( qs => qs . QualifiedName ) . ToList ( ) ) ;
161
+
162
+ var selectionReplacement = new Selection ( 22 , 2 , 44 , 5 ) ;
163
+
164
+ selectionRecoverer . SaveSelections ( _testModuleSelections . Select ( qualifiedSelection => qualifiedSelection . QualifiedName ) . Take ( 2 ) ) ;
165
+ selectionRecoverer . ReplaceSavedSelection ( _testModuleSelections [ 2 ] . QualifiedName , selectionReplacement ) ;
166
+ selectionRecoverer . RecoverSavedSelections ( ) ;
167
+
168
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 0 ] . QualifiedName ) , Times . Once ) ;
169
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 1 ] . QualifiedName ) , Times . Once ) ;
170
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 2 ] . QualifiedName ) , Times . Never ) ;
171
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 3 ] . QualifiedName ) , Times . Never ) ;
172
+
173
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 0 ] . QualifiedName , _testModuleSelections [ 0 ] . Selection ) , Times . Once ) ;
174
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 1 ] . QualifiedName , _testModuleSelections [ 1 ] . Selection ) , Times . Once ) ;
175
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 2 ] . QualifiedName , It . IsAny < Selection > ( ) ) , Times . Never ) ;
176
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 3 ] . QualifiedName , It . IsAny < Selection > ( ) ) , Times . Never ) ;
135
177
}
136
178
137
179
[ Test ]
@@ -288,34 +330,67 @@ public void SetsModifiedSelectionAfterOffsetIsAppliedOnParseAfterRecoverSelectio
288
330
m => m . TrySetSelection ( _testModuleSelections [ 2 ] . QualifiedName , It . IsAny < Selection > ( ) ) , Times . Never ) ;
289
331
}
290
332
333
+
334
+
291
335
[ Test ]
292
336
[ Category ( "Rewriting" ) ]
293
- public void SetsReplacementSelectionOnParseAfterRecoverSelectionsOnNextParse_SelectionSavedPreviously ( )
337
+ public void SetReplacementSelectionOnNextParseAfterRecoverSelectionsOnNextParse_SelectionNotSavedPreviously_ModuleOpen ( )
294
338
{
295
339
var selectionServiceMock = TestSelectionServiceMock ( ) ;
296
340
var parseManagerMock = new Mock < IParseManager > ( ) ;
297
341
var selectionRecoverer = new SelectionRecoverer ( selectionServiceMock . Object , parseManagerMock . Object ) ;
298
342
299
343
var selectionReplacement = new Selection ( 22 , 2 , 44 , 5 ) ;
300
344
301
- selectionRecoverer . SaveSelections ( _testModuleSelections
302
- . Select ( qualifiedSelection => qualifiedSelection . QualifiedName ) . Take ( 2 ) ) ;
345
+ selectionRecoverer . SaveSelections ( _testModuleSelections . Select ( qualifiedSelection => qualifiedSelection . QualifiedName ) . Take ( 2 ) ) ;
303
346
selectionRecoverer . ReplaceSavedSelection ( _testModuleSelections [ 2 ] . QualifiedName , selectionReplacement ) ;
304
- selectionRecoverer . RecoverSavedSelections ( ) ;
347
+ selectionRecoverer . RecoverSavedSelectionsOnNextParse ( ) ;
305
348
306
- foreach ( var qualifiedSelection in _testModuleSelections . Take ( 2 ) )
307
- {
308
- selectionServiceMock . Verify (
309
- m => m . TrySetSelection ( qualifiedSelection . QualifiedName , qualifiedSelection . Selection ) , Times . Once ) ;
310
- }
349
+ var stateEventArgs = new ParserStateEventArgs ( _stateExpectedToTriggerTheRecovery , ParserState . Pending ,
350
+ CancellationToken . None ) ;
351
+ parseManagerMock . Raise ( m => m . StateChanged += null , stateEventArgs ) ;
311
352
312
- selectionServiceMock . Verify (
313
- m => m . TrySetSelection ( _testModuleSelections [ 2 ] . QualifiedName , selectionReplacement ) , Times . Once ) ;
353
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 0 ] . QualifiedName , _testModuleSelections [ 0 ] . Selection ) , Times . Once ) ;
354
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 1 ] . QualifiedName , _testModuleSelections [ 1 ] . Selection ) , Times . Once ) ;
355
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 2 ] . QualifiedName , selectionReplacement ) , Times . Once ) ;
356
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 3 ] . QualifiedName , It . IsAny < Selection > ( ) ) , Times . Never ) ;
357
+ }
358
+
359
+ [ Test ]
360
+ [ Category ( "Rewriting" ) ]
361
+ public void DoesNotSaveOrSetReplacementSelectionOnOnNextParseAfterRecoverSelectionsOnNextParse_SelectionNotSavedPreviously_ModuleNotOpen ( )
362
+ {
363
+ var selectionServiceMock = TestSelectionServiceMock ( ) ;
364
+ var parseManagerMock = new Mock < IParseManager > ( ) ;
365
+ var selectionRecoverer = new SelectionRecoverer ( selectionServiceMock . Object , parseManagerMock . Object ) ;
366
+
367
+ selectionServiceMock . Setup ( m => m . OpenModules ( ) )
368
+ . Returns ( ( ) => _testModuleSelections . Take ( 2 ) . Select ( qs => qs . QualifiedName ) . ToList ( ) ) ;
369
+
370
+ var selectionReplacement = new Selection ( 22 , 2 , 44 , 5 ) ;
371
+
372
+ selectionRecoverer . SaveSelections ( _testModuleSelections . Select ( qualifiedSelection => qualifiedSelection . QualifiedName ) . Take ( 2 ) ) ;
373
+ selectionRecoverer . ReplaceSavedSelection ( _testModuleSelections [ 2 ] . QualifiedName , selectionReplacement ) ;
374
+ selectionRecoverer . RecoverSavedSelectionsOnNextParse ( ) ;
375
+
376
+ var stateEventArgs = new ParserStateEventArgs ( _stateExpectedToTriggerTheRecovery , ParserState . Pending ,
377
+ CancellationToken . None ) ;
378
+ parseManagerMock . Raise ( m => m . StateChanged += null , stateEventArgs ) ;
379
+
380
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 0 ] . QualifiedName ) , Times . Once ) ;
381
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 1 ] . QualifiedName ) , Times . Once ) ;
382
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 2 ] . QualifiedName ) , Times . Never ) ;
383
+ selectionServiceMock . Verify ( m => m . Selection ( _testModuleSelections [ 3 ] . QualifiedName ) , Times . Never ) ;
384
+
385
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 0 ] . QualifiedName , _testModuleSelections [ 0 ] . Selection ) , Times . Once ) ;
386
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 1 ] . QualifiedName , _testModuleSelections [ 1 ] . Selection ) , Times . Once ) ;
387
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 2 ] . QualifiedName , It . IsAny < Selection > ( ) ) , Times . Never ) ;
388
+ selectionServiceMock . Verify ( m => m . TrySetSelection ( _testModuleSelections [ 3 ] . QualifiedName , It . IsAny < Selection > ( ) ) , Times . Never ) ;
314
389
}
315
390
316
391
[ Test ]
317
392
[ Category ( "Rewriting" ) ]
318
- public void SetsReplacementSelectionOnParseAfterRecoverSelectionsOnNextParse_SelectionNotSavedPreviously ( )
393
+ public void SetsReplacementSelectionOnParseAfterRecoverSelectionsOnNextParse_SelectionSavedPreviously ( )
319
394
{
320
395
var selectionServiceMock = TestSelectionServiceMock ( ) ;
321
396
var parseManagerMock = new Mock < IParseManager > ( ) ;
0 commit comments