diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/SpellCheck/SpellCheckTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/SpellCheck/SpellCheckTests.cs index afe602e4a2dd186b3a9222dc1bf5a82af54e9362..c89773fbfd492919196c31e7620afe8d10f7ef63 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/SpellCheck/SpellCheckTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/SpellCheck/SpellCheckTests.cs @@ -435,5 +435,31 @@ public async Task TestTestMissingName() "[assembly: Microsoft.CodeAnalysis.[||]]"); } + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsSpellcheck)] + [WorkItem(12990, "https://github.com/dotnet/roslyn/issues/12990")] + public async Task TestTrivia1() + { + var text = @" +using System.Text; +class C +{ + void M() + { + /*leading*/ [|stringbuilder|] /*trailing*/ sb = null; + } +}"; + + var expected = @" +using System.Text; +class C +{ + void M() + { + /*leading*/ StringBuilder /*trailing*/ sb = null; + } +}"; + + await TestAsync(text, expected, compareTokens: false); + } } } \ No newline at end of file diff --git a/src/EditorFeatures/VisualBasicTest/Diagnostics/Spellcheck/SpellcheckTests.vb b/src/EditorFeatures/VisualBasicTest/Diagnostics/Spellcheck/SpellcheckTests.vb index 4fe782536ee59e33bfb011eafb2c6e7c43187b97..a11c87bbc763867b6acb34961c338ab20bf65bce 100644 --- a/src/EditorFeatures/VisualBasicTest/Diagnostics/Spellcheck/SpellcheckTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Diagnostics/Spellcheck/SpellcheckTests.vb @@ -459,8 +459,8 @@ End Class End Function - - Public Async Function TestTestObjectConstruction() As Task + + Public Async Function TestObjectConstruction() As Task Await TestAsync( NewLines("Class AwesomeClass \n Sub M() \n Dim foo = New [|AwesomeClas()|] \n End Sub \n End Class"), NewLines("Class AwesomeClass \n Sub M() \n Dim foo = New AwesomeClass() \n End Sub \n End Class"), @@ -468,12 +468,28 @@ index:=0) End Function - + Public Async Function TestTestMissingName() As Task Await TestMissingAsync( NewLines("")) End Function + + Public Async Function TestTrivia1() As Task + Await TestAsync( +"Class AwesomeClass + Sub M() + Dim foo = New [|AwesomeClas|] ' trailing trivia + End Sub +End Class", +"Class AwesomeClass + Sub M() + Dim foo = New AwesomeClass ' trailing trivia + End Sub +End Class", +compareTokens:=False) + End Function + Public Class AddImportTestsWithAddImportDiagnosticProvider Inherits AbstractVisualBasicDiagnosticProviderBasedUserDiagnosticTest @@ -484,7 +500,7 @@ NewLines("")) End Function - + Public Async Function TestIncompleteStatement() As Task Await TestAsync( NewLines("Class AwesomeClass \n Inherits System.Attribute \n End Class \n Module Program \n <[|AwesomeClas|]> \n End Module"), diff --git a/src/Features/CSharp/Portable/CodeFixes/SpellCheck/CSharpSpellcheckCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/SpellCheck/CSharpSpellcheckCodeFixProvider.cs index 37475d4e651bbd20a742acef23a4bd50141329fc..7a3cedd84f24dd1ef7be75230d0abf6ed2afad3d 100644 --- a/src/Features/CSharp/Portable/CodeFixes/SpellCheck/CSharpSpellcheckCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/CodeFixes/SpellCheck/CSharpSpellcheckCodeFixProvider.cs @@ -34,7 +34,7 @@ protected override bool IsGeneric(CompletionItem completionItem) protected override SyntaxToken CreateIdentifier(SimpleNameSyntax nameNode, string newName) { - return SyntaxFactory.Identifier(newName); + return SyntaxFactory.Identifier(newName).WithTriviaFrom(nameNode.Identifier); } } } \ No newline at end of file