@@ -70,32 +70,29 @@ protected override async Task RegisterCodeFixesAsync(DocumentEditorCodeFixContex
7070 }
7171 else if ( syntaxRoot . TryFindNodeOrAncestor ( diagnostic , out StatementSyntax ? statement ) )
7272 {
73- if ( statement is LocalDeclarationStatementSyntax lds )
74- {
75- context . RegisterCodeFix (
76- "using" ,
77- ( editor , _ ) => editor . ReplaceNode (
78- lds ,
79- x => x . WithUsingKeyword ( SyntaxFactory . Token ( SyntaxKind . UsingKeyword )
80- . WithLeadingTrivia ( x . Declaration . GetLeadingTrivia ( ) ) )
81- . WithDeclaration ( x . Declaration . WithLeadingTrivia ( SyntaxFactory . TriviaList ( ) ) ) ) ,
82- "using" ,
83- diagnostic ) ;
84- }
85-
8673 switch ( statement )
8774 {
88- case LocalDeclarationStatementSyntax { Declaration : { } , Parent : BlockSyntax _ } localDeclarationStatement :
75+ case LocalDeclarationStatementSyntax { Declaration : { } , Parent : BlockSyntax _ } localDeclaration :
76+ context . RegisterCodeFix (
77+ "using" ,
78+ ( editor , _ ) => editor . ReplaceNode (
79+ localDeclaration ,
80+ x => x . WithUsingKeyword ( SyntaxFactory . Token ( SyntaxKind . UsingKeyword )
81+ . WithLeadingTrivia ( x . Declaration . GetLeadingTrivia ( ) ) )
82+ . WithDeclaration ( x . Declaration . WithLeadingTrivia ( SyntaxFactory . TriviaList ( ) ) ) ) ,
83+ "using" ,
84+ diagnostic ) ;
85+
8986 context . RegisterCodeFix (
9087 "Add using to end of block." ,
91- ( editor , _ ) => AddUsingToEndOfBlock ( editor , localDeclarationStatement ) ,
88+ ( editor , _ ) => AddUsingToEndOfBlock ( editor , localDeclaration ) ,
9289 "Add using to end of block." ,
9390 diagnostic ) ;
9491 break ;
95- case LocalDeclarationStatementSyntax { Declaration : { } , Parent : SwitchSectionSyntax _ } localDeclarationStatement :
92+ case LocalDeclarationStatementSyntax { Declaration : { } , Parent : SwitchSectionSyntax _ } localDeclaration :
9693 context . RegisterCodeFix (
9794 "Add using to end of block." ,
98- ( editor , _ ) => AddUsingToEndOfBlock ( editor , localDeclarationStatement ) ,
95+ ( editor , _ ) => AddUsingToEndOfBlock ( editor , localDeclaration ) ,
9996 "Add using to end of block." ,
10097 diagnostic ) ;
10198 break ;
0 commit comments