mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-10-31 09:09:25 +08:00 
			
		
		
		
	Preserve whitespace trivia when applying code fix
This commit is contained in:
		 Patrik Svensson
					Patrik Svensson
				
			
				
					committed by
					
						 Phil Scott
						Phil Scott
					
				
			
			
				
	
			
			
			 Phil Scott
						Phil Scott
					
				
			
						parent
						
							6b5b31957c
						
					
				
				
					commit
					a186fd94ac
				
			| @@ -107,8 +107,9 @@ namespace Spectre.Console.Analyzer.CodeActions | ||||
|                                 SyntaxKind.SimpleMemberAccessExpression, | ||||
|                                 IdentifierName(ansiConsoleIdentifier), | ||||
|                                 IdentifierName(originalCaller))) | ||||
|                         .WithArgumentList( | ||||
|                         _originalInvocation.ArgumentList)) | ||||
|                         .WithArgumentList(_originalInvocation.ArgumentList) | ||||
|                         .WithTrailingTrivia(_originalInvocation.GetTrailingTrivia()) | ||||
|                         .WithLeadingTrivia(_originalInvocation.GetLeadingTrivia())) | ||||
|             .Expression; | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -47,6 +47,46 @@ class TestClass | ||||
|                 .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] | ||||
|         public async Task Static_call_replaced_with_parameter_call() | ||||
|         { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user