Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add 601

]

steps:
Expand Down
8 changes: 4 additions & 4 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support 601

),
],
targets: [
Expand Down
23 changes: 16 additions & 7 deletions Sources/MacroTesting/AssertMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Author

Choose a reason for hiding this comment

The 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)
Expand All @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The 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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/MacroTestingTests/MacroExamples/AddAsyncMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public struct AddAsyncMacro: PeerMacro {
let isResultReturn = returnType?.children(viewMode: .all).first?.description == "Result"
let successReturnType =
isResultReturn
? returnType!.as(IdentifierTypeSyntax.self)!.genericArgumentClause?.arguments.first!.argument
? returnType!.as(IdentifierTypeSyntax.self)!.genericArgumentClause?.arguments.first!.argumentCompat600
: returnType

// Remove completionHandler and comma from the previous parameter
Expand Down
2 changes: 1 addition & 1 deletion Tests/MacroTestingTests/MacroExamples/OptionSetMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public struct OptionSetMacro {
guard
let genericArgs = attribute.attributeName.as(IdentifierTypeSyntax.self)?
.genericArgumentClause,
let rawType = genericArgs.arguments.first?.argument
let rawType = genericArgs.arguments.first?.argumentCompat600
else {
context.diagnose(OptionSetMacroDiagnostic.requiresOptionsEnumRawType.diagnose(at: attribute))
return nil
Expand Down
11 changes: 11 additions & 0 deletions Tests/MacroTestingTests/SwiftSyntaxCompatibilityHelpers.swift
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
}
}