Skip to content

Commit 719f287

Browse files
committed
Deprecate token accessors that don’t specify the syntax tree view mode
I know that it’s really verbose but I would like to be explicit about the view mode be explicit about the view mode because different clients will have different needs and we shouldn’t be assuming that one of the view modes is superior to the other.
1 parent 66d387d commit 719f287

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

CodeGeneration/Sources/generate-swiftsyntax/templates/basicformat/BasicFormatFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let basicFormatFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
6666
indentationLevel += 1
6767
}
6868
if let parent = node.parent, childrenSeparatedByNewline(parent) {
69-
putNextTokenOnNewLine = true && node.previousToken != nil
69+
putNextTokenOnNewLine = true && node.previousToken(viewMode: .sourceAccurate) != nil
7070
}
7171
}
7272
"""

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ open class BasicFormat: SyntaxRewriter {
3434
indentationLevel += 1
3535
}
3636
if let parent = node.parent, childrenSeparatedByNewline(parent) {
37-
putNextTokenOnNewLine = true && node.previousToken != nil
37+
putNextTokenOnNewLine = true && node.previousToken(viewMode: .sourceAccurate) != nil
3838
}
3939
}
4040

Sources/SwiftSyntax/Syntax.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ public extension SyntaxProtocol {
286286
return childrenKeyPaths[data.indexInParent]
287287
}
288288

289-
/// Recursively walks through the tree to find the token semantically before
290-
/// this node.
289+
@available(*, deprecated, message: "Use previousToken(viewMode:) instead")
291290
var previousToken: TokenSyntax? {
292291
return self.previousToken(viewMode: .sourceAccurate)
293292
}
@@ -312,8 +311,7 @@ public extension SyntaxProtocol {
312311
return parent.previousToken(viewMode: viewMode)
313312
}
314313

315-
/// Recursively walks through the tree to find the next token semantically
316-
/// after this node.
314+
@available(*, deprecated, message: "Use nextToken(viewMode:) instead")
317315
var nextToken: TokenSyntax? {
318316
return self.nextToken(viewMode: .sourceAccurate)
319317
}
@@ -335,8 +333,7 @@ public extension SyntaxProtocol {
335333
return parent.nextToken(viewMode: viewMode)
336334
}
337335

338-
/// Returns the first token in this syntax node in the source accurate view of
339-
/// the syntax tree.
336+
@available(*, deprecated, message: "Use firstToken(viewMode: .sourceAccurate) instead")
340337
var firstToken: TokenSyntax? {
341338
return self.firstToken(viewMode: .sourceAccurate)
342339
}
@@ -356,7 +353,7 @@ public extension SyntaxProtocol {
356353
return nil
357354
}
358355

359-
/// Returns the last token node that is part of this syntax node.
356+
@available(*, deprecated, message: "Use lastToken(viewMode: .sourceAccurate) instead")
360357
var lastToken: TokenSyntax? {
361358
return self.lastToken(viewMode: .sourceAccurate)
362359
}

0 commit comments

Comments
 (0)