From d5400cb2e3ccc8a5c9bbdd79f1ab667d8e0fc720 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 18 Oct 2023 13:19:30 -0700 Subject: [PATCH] Improve comment of leading and trailing trivia on `SyntaxProtocol` --- Sources/SwiftSyntax/SyntaxProtocol.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/SwiftSyntax/SyntaxProtocol.swift b/Sources/SwiftSyntax/SyntaxProtocol.swift index 2be9d451a25..286c7382edd 100644 --- a/Sources/SwiftSyntax/SyntaxProtocol.swift +++ b/Sources/SwiftSyntax/SyntaxProtocol.swift @@ -463,11 +463,12 @@ public extension SyntaxProtocol { // MARK: Trivia public extension SyntaxProtocol { - /// The leading trivia of this syntax node. Leading trivia is attached to - /// the first token syntax contained by this node. Without such token, this - /// property will return nil. + /// The leading trivia of this syntax node. /// - /// Note: ``Trivia`` is not able to represent invalid UTF-8 sequences. To get + /// Trivia is always attached to tokens, not to layout nodes. This will return the leading trivia of the first token + /// within the subtree. If no such token exists, this returns empty trivia. + /// + /// - Note: ``Trivia`` is not able to represent invalid UTF-8 sequences. To get /// the leading trivia text including all invalid UTF-8 sequences, use /// ``` /// node.syntaxTextBytes.prefix(self.leadingTriviaLength.utf8Length) @@ -481,9 +482,10 @@ public extension SyntaxProtocol { } } - /// The trailing trivia of this syntax node. Trailing trivia is attached to - /// the last token syntax contained by this node. Without such token, this - /// property will return nil. + /// The trailing trivia of this syntax node. + /// + /// Trivia is always attached to tokens, not to layout nodes. This will return the trailing trivia of the last token + /// within the subtree. If no such token exists, this returns empty trivia. /// /// Note: ``Trivia`` is not able to represent invalid UTF-8 sequences. To get /// the leading trivia text including all invalid UTF-8 sequences, use