Skip to content

Commit a70b521

Browse files
paulirwinclaude
andcommitted
Match source line-ending convention in 4002 code fix
The fix previously emitted '\n' line terminators unconditionally, which matched local Mac checkouts (LF) but failed on Linux CI where the checked-out source uses CRLF. Detect the existing line ending from the target tree's trivia and reuse it so the fixed output stays consistent with the surrounding file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f92d020 commit a70b521

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/Lucene.Net.CodeAnalysis.Dev.CodeFixes/LuceneDev4xxx/LuceneDev4002_StackTraceHelperNoInliningCodeFixProvider.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ private static async Task<Solution> AddNoInliningToTargetAsync(
156156
SyntaxFactory.IdentifierName("NoInlining"))))));
157157

158158
var leadingIndent = ExtractLeadingIndentation(targetDecl);
159+
var endOfLine = DetectEndOfLine(targetRoot);
159160
var newAttributeList = SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(attribute))
160161
.WithLeadingTrivia(targetDecl.GetLeadingTrivia())
161-
.WithTrailingTrivia(SyntaxFactory.EndOfLine("\n"), leadingIndent);
162+
.WithTrailingTrivia(endOfLine, leadingIndent);
162163

163164
var newAttributeLists = SyntaxFactory.List<AttributeListSyntax>(
164165
new[] { newAttributeList }.Concat(targetDecl.AttributeLists));
@@ -177,7 +178,7 @@ private static async Task<Solution> AddNoInliningToTargetAsync(
177178
if (!hasUsing)
178179
{
179180
var usingDirective = SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(requiredNs))
180-
.WithTrailingTrivia(SyntaxFactory.EndOfLine("\n"));
181+
.WithTrailingTrivia(endOfLine);
181182
compilationUnit = compilationUnit.AddUsings(usingDirective);
182183
newTargetRoot = compilationUnit;
183184
}
@@ -186,6 +187,18 @@ private static async Task<Solution> AddNoInliningToTargetAsync(
186187
return solution.WithDocumentSyntaxRoot(targetDocument.Id, newTargetRoot);
187188
}
188189

190+
private static SyntaxTrivia DetectEndOfLine(SyntaxNode root)
191+
{
192+
// Match the source's existing line-ending convention so the fixed
193+
// output doesn't mix CRLF and LF.
194+
foreach (var trivia in root.DescendantTrivia())
195+
{
196+
if (trivia.IsKind(SyntaxKind.EndOfLineTrivia))
197+
return trivia;
198+
}
199+
return SyntaxFactory.EndOfLine("\n");
200+
}
201+
189202
private static SyntaxTrivia ExtractLeadingIndentation(SyntaxNode node)
190203
{
191204
// Indentation = trailing whitespace of the leading trivia (after the

0 commit comments

Comments
 (0)