@@ -44,68 +44,26 @@ public static async Task ModifyAllReferencesAsync(
4444 }
4545
4646 // Find all locations where the symbols are referenced
47- var locations = new List < Location > ( ) ;
4847 var documents = project . Documents . ToImmutableHashSet ( ) ;
49- foreach ( var symbol in symbolSet )
50- {
51- var references = await SymbolFinder . FindReferencesAsync ( symbol , project . Solution , documents , ct ) ;
52- locations . AddRange ( references . SelectMany ( r => r . Locations ) . Select ( rl => rl . Location ) ) ;
53- }
54-
55- // var locations = new ConcurrentDictionary<Location, string>();
56- // // TODO this needs parallelisation config & be sensitive to the environment (future src generator form factor?)
57- // await Parallel.ForEachAsync(
58- // toRename,
59- // ct,
60- // async (tuple, _) =>
61- // {
62- // // First, let's add all of the locations of the declaration identifiers.
63- // var (symbol, newName) = tuple;
64- // if (includeDeclarations)
65- // {
66- // foreach (var syntaxRef in symbol.DeclaringSyntaxReferences)
67- // {
68- // var identifierLocation = IdentifierLocation(
69- // await syntaxRef.GetSyntaxAsync(ct)
70- // );
71- // if (identifierLocation is not null)
72- // {
73- // locations.TryAdd(identifierLocation, newName);
74- // }
75- // }
76- // }
77- //
78- // // Next, let's find all the references of the symbols.
79- // var references = await SymbolFinder.FindReferencesAsync(
80- // symbol,
81- // ctx.SourceProject?.Solution
82- // ?? throw new ArgumentException("SourceProject is null"),
83- // ct
84- // );
85- //
86- // foreach (var referencedSymbol in references)
87- // {
88- // foreach (var referencedSymbolLocation in referencedSymbol.Locations)
89- // {
90- // if (
91- // !includeCandidateLocations
92- // && (
93- // referencedSymbolLocation.IsCandidateLocation
94- // || referencedSymbolLocation.IsImplicit
95- // )
96- // )
97- // {
98- // continue;
99- // }
100- //
101- // locations.TryAdd(referencedSymbolLocation.Location, newName);
102- // }
103- // }
104- // }
105- // );
48+ var locations = new ConcurrentBag < ( ISymbol Symbol , Location Location ) > ( ) ;
49+ // TODO this needs parallelisation config & be sensitive to the environment (future src generator form factor?)
50+ await Parallel . ForEachAsync (
51+ symbolSet ,
52+ ct ,
53+ async ( symbol , _ ) => {
54+ var references = await SymbolFinder . FindReferencesAsync ( symbol , project . Solution , documents , ct ) ;
55+ foreach ( var reference in references )
56+ {
57+ foreach ( var location in reference . Locations )
58+ {
59+ locations . Add ( ( symbol , location . Location ) ) ;
60+ }
61+ }
62+ }
63+ ) ;
10664
10765 // Group the locations by source tree. This will be used to prevent accidentally overwriting changes.
108- var locationsBySourcetree = locations . GroupBy ( l => l . SourceTree ) ;
66+ var locationsBySourcetree = locations . GroupBy ( l => l . Location . SourceTree ) ;
10967 foreach ( var group in locationsBySourcetree )
11068 {
11169 var syntaxTree = group . Key ;
@@ -125,12 +83,12 @@ public static async Task ModifyAllReferencesAsync(
12583 // Modify each location
12684 // We order the locations so that we modify starting from the end of the file
12785 // This way we prevent changes from being accidentally overwriting changes
128- foreach ( var location in group . OrderByDescending ( l => l . SourceSpan . Start ) )
86+ foreach ( var ( symbol , location ) in group . OrderByDescending ( l => l . Location . SourceSpan . Start ) )
12987 {
13088 foreach ( var transformer in transformersSet )
13189 {
13290 var syntaxNode = syntaxRoot . FindNode ( location . SourceSpan ) ;
133- var nodeToModify = transformer . GetNodeToModify ( syntaxNode ) ;
91+ var nodeToModify = transformer . GetNodeToModify ( syntaxNode , symbol ) ;
13492 if ( nodeToModify == null )
13593 {
13694 continue ;
@@ -162,9 +120,10 @@ public abstract class LocationTransformer : CSharpSyntaxRewriter
162120 /// Returning null will lead to no node being modified.
163121 /// Returning the parent node will lead to the parent node being modified instead of the original node.
164122 /// </summary>
165- /// <param name="current">TODO</param>
166- /// <returns>TODO</returns>
167- public abstract SyntaxNode ? GetNodeToModify ( SyntaxNode current ) ;
123+ /// <param name="current">The current node.</param>
124+ /// <param name="symbol">The symbol that was used to find the current node.</param>
125+ /// <returns>The parent of the given node, the given node, or null.</returns>
126+ public abstract SyntaxNode ? GetNodeToModify ( SyntaxNode current , ISymbol symbol ) ;
168127}
169128
170129// // TODO: Implement this
@@ -194,7 +153,7 @@ public abstract class LocationTransformer : CSharpSyntaxRewriter
194153public class PointerDimensionReductionTransformer : LocationTransformer
195154{
196155 /// <inheritdoc />
197- public override SyntaxNode ? GetNodeToModify ( SyntaxNode current )
156+ public override SyntaxNode ? GetNodeToModify ( SyntaxNode current , ISymbol symbol )
198157 {
199158 if ( current . Parent is PointerTypeSyntax parent )
200159 {
0 commit comments