@@ -190,7 +190,7 @@ public override AbstractFormattingRule WithOptions(SyntaxFormattingOptions optio
190190 return CreateAdjustNewLinesOperation ( 1 , AdjustNewLinesOption . PreserveLines ) ;
191191 }
192192
193- // ; * or ; * for using directive
193+ // ; * or ; * for using directive and file scoped namespace
194194 if ( previousToken . Kind ( ) == SyntaxKind . SemicolonToken )
195195 {
196196 return AdjustNewLinesAfterSemicolonToken ( previousToken , currentToken ) ;
@@ -225,31 +225,37 @@ MemberDeclarationSyntax or
225225 private AdjustNewLinesOperation AdjustNewLinesAfterSemicolonToken (
226226 SyntaxToken previousToken , SyntaxToken currentToken )
227227 {
228- // between anything that isn't a using directive, we don't touch newlines after a semicolon
229- if ( previousToken . Parent is not UsingDirectiveSyntax previousUsing )
230- return CreateAdjustNewLinesOperation ( 0 , AdjustNewLinesOption . PreserveLines ) ;
231-
232- // if the user is separating using-groups, and we're between two usings, and these
233- // usings *should* be separated, then do so (if the usings were already properly
234- // sorted).
235- if ( _options . SeparateImportDirectiveGroups &&
236- currentToken . Parent is UsingDirectiveSyntax currentUsing &&
237- UsingsAndExternAliasesOrganizer . NeedsGrouping ( previousUsing , currentUsing ) )
238- {
239- RoslynDebug . AssertNotNull ( currentUsing . Parent ) ;
240-
241- var usings = GetUsings ( currentUsing . Parent ) ;
242- if ( usings . IsSorted ( UsingsAndExternAliasesDirectiveComparer . SystemFirstInstance ) ||
243- usings . IsSorted ( UsingsAndExternAliasesDirectiveComparer . NormalInstance ) )
228+ if ( previousToken . Parent is UsingDirectiveSyntax previousUsing )
229+ {
230+ // if the user is separating using-groups, and we're between two usings, and these
231+ // usings *should* be separated, then do so (if the usings were already properly
232+ // sorted).
233+ if ( _options . SeparateImportDirectiveGroups &&
234+ currentToken . Parent is UsingDirectiveSyntax currentUsing &&
235+ UsingsAndExternAliasesOrganizer . NeedsGrouping ( previousUsing , currentUsing ) )
244236 {
245- // Force at least one blank line here.
246- return CreateAdjustNewLinesOperation ( 2 , AdjustNewLinesOption . PreserveLines ) ;
237+ RoslynDebug . AssertNotNull ( currentUsing . Parent ) ;
238+
239+ var usings = GetUsings ( currentUsing . Parent ) ;
240+ if ( usings . IsSorted ( UsingsAndExternAliasesDirectiveComparer . SystemFirstInstance ) ||
241+ usings . IsSorted ( UsingsAndExternAliasesDirectiveComparer . NormalInstance ) )
242+ {
243+ // Force at least one blank line here.
244+ return CreateAdjustNewLinesOperation ( 2 , AdjustNewLinesOption . PreserveLines ) ;
245+ }
247246 }
247+
248+ // For all other cases where we have a using-directive, just make sure it's followed by
249+ // a new-line.
250+ return CreateAdjustNewLinesOperation ( 1 , AdjustNewLinesOption . PreserveLines ) ;
248251 }
249252
250- // For all other cases where we have a using-directive, just make sure it's followed by
251- // a new-line.
252- return CreateAdjustNewLinesOperation ( 1 , AdjustNewLinesOption . PreserveLines ) ;
253+ // ensure that there is a newline after a file scoped namespace declaration
254+ if ( previousToken . Parent is FileScopedNamespaceDeclarationSyntax )
255+ return CreateAdjustNewLinesOperation ( 2 , AdjustNewLinesOption . PreserveLines ) ;
256+
257+ // between anything that isn't a using directive or file scoped namespace declaration, we don't touch newlines after a semicolon
258+ return CreateAdjustNewLinesOperation ( 0 , AdjustNewLinesOption . PreserveLines ) ;
253259 }
254260
255261 private static SyntaxList < UsingDirectiveSyntax > GetUsings ( SyntaxNode node )
0 commit comments