@@ -225,8 +225,9 @@ private static void BuildReplaceMapForNamespaces(UsingsSorter usingsHelper, Dict
225
225
}
226
226
227
227
var indentation = IndentationHelper . GenerateIndentationString ( indentationSettings , indentationSteps ) ;
228
+ var withLeadingBlankLine = usingList [ 0 ] . Parent . IsKind ( SyntaxKindEx . FileScopedNamespaceDeclaration ) ;
228
229
229
- var modifiedUsings = usingsHelper . GenerateGroupedUsings ( usingList , indentation , false , qualifyNames ) ;
230
+ var modifiedUsings = usingsHelper . GenerateGroupedUsings ( usingList , indentation , withLeadingBlankLine , withTrailingBlankLine : false , qualifyNames ) ;
230
231
231
232
for ( var i = 0 ; i < usingList . Count ; i ++ )
232
233
{
@@ -254,7 +255,7 @@ private static void BuildReplaceMapForConditionalDirectives(UsingsSorter usingsH
254
255
255
256
var indentation = IndentationHelper . GenerateIndentationString ( indentationSettings , indentationSteps ) ;
256
257
257
- var modifiedUsings = usingsHelper . GenerateGroupedUsings ( childSpan , indentation , false , qualifyNames : false ) ;
258
+ var modifiedUsings = usingsHelper . GenerateGroupedUsings ( childSpan , indentation , false , false , qualifyNames : false ) ;
258
259
259
260
for ( var i = 0 ; i < originalUsings . Count ; i ++ )
260
261
{
@@ -274,9 +275,10 @@ private static int CompareSpanStart(UsingDirectiveSyntax left, UsingDirectiveSyn
274
275
private static SyntaxNode AddUsingsToNamespace ( SyntaxNode newSyntaxRoot , UsingsSorter usingsHelper , string usingsIndentation , bool hasConditionalDirectives )
275
276
{
276
277
var rootNamespace = ( BaseNamespaceDeclarationSyntaxWrapper ) ( ( CompilationUnitSyntax ) newSyntaxRoot ) . Members . First ( member => BaseNamespaceDeclarationSyntaxWrapper . IsInstance ( member ) ) ;
278
+ var withLeadingBlankLine = rootNamespace . SyntaxNode . IsKind ( SyntaxKindEx . FileScopedNamespaceDeclaration ) ;
277
279
var withTrailingBlankLine = hasConditionalDirectives || rootNamespace . Members . Any ( ) || rootNamespace . Externs . Any ( ) ;
278
280
279
- var groupedUsings = usingsHelper . GenerateGroupedUsings ( TreeTextSpan . Empty , usingsIndentation , withTrailingBlankLine , qualifyNames : false ) ;
281
+ var groupedUsings = usingsHelper . GenerateGroupedUsings ( TreeTextSpan . Empty , usingsIndentation , withLeadingBlankLine , withTrailingBlankLine , qualifyNames : false ) ;
280
282
groupedUsings = groupedUsings . AddRange ( rootNamespace . Usings ) ;
281
283
282
284
var newRootNamespace = rootNamespace . WithUsings ( groupedUsings ) ;
@@ -290,7 +292,7 @@ private static SyntaxNode AddUsingsToCompilationRoot(SyntaxNode newSyntaxRoot, U
290
292
var newCompilationUnit = ( CompilationUnitSyntax ) newSyntaxRoot ;
291
293
var withTrailingBlankLine = hasConditionalDirectives || newCompilationUnit . AttributeLists . Any ( ) || newCompilationUnit . Members . Any ( ) || newCompilationUnit . Externs . Any ( ) ;
292
294
293
- var groupedUsings = usingsHelper . GenerateGroupedUsings ( TreeTextSpan . Empty , usingsIndentation , withTrailingBlankLine , qualifyNames : true ) ;
295
+ var groupedUsings = usingsHelper . GenerateGroupedUsings ( TreeTextSpan . Empty , usingsIndentation , withLeadingBlankLine : false , withTrailingBlankLine , qualifyNames : true ) ;
294
296
groupedUsings = groupedUsings . AddRange ( newCompilationUnit . Usings ) ;
295
297
newSyntaxRoot = newCompilationUnit . WithUsings ( groupedUsings ) ;
296
298
0 commit comments