Skip to content

Commit 0f9095f

Browse files
authored
Merge pull request #3525 from sharwell/track-nodes
Keep tracked nodes in a list
2 parents 01f7674 + 2fa97fe commit 0f9095f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1133CodeFixProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fi
116116
var syntaxRoot = await document.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
117117
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, fixAllContext.CancellationToken);
118118

119-
var nodes = diagnostics.Select(diagnostic => syntaxRoot.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true).FirstAncestorOrSelf<AttributeListSyntax>());
119+
// 🐉 Need to eagerly evaluate this with ToList() to ensure nodes are not garbage collected between the
120+
// call to TrackNodes and subsequent enumeration.
121+
var nodes = diagnostics.Select(diagnostic => syntaxRoot.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true).FirstAncestorOrSelf<AttributeListSyntax>()).ToList();
120122

121123
var newRoot = syntaxRoot.TrackNodes(nodes);
122124

0 commit comments

Comments
 (0)