From fe6ab435c338d596458691dd3532a9aef71d9d89 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Tue, 4 Apr 2023 10:44:41 -0700 Subject: [PATCH] Document that `Trivia` cannot represent invalid UTF-8 --- Sources/SwiftSyntax/Syntax.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/SwiftSyntax/Syntax.swift b/Sources/SwiftSyntax/Syntax.swift index c648c486228..3b90ca08be8 100644 --- a/Sources/SwiftSyntax/Syntax.swift +++ b/Sources/SwiftSyntax/Syntax.swift @@ -471,6 +471,12 @@ 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. + /// + /// 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) + /// ``` var leadingTrivia: Trivia { get { return raw.formLeadingTrivia() @@ -483,6 +489,12 @@ 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. + /// + /// 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[(node.byteSize - node.trailingTriviaLength.utf8Length)...] + /// ``` var trailingTrivia: Trivia { get { return raw.formTrailingTrivia()