1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System ;
4
5
using System . Collections . Generic ;
5
6
using System . Diagnostics ;
6
- using System ;
7
7
using System . Diagnostics . CodeAnalysis ;
8
8
using System . Linq ;
9
- using System . Reflection . Emit ;
10
9
using ApiDocsSync . PortToTripleSlash . Docs ;
11
10
using Microsoft . CodeAnalysis ;
12
11
using Microsoft . CodeAnalysis . CSharp ;
13
12
using Microsoft . CodeAnalysis . CSharp . Syntax ;
14
- using Microsoft . CodeAnalysis . Editing ;
15
- using System . Reflection . Metadata ;
16
- using System . Xml ;
17
- using System . Xml . Linq ;
18
- using System . Collections ;
19
- using System . Security . Policy ;
20
13
21
14
/*
22
15
* According to the Roslyn Quoter: https://roslynquoter.azurewebsites.net/
@@ -328,17 +321,10 @@ private bool TryGetType(SyntaxNode originalNode, [NotNullWhen(returnValue: true)
328
321
return type != null ;
329
322
}
330
323
331
- private static bool IsPublic ( [ NotNullWhen ( returnValue : true ) ] SyntaxNode ? node )
332
- {
333
- if ( node == null ||
334
- node is not MemberDeclarationSyntax baseNode ||
335
- ! baseNode . Modifiers . Any ( t => t . IsKind ( SyntaxKind . PublicKeyword ) ) )
336
- {
337
- return false ;
338
- }
339
-
340
- return true ;
341
- }
324
+ private static bool IsPublic ( [ NotNullWhen ( returnValue : true ) ] SyntaxNode ? node ) =>
325
+ node != null &&
326
+ node is MemberDeclarationSyntax baseNode &&
327
+ baseNode . Modifiers . Any ( t => t . IsKind ( SyntaxKind . PublicKeyword ) ) ;
342
328
343
329
public SyntaxNode Generate ( SyntaxNode node , IDocsAPI api )
344
330
{
@@ -358,9 +344,22 @@ public SyntaxNode Generate(SyntaxNode node, IDocsAPI api)
358
344
break ;
359
345
}
360
346
347
+ if ( originalTrivia . IsKind ( SyntaxKind . WhitespaceTrivia ) )
348
+ {
349
+ // Avoid re-adding existing whitespace trivia, it will always be added later
350
+ continue ;
351
+ }
352
+
361
353
if ( ! originalTrivia . HasStructure )
362
354
{
355
+ // Double slash comments do not have a structure but must be preserved with the original indentation
356
+ // Only add indentation if the current trivia is not a new line
357
+ if ( ( SyntaxKind ) originalTrivia . RawKind != SyntaxKind . EndOfLineTrivia && indentationTrivia . HasValue )
358
+ {
359
+ updatedLeadingTrivia . Add ( indentationTrivia . Value ) ;
360
+ }
363
361
updatedLeadingTrivia . Add ( originalTrivia ) ;
362
+
364
363
continue ;
365
364
}
366
365
@@ -369,6 +368,11 @@ public SyntaxNode Generate(SyntaxNode node, IDocsAPI api)
369
368
370
369
if ( ! structuredTrivia . IsKind ( SyntaxKind . SingleLineDocumentationCommentTrivia ) )
371
370
{
371
+ // Unsure if there are other structured comments, but must preserve them with the original indentation
372
+ if ( indentationTrivia . HasValue )
373
+ {
374
+ updatedLeadingTrivia . Add ( indentationTrivia . Value ) ;
375
+ }
372
376
updatedLeadingTrivia . Add ( originalTrivia ) ;
373
377
continue ;
374
378
}
@@ -396,7 +400,7 @@ public SyntaxNode Generate(SyntaxNode node, IDocsAPI api)
396
400
397
401
// The last trivia is the spacing before the actual node (usually before the visibility keyword)
398
402
// must be replaced in its original location
399
- if ( indentationTrivia != null )
403
+ if ( indentationTrivia . HasValue )
400
404
{
401
405
updatedLeadingTrivia . Add ( indentationTrivia . Value ) ;
402
406
}
0 commit comments