Skip to content

Commit 0c41fe6

Browse files
authored
Merge pull request #1912 from ahoppen/ahoppen/syntaxprotocol-api
Audit public API on `SyntaxProtocol`
2 parents 9449d61 + 0edd761 commit 0c41fe6

File tree

11 files changed

+166
-115
lines changed

11 files changed

+166
-115
lines changed

Sources/SwiftIDEUtils/Syntax+Classifications.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public extension SyntaxProtocol {
2121
/// consecutive tokens would have the same classification then a single classified
2222
/// range is provided for all of them.
2323
var classifications: SyntaxClassifications {
24-
let fullRange = ByteSourceRange(offset: 0, length: byteSize)
24+
let fullRange = ByteSourceRange(offset: 0, length: totalLength.utf8Length)
2525
return SyntaxClassifications(_syntaxNode, in: fullRange)
2626
}
2727

Sources/SwiftParser/IncrementalParseTransition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension Parser {
2020

2121
let currentOffset = self.lexemes.offsetToStart(self.currentToken)
2222
if let node = parseLookup!.lookUp(currentOffset, kind: kind) {
23-
self.lexemes.advance(by: node.byteSize, currentToken: &self.currentToken)
23+
self.lexemes.advance(by: node.totalLength.utf8Length, currentToken: &self.currentToken)
2424
return node
2525
}
2626

Sources/SwiftParserDiagnostics/MissingTokenError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ extension ParseDiagnosticsGenerator {
136136
missingToken: TokenSyntax,
137137
invalidTokenContainer: UnexpectedNodesSyntax
138138
) -> Bool {
139-
let isTooMany = invalidToken.contentLength > missingToken.contentLength
139+
let isTooMany = invalidToken.trimmedLength > missingToken.trimmedLength
140140
let message: DiagnosticMessage
141141
if missingToken.parent?.is(ExpressionSegmentSyntax.self) == true {
142142
message = .tooManyRawStringDelimitersToStartInterpolation
@@ -157,7 +157,7 @@ extension ParseDiagnosticsGenerator {
157157
)
158158
addDiagnostic(
159159
invalidToken,
160-
position: invalidToken.positionAfterSkippingLeadingTrivia.advanced(by: missingToken.contentLength.utf8Length),
160+
position: invalidToken.positionAfterSkippingLeadingTrivia.advanced(by: missingToken.trimmedLength.utf8Length),
161161
message,
162162
fixIts: [fixIt],
163163
handledNodes: [invalidTokenContainer.id]

Sources/SwiftSyntax/Raw/RawSyntax.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ extension RawSyntax {
508508
/// The length of this node’s content, without the first leading and the last
509509
/// trailing trivia. Intermediate trivia inside a layout node is included in
510510
/// this.
511-
var contentByteLength: Int {
511+
var trimmedByteLength: Int {
512512
let result = byteLength - leadingTriviaByteLength - trailingTriviaByteLength
513513
precondition(result >= 0)
514514
return result
@@ -523,8 +523,8 @@ extension RawSyntax {
523523
}
524524

525525
/// The length of this node excluding its leading and trailing trivia.
526-
var contentLength: SourceLength {
527-
SourceLength(utf8Length: contentByteLength)
526+
var trimmedLength: SourceLength {
527+
SourceLength(utf8Length: trimmedByteLength)
528528
}
529529
}
530530

Sources/SwiftSyntax/Raw/RawSyntaxTokenView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public struct RawSyntaxTokenView {
229229
}
230230

231231
@_spi(RawSyntax)
232-
public var contentLength: SourceLength {
232+
public var trimmedLength: SourceLength {
233233
SourceLength(utf8Length: textByteLength)
234234
}
235235

Sources/SwiftSyntax/SourceLocation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public final class SourceLocationConverter {
192192
self.file = file
193193
self.source = tree.syntaxTextBytes
194194
(self.lines, endOfFile) = computeLines(tree: Syntax(tree))
195-
precondition(tree.byteSize == endOfFile.utf8Offset)
195+
precondition(tree.totalLength.utf8Length == endOfFile.utf8Offset)
196196

197197
for directive in SourceLocationCollector.collectSourceLocations(in: tree) {
198198
let location = self.physicalLocation(for: directive.positionAfterSkippingLeadingTrivia)
@@ -400,7 +400,7 @@ public extension Syntax {
400400
) -> SourceLocation {
401401
var pos = data.position
402402
pos += raw.leadingTriviaLength
403-
pos += raw.contentLength
403+
pos += raw.trimmedLength
404404
if afterTrailingTrivia {
405405
pos += raw.trailingTriviaLength
406406
}

0 commit comments

Comments
 (0)