Closed tayloraswift closed 3 months ago
This behaves as intended. Running trimmed
modifies the syntax tree to remove the leading and trailing trivia of the first and last token, respectively. The trimmed node should probably be detached from the original tree, which would make the behavior more obvious.
I would suggest that you do something like the following
let trimmed = function.modifiers.detached.trimmed
let trimmedBytes = trimmed.syntaxTextBytes
for span in trimmed.classifications {
let range = span.range.offset ..< span.range.offset + span.range.length
print(String.init(decoding: syntaxTextBytes[range], as: Unicode.UTF8.self))
}
Description
using the
trimmed
family ofSyntaxProtocol
methods corrupts theByteSourceRange
s when obtaining syntax classifications.i was able to reproduce this on
510.0.2
, and on600.0.0-prerelease-2024-06-12
.Steps to Reproduce