-
Notifications
You must be signed in to change notification settings - Fork 17
Support SwiftSyntax 601 #50
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ jobs: | |
"509.0.0..<510.0.0", | ||
"510.0.0..<511.0.0", | ||
"511.0.0..<601.0.0", | ||
"601.0.0..<602.0.0", | ||
] | ||
|
||
steps: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ let package = Package( | |
.conditionalPackage( | ||
url: "https://github.com/swiftlang/swift-syntax", | ||
envVar: "SWIFT_SYNTAX_VERSION", | ||
default: "509.0.0..<601.0.0" | ||
default: "509.0.0..<602.0.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. support 601 |
||
), | ||
], | ||
targets: [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -549,14 +549,14 @@ public func assertMacro( | |
} | ||
} | ||
|
||
// From: https://github.com/apple/swift-syntax/blob/d647052/Sources/SwiftSyntaxMacrosTestSupport/Assertions.swift | ||
extension FixIt.Change { | ||
// From: https://github.com/swiftlang/swift-syntax/blob/601.0.1/Sources/SwiftSyntaxMacrosGenericTestSupport/Assertions.swift | ||
fileprivate extension FixIt.Change { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copy-pasted the latest code and made some small adjustments. |
||
/// Returns the edit for this change, translating positions from detached nodes | ||
/// to the corresponding locations in the original source file based on | ||
/// `expansionContext`. | ||
/// | ||
/// - SeeAlso: `FixIt.Change.edit` | ||
fileprivate func edit(in expansionContext: BasicMacroExpansionContext) -> SourceEdit { | ||
func edit(in expansionContext: BasicMacroExpansionContext) -> SourceEdit { | ||
switch self { | ||
case .replace(let oldNode, let newNode): | ||
let start = expansionContext.position(of: oldNode.position, anchoredAt: oldNode) | ||
|
@@ -568,21 +568,30 @@ extension FixIt.Change { | |
|
||
case .replaceLeadingTrivia(let token, let newTrivia): | ||
let start = expansionContext.position(of: token.position, anchoredAt: token) | ||
let end = expansionContext.position( | ||
of: token.positionAfterSkippingLeadingTrivia, anchoredAt: token) | ||
let end = expansionContext.position(of: token.positionAfterSkippingLeadingTrivia, anchoredAt: token) | ||
return SourceEdit( | ||
range: start..<end, | ||
replacement: newTrivia.description | ||
) | ||
|
||
case .replaceTrailingTrivia(let token, let newTrivia): | ||
let start = expansionContext.position( | ||
of: token.endPositionBeforeTrailingTrivia, anchoredAt: token) | ||
let start = expansionContext.position(of: token.endPositionBeforeTrailingTrivia, anchoredAt: token) | ||
let end = expansionContext.position(of: token.endPosition, anchoredAt: token) | ||
return SourceEdit( | ||
range: start..<end, | ||
replacement: newTrivia.description | ||
) | ||
|
||
#if canImport(SwiftSyntax601) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this compile-time conditional. |
||
case .replaceChild(let replacingChildData): | ||
let range = replacingChildData.replacementRange | ||
let start = expansionContext.position(of: range.lowerBound, anchoredAt: replacingChildData.parent) | ||
let end = expansionContext.position(of: range.upperBound, anchoredAt: replacingChildData.parent) | ||
return SourceEdit( | ||
range: start..<end, | ||
replacement: replacingChildData.newChild.description | ||
) | ||
#endif | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import SwiftSyntax | ||
|
||
extension GenericArgumentSyntax { | ||
var argumentCompat600: TypeSyntax? { | ||
#if canImport(SwiftSyntax601) | ||
argument.as(TypeSyntax.self) | ||
#else | ||
argument | ||
#endif | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add 601