@@ -33,8 +33,12 @@ public static async Task<ImmutableArray<ClassifiedSpan>> GetClassifiedSpansAsync
3333 bool includeAdditiveSpans ,
3434 CancellationToken cancellationToken )
3535 {
36- return await GetClassifiedSpansAsync ( document , [ span ] , options , includeAdditiveSpans , cancellationToken )
36+ using var _ = Classifier . GetPooledList ( out var classifiedSpans ) ;
37+
38+ await AddClassifiedSpansAsync ( classifiedSpans , document , [ span ] , options , includeAdditiveSpans , cancellationToken )
3739 . ConfigureAwait ( false ) ;
40+
41+ return [ .. classifiedSpans ] ;
3842 }
3943
4044 /// <summary>
@@ -49,7 +53,8 @@ public static async Task<ImmutableArray<ClassifiedSpan>> GetClassifiedSpansAsync
4953 /// results or not. 'Additive' spans are things like 'this variable is static' or 'this variable is
5054 /// overwritten'. i.e. they add additional information to a previous classification.</param>
5155 /// <param name="cancellationToken">A cancellation token.</param>
52- public static async Task < ImmutableArray < ClassifiedSpan > > GetClassifiedSpansAsync (
56+ public static async Task AddClassifiedSpansAsync (
57+ SegmentedList < ClassifiedSpan > classifiedSpans ,
5358 Document document ,
5459 ImmutableArray < TextSpan > spans ,
5560 ClassificationOptions options ,
@@ -58,7 +63,7 @@ public static async Task<ImmutableArray<ClassifiedSpan>> GetClassifiedSpansAsync
5863 {
5964 var classificationService = document . GetLanguageService < IClassificationService > ( ) ;
6065 if ( classificationService == null )
61- return default ;
66+ return ;
6267
6368 // Call out to the individual language to classify the chunk of text around the
6469 // reference. We'll get both the syntactic and semantic spans for this region.
@@ -90,8 +95,7 @@ public static async Task<ImmutableArray<ClassifiedSpan>> GetClassifiedSpansAsync
9095 }
9196
9297 var widenedSpan = new TextSpan ( spans [ 0 ] . Start , spans [ ^ 1 ] . End ) ;
93- var classifiedSpans = MergeClassifiedSpans ( syntaxSpans , semanticSpans , widenedSpan ) ;
94- return classifiedSpans ;
98+ MergeClassifiedSpans ( syntaxSpans , semanticSpans , widenedSpan , classifiedSpans ) ;
9599 }
96100
97101 private static void RemoveAdditiveSpans ( SegmentedList < ClassifiedSpan > spans )
@@ -104,10 +108,11 @@ private static void RemoveAdditiveSpans(SegmentedList<ClassifiedSpan> spans)
104108 }
105109 }
106110
107- private static ImmutableArray < ClassifiedSpan > MergeClassifiedSpans (
111+ private static void MergeClassifiedSpans (
108112 SegmentedList < ClassifiedSpan > syntaxSpans ,
109113 SegmentedList < ClassifiedSpan > semanticSpans ,
110- TextSpan widenedSpan )
114+ TextSpan widenedSpan ,
115+ SegmentedList < ClassifiedSpan > classifiedSpans )
111116 {
112117 // The spans produced by the language services may not be ordered
113118 // (indeed, this happens with semantic classification as different
@@ -130,16 +135,14 @@ private static ImmutableArray<ClassifiedSpan> MergeClassifiedSpans(
130135 AdjustSpans ( syntaxSpans , widenedSpan ) ;
131136 AdjustSpans ( semanticSpans , widenedSpan ) ;
132137
133- using var _1 = Classifier . GetPooledList ( out var mergedSpans ) ;
138+ using var _ = Classifier . GetPooledList ( out var mergedSpans ) ;
134139
135140 MergeParts ( syntaxSpans , semanticSpans , mergedSpans ) ;
136141 Order ( mergedSpans ) ;
137142
138143 // The classification service will only produce classifications for things it knows about. i.e. there will
139144 // be gaps in what it produces. Fill in those gaps so we have *all* parts of the span classified properly.
140- using var _2 = Classifier . GetPooledList ( out var filledInSpans ) ;
141- FillInClassifiedSpanGaps ( widenedSpan . Start , mergedSpans , filledInSpans ) ;
142- return [ .. filledInSpans ] ;
145+ FillInClassifiedSpanGaps ( widenedSpan . Start , mergedSpans , classifiedSpans ) ;
143146 }
144147
145148 private static readonly Comparison < ClassifiedSpan > s_spanComparison = static ( s1 , s2 ) => s1 . TextSpan . Start - s2 . TextSpan . Start ;
0 commit comments