@@ -55,19 +55,22 @@ public ITrackedLines Create(List<ILine> lines, ITextSnapshot textSnapshot)
5555 {
5656 ICoverageContentType coverageContentType = this . GetCoverageContentType ( textSnapshot ) ;
5757 IFileCodeSpanRangeService fileCodeSpanRangeService = coverageContentType . FileCodeSpanRangeService ;
58- List < IContainingCodeTracker > containingCodeTrackers = this . CreateContainingCodeTrackers (
58+ ( List < IContainingCodeTracker > containingCodeTrackers , bool usedFileCodeSpanRangeService ) = this . CreateContainingCodeTrackers (
5959 lines , textSnapshot , fileCodeSpanRangeService , coverageContentType . CoverageOnlyFromFileCodeSpanRangeService ) ;
60- return containingCodeTrackers == null
60+
61+ IContainingCodeTrackerTrackedLines trackedLines = containingCodeTrackers == null
6162 ? this . GetNonTrackingTrackedLines ( )
6263 : this . containingCodeTrackedLinesFactory . Create (
6364 containingCodeTrackers ,
6465 this . GetNewCodeTrackerIfProvidesLineExcluder ( coverageContentType . LineExcluder ) ,
6566 this . GetFileCodeSpanRangeServiceForChanges ( coverageContentType ) ) ;
67+
68+ return new ContainingCodeTrackerTrackedLinesWithState ( trackedLines , usedFileCodeSpanRangeService ) ;
6669 }
6770
68- private ITrackedLines GetNonTrackingTrackedLines ( ) => this . containingCodeTrackedLinesFactory . Create ( new List < IContainingCodeTracker > ( ) , null , null ) ;
71+ private IContainingCodeTrackerTrackedLines GetNonTrackingTrackedLines ( ) => this . containingCodeTrackedLinesFactory . Create ( new List < IContainingCodeTracker > ( ) , null , null ) ;
6972
70- private List < IContainingCodeTracker > CreateContainingCodeTrackers (
73+ private ( List < IContainingCodeTracker > containingCodeTrackers , bool usedFileCodeSpanRangeService ) CreateContainingCodeTrackers (
7174 List < ILine > lines ,
7275 ITextSnapshot textSnapshot ,
7376 IFileCodeSpanRangeService fileCodeSpanRangeService ,
@@ -76,20 +79,20 @@ bool coverageOnlyFromFileCodeSpanRangeService
7679 {
7780 if ( this . AnyLinesOutsideTextSnapshot ( lines , textSnapshot ) )
7881 {
79- return null ;
82+ return ( null , false ) ;
8083 }
8184
8285 if ( fileCodeSpanRangeService != null )
8386 {
8487 List < CodeSpanRange > codeSpanRanges = fileCodeSpanRangeService . GetFileCodeSpanRanges ( textSnapshot ) ;
8588 if ( codeSpanRanges != null )
8689 {
87- return this . CreateContainingCodeTrackersFromCodeSpanRanges (
88- lines , textSnapshot , codeSpanRanges , coverageOnlyFromFileCodeSpanRangeService ) ;
90+ return ( this . CreateContainingCodeTrackersFromCodeSpanRanges (
91+ lines , textSnapshot , codeSpanRanges , coverageOnlyFromFileCodeSpanRangeService ) , true ) ;
8992 }
9093 }
9194
92- return lines . Select ( line => this . CreateSingleLineContainingCodeTracker ( textSnapshot , line ) ) . ToList ( ) ;
95+ return ( lines . Select ( line => this . CreateSingleLineContainingCodeTracker ( textSnapshot , line ) ) . ToList ( ) , false ) ;
9396 }
9497
9598 private bool AnyLinesOutsideTextSnapshot ( List < ILine > lines , ITextSnapshot textSnapshot )
@@ -204,7 +207,7 @@ void CreateOtherLine(int otherCodeLine)
204207
205208 #region Serialization
206209
207- private ITrackedLines RecreateTrackedLines (
210+ private IContainingCodeTrackerTrackedLines RecreateTrackedLinesNoFileCodeSpanRangeService (
208211 List < SerializedContainingCodeTracker > serializedContainingCodeTrackers ,
209212 ITextSnapshot currentSnapshot ,
210213 ILineExcluder lineExcluder ,
@@ -267,14 +270,14 @@ ITextSnapshot currentSnapshot
267270 return containingCodeTracker ;
268271 }
269272
270- private ITrackedLines RecreateTrackedLines (
273+ private IContainingCodeTrackerTrackedLines RecreateTrackedLinesFileCodeSpanRangeService (
271274 List < SerializedContainingCodeTracker > serializedContainingCodeTrackers ,
272275 ITextSnapshot currentSnapshot ,
273276 ICoverageContentType coverageContentType )
274277 {
275- List < CodeSpanRange > codeSpanRanges = coverageContentType . FileCodeSpanRangeService . GetFileCodeSpanRanges ( currentSnapshot ) ;
276278 List < IContainingCodeTracker > containingCodeTrackers = this . RecreateContainingCodeTrackers (
277279 serializedContainingCodeTrackers , currentSnapshot ) ;
280+ List < CodeSpanRange > codeSpanRanges = coverageContentType . FileCodeSpanRangeService . GetFileCodeSpanRanges ( currentSnapshot ) ;
278281 INewCodeTracker newCodeTracker = this . RecreateNewCodeTracker (
279282 serializedContainingCodeTrackers ,
280283 currentSnapshot ,
@@ -330,26 +333,29 @@ private IEnumerable<int> EveryLineInCodeSpanRanges(List<CodeSpanRange> newCodeCo
330333 public ITrackedLines Create ( string serializedCoverage , ITextSnapshot currentSnapshot )
331334 {
332335 SerializedEditorDynamicCoverage serializedEditorDynamicCoverage = this . jsonConvertService . DeserializeObject < SerializedEditorDynamicCoverage > ( serializedCoverage ) ;
333-
334- return this . TextUnchanged ( serializedEditorDynamicCoverage , currentSnapshot )
336+ bool usedFileCodeSpanRangeService = serializedEditorDynamicCoverage . UsedFileCodeSpanRangeService ;
337+ IContainingCodeTrackerTrackedLines trackedLines = this . TextUnchanged ( serializedEditorDynamicCoverage , currentSnapshot )
335338 ? this . RecreateTrackedLines (
336339 serializedEditorDynamicCoverage . SerializedContainingCodeTrackers ,
337340 serializedEditorDynamicCoverage . NewCodeLineNumbers ,
338- currentSnapshot )
341+ currentSnapshot ,
342+ usedFileCodeSpanRangeService
343+ )
339344 : this . GetNonTrackingTrackedLines ( ) ;
345+ return new ContainingCodeTrackerTrackedLinesWithState ( trackedLines , usedFileCodeSpanRangeService ) ;
340346 }
341347
342- private ITrackedLines RecreateTrackedLines (
348+ private IContainingCodeTrackerTrackedLines RecreateTrackedLines (
343349 List < SerializedContainingCodeTracker > serializedContainingCodeTrackers ,
344350 List < int > newCodeLineNumbers ,
345- ITextSnapshot currentSnapshot
351+ ITextSnapshot currentSnapshot ,
352+ bool usedFileCodeSpanRangeService
346353 )
347354 {
348355 ICoverageContentType coverageContentType = this . GetCoverageContentType ( currentSnapshot ) ;
349- IFileCodeSpanRangeService fileCodeSpanRangeService = coverageContentType . FileCodeSpanRangeService ;
350- return fileCodeSpanRangeService == null
351- ? this . RecreateTrackedLines ( serializedContainingCodeTrackers , currentSnapshot , coverageContentType . LineExcluder , newCodeLineNumbers )
352- : this . RecreateTrackedLines ( serializedContainingCodeTrackers , currentSnapshot , coverageContentType ) ;
356+ return usedFileCodeSpanRangeService ?
357+ this . RecreateTrackedLinesFileCodeSpanRangeService ( serializedContainingCodeTrackers , currentSnapshot , coverageContentType ) :
358+ this . RecreateTrackedLinesNoFileCodeSpanRangeService ( serializedContainingCodeTrackers , currentSnapshot , coverageContentType . LineExcluder , newCodeLineNumbers ) ;
353359 }
354360
355361 private bool TextUnchanged ( SerializedEditorDynamicCoverage serializedEditorDyamicCoverage , ITextSnapshot textSnapshot )
@@ -361,13 +367,20 @@ private bool TextUnchanged(SerializedEditorDynamicCoverage serializedEditorDyami
361367
362368 public string Serialize ( ITrackedLines trackedLines , string text )
363369 {
364- var containingCodeTrackerTrackedLines = trackedLines as IContainingCodeTrackerTrackedLines ;
365- List < SerializedContainingCodeTracker > serializedContainingCodeTrackers = this . GetSerializedContainingCodeTrackers ( containingCodeTrackerTrackedLines ) ;
370+ var containingCodeTrackerTrackedLinesWithState = trackedLines as ContainingCodeTrackerTrackedLinesWithState ;
371+ List < SerializedContainingCodeTracker > serializedContainingCodeTrackers = this . GetSerializedContainingCodeTrackers ( containingCodeTrackerTrackedLinesWithState ) ;
372+ var newCodeLineNumbers = new List < int > ( ) ;
373+ if ( containingCodeTrackerTrackedLinesWithState . NewCodeTracker != null )
374+ {
375+ newCodeLineNumbers = containingCodeTrackerTrackedLinesWithState . NewCodeTracker . Lines . Select ( l => l . Number ) . ToList ( ) ;
376+ }
377+
366378 return this . jsonConvertService . SerializeObject (
367379 new SerializedEditorDynamicCoverage {
368380 SerializedContainingCodeTrackers = serializedContainingCodeTrackers ,
369381 Text = text ,
370- NewCodeLineNumbers = containingCodeTrackerTrackedLines . NewCodeTracker ? . Lines . Select ( l => l . Number ) . ToList ( )
382+ NewCodeLineNumbers = newCodeLineNumbers ,
383+ UsedFileCodeSpanRangeService = containingCodeTrackerTrackedLinesWithState . UsedFileCodeSpanRangeService
371384 } ) ;
372385 }
373386
0 commit comments