Skip to content

Audit public API on SyntaxProtocol #1912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftIDEUtils/Syntax+Classifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public extension SyntaxProtocol {
/// consecutive tokens would have the same classification then a single classified
/// range is provided for all of them.
var classifications: SyntaxClassifications {
let fullRange = ByteSourceRange(offset: 0, length: byteSize)
let fullRange = ByteSourceRange(offset: 0, length: totalLength.utf8Length)
return SyntaxClassifications(_syntaxNode, in: fullRange)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/IncrementalParseTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension Parser {

let currentOffset = self.lexemes.offsetToStart(self.currentToken)
if let node = parseLookup!.lookUp(currentOffset, kind: kind) {
self.lexemes.advance(by: node.byteSize, currentToken: &self.currentToken)
self.lexemes.advance(by: node.totalLength.utf8Length, currentToken: &self.currentToken)
return node
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftParserDiagnostics/MissingTokenError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ extension ParseDiagnosticsGenerator {
missingToken: TokenSyntax,
invalidTokenContainer: UnexpectedNodesSyntax
) -> Bool {
let isTooMany = invalidToken.contentLength > missingToken.contentLength
let isTooMany = invalidToken.trimmedLength > missingToken.trimmedLength
let message: DiagnosticMessage
if missingToken.parent?.is(ExpressionSegmentSyntax.self) == true {
message = .tooManyRawStringDelimitersToStartInterpolation
Expand All @@ -157,7 +157,7 @@ extension ParseDiagnosticsGenerator {
)
addDiagnostic(
invalidToken,
position: invalidToken.positionAfterSkippingLeadingTrivia.advanced(by: missingToken.contentLength.utf8Length),
position: invalidToken.positionAfterSkippingLeadingTrivia.advanced(by: missingToken.trimmedLength.utf8Length),
message,
fixIts: [fixIt],
handledNodes: [invalidTokenContainer.id]
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftSyntax/Raw/RawSyntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ extension RawSyntax {
/// The length of this node’s content, without the first leading and the last
/// trailing trivia. Intermediate trivia inside a layout node is included in
/// this.
var contentByteLength: Int {
var trimmedByteLength: Int {
let result = byteLength - leadingTriviaByteLength - trailingTriviaByteLength
precondition(result >= 0)
return result
Expand All @@ -523,8 +523,8 @@ extension RawSyntax {
}

/// The length of this node excluding its leading and trailing trivia.
var contentLength: SourceLength {
SourceLength(utf8Length: contentByteLength)
var trimmedLength: SourceLength {
SourceLength(utf8Length: trimmedByteLength)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntax/Raw/RawSyntaxTokenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public struct RawSyntaxTokenView {
}

@_spi(RawSyntax)
public var contentLength: SourceLength {
public var trimmedLength: SourceLength {
SourceLength(utf8Length: textByteLength)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSyntax/SourceLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public final class SourceLocationConverter {
self.file = file
self.source = tree.syntaxTextBytes
(self.lines, endOfFile) = computeLines(tree: Syntax(tree))
precondition(tree.byteSize == endOfFile.utf8Offset)
precondition(tree.totalLength.utf8Length == endOfFile.utf8Offset)

for directive in SourceLocationCollector.collectSourceLocations(in: tree) {
let location = self.physicalLocation(for: directive.positionAfterSkippingLeadingTrivia)
Expand Down Expand Up @@ -400,7 +400,7 @@ public extension Syntax {
) -> SourceLocation {
var pos = data.position
pos += raw.leadingTriviaLength
pos += raw.contentLength
pos += raw.trimmedLength
if afterTrailingTrivia {
pos += raw.trailingTriviaLength
}
Expand Down
Loading