mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 17:02:51 +08:00
Preserve whitespace trivia when applying code fix
This commit is contained in:
parent
6b5b31957c
commit
a186fd94ac
@ -107,8 +107,9 @@ namespace Spectre.Console.Analyzer.CodeActions
|
|||||||
SyntaxKind.SimpleMemberAccessExpression,
|
SyntaxKind.SimpleMemberAccessExpression,
|
||||||
IdentifierName(ansiConsoleIdentifier),
|
IdentifierName(ansiConsoleIdentifier),
|
||||||
IdentifierName(originalCaller)))
|
IdentifierName(originalCaller)))
|
||||||
.WithArgumentList(
|
.WithArgumentList(_originalInvocation.ArgumentList)
|
||||||
_originalInvocation.ArgumentList))
|
.WithTrailingTrivia(_originalInvocation.GetTrailingTrivia())
|
||||||
|
.WithLeadingTrivia(_originalInvocation.GetLeadingTrivia()))
|
||||||
.Expression;
|
.Expression;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,46 @@ class TestClass
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Static_call_replaced_with_field_call_Should_Preserve_Trivia()
|
||||||
|
{
|
||||||
|
const string Source = @"
|
||||||
|
using Spectre.Console;
|
||||||
|
|
||||||
|
class TestClass
|
||||||
|
{
|
||||||
|
IAnsiConsole _ansiConsole = AnsiConsole.Console;
|
||||||
|
|
||||||
|
void TestMethod()
|
||||||
|
{
|
||||||
|
var foo = 1;
|
||||||
|
|
||||||
|
AnsiConsole.Write(""this is fine"");
|
||||||
|
_ansiConsole.Write(""Hello, World"");
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
|
||||||
|
const string FixedSource = @"
|
||||||
|
using Spectre.Console;
|
||||||
|
|
||||||
|
class TestClass
|
||||||
|
{
|
||||||
|
IAnsiConsole _ansiConsole = AnsiConsole.Console;
|
||||||
|
|
||||||
|
void TestMethod()
|
||||||
|
{
|
||||||
|
var foo = 1;
|
||||||
|
|
||||||
|
_ansiConsole.Write(""this is fine"");
|
||||||
|
_ansiConsole.Write(""Hello, World"");
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
|
||||||
|
await SpectreAnalyzerVerifier<FavorInstanceAnsiConsoleOverStaticAnalyzer>
|
||||||
|
.VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(12, 9), FixedSource)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Static_call_replaced_with_parameter_call()
|
public async Task Static_call_replaced_with_parameter_call()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user