diff --git a/Package.swift b/Package.swift index 54f7cdd05f9..060924b1ee0 100644 --- a/Package.swift +++ b/Package.swift @@ -250,12 +250,12 @@ let package = Package( .target( name: "SwiftRefactor", - dependencies: ["SwiftParser", "SwiftSyntax"] + dependencies: ["SwiftBasicFormat", "SwiftParser", "SwiftSyntax", "SwiftSyntaxBuilder"] ), .testTarget( name: "SwiftRefactorTest", - dependencies: ["_SwiftSyntaxTestSupport", "SwiftRefactor", "SwiftSyntaxBuilder"] + dependencies: ["_SwiftSyntaxTestSupport", "SwiftRefactor"] ), // MARK: - Executable targets diff --git a/Sources/SwiftBasicFormat/BasicFormat.swift b/Sources/SwiftBasicFormat/BasicFormat.swift index 9ebc31edf0a..aed7bda76a2 100644 --- a/Sources/SwiftBasicFormat/BasicFormat.swift +++ b/Sources/SwiftBasicFormat/BasicFormat.swift @@ -213,7 +213,7 @@ open class BasicFormat: SyntaxRewriter { (.keyword(.set), .leftParen), // var mYar: Int { set(value) {} } (.keyword(.subscript), .leftParen), // subscript(x: Int) (.keyword(.super), .period), // super.someProperty - (.leftBrace, _), + (.leftBrace, .rightBrace), // {} (.leftParen, _), (.leftSquare, _), (.multilineStringQuote, .rawStringDelimiter), // closing raw string delimiter should never be separate by a space @@ -245,7 +245,6 @@ open class BasicFormat: SyntaxRewriter { (_, .exclamationMark), (_, .postfixOperator), (_, .postfixQuestionMark), - (_, .rightBrace), (_, .rightParen), (_, .rightSquare), (_, .semicolon), diff --git a/Sources/SwiftRefactor/AddSeparatorsToIntegerLiteral.swift b/Sources/SwiftRefactor/AddSeparatorsToIntegerLiteral.swift index 77f38b6865d..a2f1cf39b26 100644 --- a/Sources/SwiftRefactor/AddSeparatorsToIntegerLiteral.swift +++ b/Sources/SwiftRefactor/AddSeparatorsToIntegerLiteral.swift @@ -32,7 +32,7 @@ import SwiftSyntax /// 0xF_FFFF_FFFF /// 0b1_010 /// ``` -public struct AddSeparatorsToIntegerLiteral: RefactoringProvider { +public struct AddSeparatorsToIntegerLiteral: SyntaxRefactoringProvider { public static func refactor(syntax lit: IntegerLiteralExprSyntax, in context: Void) -> IntegerLiteralExprSyntax? { if lit.digits.text.contains("_") { guard let strippedLiteral = RemoveSeparatorsFromIntegerLiteral.refactor(syntax: lit) else { diff --git a/Sources/SwiftRefactor/CallToTrailingClosures.swift b/Sources/SwiftRefactor/CallToTrailingClosures.swift new file mode 100644 index 00000000000..2d5cf49b51d --- /dev/null +++ b/Sources/SwiftRefactor/CallToTrailingClosures.swift @@ -0,0 +1,149 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftBasicFormat +import SwiftSyntax + +/// Convert a call with inline closures to one that uses trailing closure +/// syntax. Returns `nil` if there's already trailing closures or there are no +/// closures within the call. Pass `startAtArgument` to specify the argument +/// index to start the conversion from, ie. to skip converting closures before +/// `startAtArgument`. +/// +/// ## Before +/// ``` +/// someCall(closure1: { arg in +/// return 1 +/// }, closure2: { arg in +/// return 2 +/// }) +/// ``` +/// +/// ## After +/// ``` +/// someCall { arg in +/// return 1 +/// } closure2: { arg in +/// return 2 +/// } +/// ``` +public struct CallToTrailingClosures: SyntaxRefactoringProvider { + public struct Context { + public let startAtArgument: Int + + public init(startAtArgument: Int = 0) { + self.startAtArgument = startAtArgument + } + } + + // TODO: Rather than returning nil, we should consider throwing errors with + // appropriate messages instead. + public static func refactor(syntax call: FunctionCallExprSyntax, in context: Context = Context()) -> FunctionCallExprSyntax? { + return call.convertToTrailingClosures(from: context.startAtArgument)?.formatted().as(FunctionCallExprSyntax.self) + } +} + +extension FunctionCallExprSyntax { + fileprivate func convertToTrailingClosures(from startAtArgument: Int) -> FunctionCallExprSyntax? { + guard trailingClosure == nil, additionalTrailingClosures == nil, leftParen != nil, rightParen != nil else { + // Already have trailing closures + return nil + } + + var closures = [(original: TupleExprElementSyntax, closure: ClosureExprSyntax)]() + for arg in argumentList.dropFirst(startAtArgument) { + guard var closure = arg.expression.as(ClosureExprSyntax.self) else { + closures.removeAll() + continue + } + + // Trailing comma won't exist any more, move its trivia to the end of + // the closure instead + if let comma = arg.trailingComma { + closure = closure.with(\.trailingTrivia, closure.trailingTrivia.merging(triviaOf: comma)) + } + closures.append((arg, closure)) + } + + guard !closures.isEmpty else { + return nil + } + + // First trailing closure won't have label/colon. Transfer their trivia. + var trailingClosure = closures.first!.closure + .with( + \.leadingTrivia, + Trivia() + .merging(triviaOf: closures.first!.original.label) + .merging(triviaOf: closures.first!.original.colon) + .merging(closures.first!.closure.leadingTrivia) + ) + let additionalTrailingClosures = closures.dropFirst().map { + MultipleTrailingClosureElementSyntax( + label: $0.original.label ?? .wildcardToken(), + colon: $0.original.colon ?? .colonToken(), + closure: $0.closure + ) + } + + var converted = self.detach() + + // Remove parens if there's no non-closure arguments left and remove the + // last comma otherwise. Makes sure to keep the trivia of any removed node. + var argList = Array(argumentList.dropLast(closures.count)) + if argList.isEmpty { + converted = + converted + .with(\.leftParen, nil) + .with(\.rightParen, nil) + + // No left paren any more, right paren is handled below since it makes + // sense to keep its trivia of the end of the call, regardless of whether + // it was removed or not. + if let leftParen = leftParen { + trailingClosure = trailingClosure.with( + \.leadingTrivia, + Trivia() + .merging(triviaOf: leftParen) + .merging(trailingClosure.leadingTrivia) + ) + } + } else { + let last = argList.last! + if let comma = last.trailingComma { + converted = + converted + .with(\.rightParen, TokenSyntax.rightParenToken(trailingTrivia: Trivia().merging(triviaOf: comma))) + } + argList[argList.count - 1] = + last + .with(\.trailingComma, nil) + } + + // Update arguments and trailing closures + converted = + converted + .with(\.argumentList, TupleExprElementListSyntax(argList)) + .with(\.trailingClosure, trailingClosure) + if !additionalTrailingClosures.isEmpty { + converted = converted.with(\.additionalTrailingClosures, MultipleTrailingClosureElementListSyntax(additionalTrailingClosures)) + } + + // The right paren either doesn't exist any more, or is before all the + // trailing closures. Moves its trivia to the end of the converted call. + if let rightParen = rightParen { + converted = converted.with(\.trailingTrivia, converted.trailingTrivia.merging(triviaOf: rightParen)) + } + + return converted + } +} diff --git a/Sources/SwiftRefactor/ExpandEditorPlaceholder.swift b/Sources/SwiftRefactor/ExpandEditorPlaceholder.swift new file mode 100644 index 00000000000..372e8edf30c --- /dev/null +++ b/Sources/SwiftRefactor/ExpandEditorPlaceholder.swift @@ -0,0 +1,359 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftBasicFormat +import SwiftParser +import SwiftSyntax +import SwiftSyntaxBuilder + +/// Expands an editor placeholder, taking into accounts its provided type +/// information (if any). +/// +/// Placeholders must start with '<#' and end with +/// '#>'. They can be one of the following formats: +/// ``` +/// 'T##' display-string '##' type-string ('##' type-for-expansion-string)? +/// 'T##' display-and-type-string +/// display-string +/// ``` +/// It is required that '##' is not a valid substring of display-string or +/// type-string. If this ends up not the case for some reason, we can consider +/// adding escaping for '##'. +/// +/// The type string provided in the placeholder (preferring +/// `type-for-expansion-string`), is parsed into a syntax node. If that node is +/// a `FunctionTypeSyntax` then the placeholder is expanded into a +/// `ClosureExprSyntax`. Otherwise it is expanded as is, which is also the case +/// for when only a display string is provided. +/// +/// ## Function Typed Placeholder +/// ### Before +/// ```swift +/// <#T##(Int) -> String##(Int) -> String##(_ someInt: Int) -> String#> +/// ``` +/// +/// ### After +/// ```swift +/// { someInt in +/// <#T##String#> +/// } +/// ``` +/// +/// ## Other Type Placeholder +/// ### Before +/// ```swift +/// <#T##Int#> +/// ``` +/// +/// ### After +/// ```swift +/// Int +/// ``` +/// +/// ## No Type Placeholder +/// ### Before +/// ```swift +/// <#anything here#> +/// ``` +/// +/// ## After +/// ```swift +/// anything here +/// ``` +public struct ExpandEditorPlaceholder: EditRefactoringProvider { + public static func isPlaceholder(_ str: String) -> Bool { + return str.hasPrefix(placeholderStart) && str.hasSuffix(placeholderEnd) + } + + public static func wrapInPlaceholder(_ str: String) -> String { + return placeholderStart + str + placeholderEnd + } + + public static func wrapInTypePlaceholder(_ str: String, type: String) -> String { + return Self.wrapInPlaceholder("T##" + str + "##" + type) + } + + public static func textRefactor(syntax token: TokenSyntax, in context: Void) -> [SourceEdit] { + guard let placeholder = EditorPlaceholderData(token: token) else { + return [] + } + + let expanded: String + switch placeholder { + case let .basic(text): + expanded = String(text) + case let .typed(text, type): + if let functionType = type.as(FunctionTypeSyntax.self) { + expanded = functionType.closureExpansion.formatted().description + } else { + expanded = String(text) + } + } + + return [SourceEdit.replace(token, with: token.leadingTrivia.description + expanded + token.trailingTrivia.description)] + } +} + +/// If a function-typed placeholder is the argument to a non-trailing closure +/// call, expands it and any adjacent function-typed placeholders to trailing +/// closures on that call. All other placeholders will expand as per +/// `ExpandEditorPlaceholder`. +/// +/// ## Before +/// ```swift +/// foo( +/// closure1: <#T##(Int) -> String##(Int) -> String##(_ someInt: Int) -> String#>, +/// normalArg: <#T##Int#>, +/// closure2: { ... }, +/// closure3: <#T##(Int) -> String##(Int) -> String##(_ someInt: Int) -> String#>, +/// closure4: <#T##(Int) -> String##(Int) -> String##(_ someInt: Int) -> String#> +/// ) +/// ``` +/// +/// ## `closure3` or `closure4` Expansion +/// ```swift +/// foo( +/// closure1: <#T##(Int) -> String##(Int) -> String##(_ someInt: Int) -> String#>, +/// normalArg: <#T##Int#>, +/// closure2: { ... } +/// ) { someInt in +/// <#T##String#> +/// } closure2: { someInt in +/// <#T##String#> +/// } +/// ``` +/// +/// Expansion on `closure1` and `normalArg` is the same as `ExpandEditorPlaceholder`. +public struct ExpandEditorPlaceholders: EditRefactoringProvider { + public static func textRefactor(syntax token: TokenSyntax, in context: Void) -> [SourceEdit] { + guard let placeholder = token.parent?.as(EditorPlaceholderExprSyntax.self), + let arg = placeholder.parent?.as(TupleExprElementSyntax.self), + let argList = arg.parent?.as(TupleExprElementListSyntax.self), + let call = argList.parent?.as(FunctionCallExprSyntax.self) + else { + return ExpandEditorPlaceholder.textRefactor(syntax: token) + } + + guard let expanded = call.expandTrailingClosurePlaceholders(ifIncluded: arg) else { + return ExpandEditorPlaceholder.textRefactor(syntax: token) + } + + let callToTrailingContext = CallToTrailingClosures.Context(startAtArgument: argList.count - expanded.numClosures) + guard let trailing = CallToTrailingClosures.refactor(syntax: expanded.expr, in: callToTrailingContext) else { + return ExpandEditorPlaceholder.textRefactor(syntax: token) + } + + return [SourceEdit.replace(call, with: trailing.description)] + } +} + +extension FunctionTypeSyntax { + /// Return a closure expression for this function type, eg. + /// ``` + /// (_ someInt: Int) -> String + /// ``` + /// would become + /// ``` + /// { someInt in + /// <#T##String#> + /// } + /// ``` + fileprivate var closureExpansion: ClosureExprSyntax { + let closureSignature: ClosureSignatureSyntax? + if !arguments.isEmpty { + let args = ClosureParamListSyntax { + for arg in arguments { + ClosureParamSyntax(name: arg.expansionNameToken()) + } + } + closureSignature = ClosureSignatureSyntax(input: .simpleInput(args)) + } else { + closureSignature = nil + } + + // Single statement for the body - the placeholder-ed type if non-void and + // 'code' otherwise. + let ret = output.returnType.description + let placeholder: String + if ret == "Void" || ret == "()" { + placeholder = ExpandEditorPlaceholder.wrapInTypePlaceholder("code", type: "Void") + } else { + placeholder = ExpandEditorPlaceholder.wrapInTypePlaceholder(ret, type: ret) + } + + let statementPlaceholder = EditorPlaceholderExprSyntax( + identifier: .identifier(placeholder) + ) + let closureStatement = CodeBlockItemSyntax( + item: .expr(ExprSyntax(statementPlaceholder)) + ) + + return ClosureExprSyntax( + leftBrace: .leftBraceToken(), + signature: closureSignature, + statements: CodeBlockItemListSyntax([closureStatement]), + rightBrace: .rightBraceToken() + ) + } +} + +extension TupleTypeElementSyntax { + /// Return a token to use as the parameter name in the expanded closure. + /// We prefer the argument name if there is one and it isn't a wildcard, + /// falling back to the label with the same conditions, and finally just the + /// placeholder-ed type otherwise. + fileprivate func expansionNameToken() -> TokenSyntax { + if let secondName = secondName, secondName.tokenKind != .wildcard { + return secondName + } + + if let name = name, name.tokenKind != .wildcard { + return name + } + + return .identifier(ExpandEditorPlaceholder.wrapInPlaceholder(type.description)) + } +} + +extension FunctionCallExprSyntax { + /// If the given argument is one of the last arguments that are all + /// function-typed placeholders and this call doesn't have a trailing + /// closure, then return a replacement of this call with one that uses + /// closures based on the function types provided by each editor placeholder. + /// Otherwise return nil. + fileprivate func expandTrailingClosurePlaceholders(ifIncluded: TupleExprElementSyntax) -> (expr: FunctionCallExprSyntax, numClosures: Int)? { + var includedArg = false + var argsToExpand = 0 + for arg in argumentList.reversed() { + guard let expr = arg.expression.as(EditorPlaceholderExprSyntax.self), + let data = EditorPlaceholderData(token: expr.identifier), + case let .typed(_, type) = data, + type.is(FunctionTypeSyntax.self) + else { + break + } + if arg == ifIncluded { + includedArg = true + } + argsToExpand += 1 + } + + guard includedArg else { + return nil + } + + var expandedArgs = [TupleExprElementSyntax]() + for arg in argumentList.suffix(argsToExpand) { + let edits = ExpandEditorPlaceholder.textRefactor(syntax: arg.expression.cast(EditorPlaceholderExprSyntax.self).identifier) + guard edits.count == 1, let edit = edits.first, !edit.replacement.isEmpty else { + return nil + } + + var parser = Parser(edit.replacement) + let expr = ExprSyntax.parse(from: &parser) + expandedArgs.append( + arg.detach().with(\.expression, expr) + ) + } + + let originalArgs = argumentList.dropLast(argsToExpand) + return ( + detach().with(\.argumentList, TupleExprElementListSyntax(originalArgs + expandedArgs)), + expandedArgs.count + ) + } +} + +/// Placeholder text must start with '<#' and end with +/// '#>'. Placeholders can be one of the following formats: +/// ``` +/// 'T##' display-string '##' type-string ('##' type-for-expansion-string)? +/// 'T##' display-and-type-string +/// display-string +/// ``` +/// +/// NOTE: It is required that '##' is not a valid substring of display-string +/// or type-string. If this ends up not the case for some reason, we can consider +/// adding escaping for '##'. +fileprivate enum EditorPlaceholderData { + case basic(text: Substring) + case typed(text: Substring, type: TypeSyntax) + + init?(token: TokenSyntax) { + guard ExpandEditorPlaceholder.isPlaceholder(token.text) else { + return nil + } + + var text = token.text.dropFirst(2).dropLast(2) + + if !text.hasPrefix("T##") { + // No type information + self = .basic(text: text) + return + } + + // Drop 'T##' + text = text.dropFirst(3) + + var typeText: Substring + (text, typeText) = split(text, separatedBy: "##") + if typeText.isEmpty { + // No type information + self = .basic(text: text) + return + } + + // Have type text, see if we also have expansion text + + let expansionText: Substring + (typeText, expansionText) = split(typeText, separatedBy: "##") + if expansionText.isEmpty { + if typeText.isEmpty { + // No type information + self = .basic(text: text) + } else { + // Only have type text, use it for the placeholder expansion + self.init(typeText: typeText) + } + + return + } + + // Have expansion type text, use it for the placeholder expansion + self.init(typeText: expansionText) + } + + init(typeText: Substring) { + var parser = Parser(String(typeText)) + + let type: TypeSyntax = TypeSyntax.parse(from: &parser) + if type.hasError { + self = .basic(text: typeText) + } else { + self = .typed(text: typeText, type: type) + } + } +} + +/// Split the given string into two components on the first instance of +/// `separatedBy`. The second element is empty if `separatedBy` is missing +/// from the initial string. +fileprivate func split(_ text: Substring, separatedBy separator: String) -> (Substring, Substring) { + var rest = text + while !rest.isEmpty && !rest.hasPrefix(separator) { + rest = rest.dropFirst() + } + return (text.dropLast(rest.count), rest.dropFirst(2)) +} + +fileprivate let placeholderStart: String = "<#" +fileprivate let placeholderEnd: String = "#>" diff --git a/Sources/SwiftRefactor/FormatRawStringLiteral.swift b/Sources/SwiftRefactor/FormatRawStringLiteral.swift index 738adc3d540..ee204c057bb 100644 --- a/Sources/SwiftRefactor/FormatRawStringLiteral.swift +++ b/Sources/SwiftRefactor/FormatRawStringLiteral.swift @@ -30,7 +30,7 @@ import SwiftSyntax /// ##"Hello \#(world)"## /// "Hello World" /// ``` -public struct FormatRawStringLiteral: RefactoringProvider { +public struct FormatRawStringLiteral: SyntaxRefactoringProvider { public static func refactor(syntax lit: StringLiteralExprSyntax, in context: Void) -> StringLiteralExprSyntax? { var maximumHashes = 0 for segment in lit.segments { diff --git a/Sources/SwiftRefactor/MigrateToNewIfLetSyntax.swift b/Sources/SwiftRefactor/MigrateToNewIfLetSyntax.swift index 3fd906cb73d..02a16940510 100644 --- a/Sources/SwiftRefactor/MigrateToNewIfLetSyntax.swift +++ b/Sources/SwiftRefactor/MigrateToNewIfLetSyntax.swift @@ -33,7 +33,7 @@ import SwiftParser /// if let foo { /// // ... /// } -public struct MigrateToNewIfLetSyntax: RefactoringProvider { +public struct MigrateToNewIfLetSyntax: SyntaxRefactoringProvider { public static func refactor(syntax node: IfExprSyntax, in context: ()) -> IfExprSyntax? { // Visit all conditions in the node. let newConditions = node.conditions.enumerated().map { (index, condition) -> ConditionElementListSyntax.Element in diff --git a/Sources/SwiftRefactor/OpaqueParameterToGeneric.swift b/Sources/SwiftRefactor/OpaqueParameterToGeneric.swift index 59a260ba843..eaa522c94b7 100644 --- a/Sources/SwiftRefactor/OpaqueParameterToGeneric.swift +++ b/Sources/SwiftRefactor/OpaqueParameterToGeneric.swift @@ -115,7 +115,7 @@ fileprivate class SomeParameterRewriter: SyntaxRewriter { /// ```swift /// func someFunction(_ input: T1) {} /// ``` -public struct OpaqueParameterToGeneric: RefactoringProvider { +public struct OpaqueParameterToGeneric: SyntaxRefactoringProvider { /// Replace all of the "some" parameters in the given parameter clause with /// freshly-created generic parameters. /// diff --git a/Sources/SwiftRefactor/RefactoringProvider.swift b/Sources/SwiftRefactor/RefactoringProvider.swift index 16a92995a9f..69225237d9b 100644 --- a/Sources/SwiftRefactor/RefactoringProvider.swift +++ b/Sources/SwiftRefactor/RefactoringProvider.swift @@ -12,30 +12,43 @@ import SwiftSyntax -/// A type that transforms syntax to provide a (context-sensitive) -/// refactoring. -/// -/// A type conforming to the `RefactoringProvider` protocol defines -/// a refactoring action against a family of Swift syntax trees. -/// -/// Refactoring -/// =========== -/// -/// Refactoring is the act of transforming source code to be more effective. -/// A refactoring does not affect the semantics of code it is transforming. -/// Rather, it makes that code easier to read and reason about. -/// -/// Code Transformation -/// =================== -/// -/// Refactoring is expressed as structural transformations of Swift -/// syntax trees. The SwiftSyntax API provides a natural, easy-to-use, -/// and compositional set of updates to the syntax tree. For example, a -/// refactoring action that wishes to exchange the leading trivia of a node -/// would call `with(\.leadingTrivia, _:)` against its input syntax and return -/// the resulting syntax node. For compound syntax nodes, entire sub-trees -/// can be added, exchanged, or removed by calling the corresponding `with` -/// API. +/// A refactoring expressed as textual edits on the original syntax tree. In +/// general clients should prefer `SyntaxRefactoringProvider` where possible. +public protocol EditRefactoringProvider { + /// The type of syntax this refactoring action accepts. + associatedtype Input: SyntaxProtocol + /// Contextual information used by the refactoring action. + associatedtype Context = Void + + /// Perform the refactoring action on the provided syntax node. + /// + /// - Parameters: + /// - syntax: The syntax to transform. + /// - context: Contextual information used by the refactoring action. + /// - Returns: Textual edits that describe how to apply the result of the + /// refactoring action on locations within the original tree. An + /// empty array if the refactoring could not be performed. + static func textRefactor(syntax: Input, in context: Context) -> [SourceEdit] +} + +extension EditRefactoringProvider where Context == Void { + /// See `textRefactor(syntax:in:)`. This method provides a convenient way to + /// invoke a refactoring action that requires no context. + /// + /// - Parameters: + /// - syntax: The syntax to transform. + /// - Returns: Textual edits describing the refactoring to perform. + public static func textRefactor(syntax: Input) -> [SourceEdit] { + return self.textRefactor(syntax: syntax, in: ()) + } +} + +/// A refactoring expressed as a structural transformation of the original +/// syntax node. For example, a refactoring action that wishes to exchange the +/// leading trivia of a node could call call `with(\.leadingTrivia, _:)` +/// against its input syntax and return the resulting syntax node. Or, for +/// compound syntax nodes, entire sub-trees can be added, exchanged, or removed +/// by calling the corresponding `with` API. /// /// - Note: The syntax trees returned by SwiftSyntax are immutable: any /// transformation made against the tree results in a distinct tree. @@ -44,43 +57,116 @@ import SwiftSyntax /// ========================= /// /// A refactoring provider cannot assume that the syntax it is given is -/// neessarily well-formed. As the SwiftSyntax library is capable of recovering +/// necessarily well-formed. As the SwiftSyntax library is capable of recovering /// from a variety of erroneous inputs, a refactoring provider has to be /// prepared to fail gracefully as well. Many refactoring providers follow a /// common validation pattern that "preflights" the refactoring by testing the /// structure of the provided syntax nodes. If the tests fail, the refactoring -/// provider exits early by returning `nil`. It is recommended that refactoring -/// actions fail as quickly as possible to give any associated tooling -/// space to recover as well. -public protocol RefactoringProvider { - /// The type of syntax this refactoring action accepts. - associatedtype Input: SyntaxProtocol = SourceFileSyntax +/// provider exits early by returning an empty array. It is recommended that +/// refactoring actions fail as quickly as possible to give any associated +/// tooling space to recover as well. +public protocol SyntaxRefactoringProvider: EditRefactoringProvider { + // Should not be required, see https://github.com/apple/swift/issues/66004. + // The default is a hack to workaround the warning that we'd hit otherwise. + associatedtype Input: SyntaxProtocol = MissingSyntax /// The type of syntax this refactoring action returns. - associatedtype Output: SyntaxProtocol = SourceFileSyntax + associatedtype Output: SyntaxProtocol /// Contextual information used by the refactoring action. associatedtype Context = Void - /// Perform the refactoring action on the provided syntax node. + /// Perform the refactoring action on the provided syntax node. It is assumed + /// that the returned output completely replaces the input node. /// /// - Parameters: /// - syntax: The syntax to transform. /// - context: Contextual information used by the refactoring action. /// - Returns: The result of applying the refactoring action, or `nil` if the /// action could not be performed. - static func refactor(syntax: Self.Input, in context: Self.Context) -> Self.Output? + static func refactor(syntax: Input, in context: Context) -> Output? } -extension RefactoringProvider where Context == Void { - /// Perform the refactoring action on the provided syntax node. - /// - /// This method provides a convenient way to invoke a refactoring action that - /// requires no context. +extension SyntaxRefactoringProvider where Context == Void { + /// See `refactor(syntax:in:)`. This method provides a convenient way to + /// invoke a refactoring action that requires no context. /// /// - Parameters: /// - syntax: The syntax to transform. /// - Returns: The result of applying the refactoring action, or `nil` if the /// action could not be performed. - public static func refactor(syntax: Self.Input) -> Self.Output? { + public static func refactor(syntax: Input) -> Output? { return self.refactor(syntax: syntax, in: ()) } } + +extension SyntaxRefactoringProvider { + /// Provides a default implementation for + /// `EditRefactoringProvider.textRefactor(syntax:in:)` that produces an edit + /// to replace the input of `refactor(syntax:in:)` with its returned output. + public static func textRefactor(syntax: Input, in context: Context) -> [SourceEdit] { + guard let output = refactor(syntax: syntax, in: context) else { + return [] + } + return [SourceEdit.replace(syntax, with: output.description)] + } +} + +/// An textual edit to the original source represented by a range and a +/// replacement. +public struct SourceEdit: Equatable { + /// The half-open range that this edit applies to. + public let range: Range + /// The text to replace the original range with. Empty for a deletion. + public let replacement: String + + /// Length of the original source range that this edit applies to. Zero if + /// this is an addition. + public var length: SourceLength { + return SourceLength(utf8Length: range.lowerBound.utf8Offset - range.upperBound.utf8Offset) + } + + /// Create an edit to replace `range` in the original source with + /// `replacement`. + public init(range: Range, replacement: String) { + self.range = range + self.replacement = replacement + } + + /// Convenience function to create a textual addition after the given node + /// and its trivia. + public static func insert(_ newText: String, after node: some SyntaxProtocol) -> SourceEdit { + return SourceEdit(range: node.endPosition.. SourceEdit { + return SourceEdit(range: node.position.. SourceEdit { + return SourceEdit(range: node.position.. SourceEdit { + return SourceEdit(range: node.position.. IntegerLiteralExprSyntax? { guard lit.digits.text.contains("_") else { return lit diff --git a/Sources/SwiftSyntax/IncrementalParseTransition.swift b/Sources/SwiftSyntax/IncrementalParseTransition.swift index 6fa9f60fc97..345cdb92e67 100644 --- a/Sources/SwiftSyntax/IncrementalParseTransition.swift +++ b/Sources/SwiftSyntax/IncrementalParseTransition.swift @@ -97,11 +97,11 @@ public struct ConcurrentEdits { /// The raw concurrent edits. Are guaranteed to satisfy the requirements /// stated above. - public let edits: [SourceEdit] + public let edits: [IncrementalEdit] /// Initialize this struct from edits that are already in a concurrent form /// and are guaranteed to satisfy the requirements posed above. - public init(concurrent: [SourceEdit]) throws { + public init(concurrent: [IncrementalEdit]) throws { if !Self.isValidConcurrentEditArray(concurrent) { throw ConcurrentEditsError.editsNotConcurrent } @@ -117,7 +117,7 @@ public struct ConcurrentEdits { /// - insert 'z' at offset 2 /// to '012345' results in 'xyz012345'. - public init(fromSequential sequentialEdits: [SourceEdit]) { + public init(fromSequential sequentialEdits: [IncrementalEdit]) { do { try self.init(concurrent: Self.translateSequentialEditsToConcurrentEdits(sequentialEdits)) } catch { @@ -128,7 +128,7 @@ public struct ConcurrentEdits { /// Construct a concurrent edits struct from a single edit. For a single edit, /// there is no differentiation between being it being applied concurrently /// or sequentially. - public init(_ single: SourceEdit) { + public init(_ single: IncrementalEdit) { do { try self.init(concurrent: [single]) } catch { @@ -137,9 +137,9 @@ public struct ConcurrentEdits { } private static func translateSequentialEditsToConcurrentEdits( - _ edits: [SourceEdit] - ) -> [SourceEdit] { - var concurrentEdits: [SourceEdit] = [] + _ edits: [IncrementalEdit] + ) -> [IncrementalEdit] { + var concurrentEdits: [IncrementalEdit] = [] for editToAdd in edits { var editToAdd = editToAdd var editIndiciesMergedWithNewEdit: [Int] = [] @@ -147,14 +147,14 @@ public struct ConcurrentEdits { if existingEdit.replacementRange.intersectsOrTouches(editToAdd.range) { let intersectionLength = existingEdit.replacementRange.intersected(editToAdd.range).length - editToAdd = SourceEdit( + editToAdd = IncrementalEdit( offset: Swift.min(existingEdit.offset, editToAdd.offset), length: existingEdit.length + editToAdd.length - intersectionLength, replacementLength: existingEdit.replacementLength + editToAdd.replacementLength - intersectionLength ) editIndiciesMergedWithNewEdit.append(index) } else if existingEdit.offset < editToAdd.endOffset { - editToAdd = SourceEdit( + editToAdd = IncrementalEdit( offset: editToAdd.offset - existingEdit.replacementLength + existingEdit.length, length: editToAdd.length, replacementLength: editToAdd.replacementLength @@ -175,7 +175,7 @@ public struct ConcurrentEdits { return concurrentEdits } - private static func isValidConcurrentEditArray(_ edits: [SourceEdit]) -> Bool { + private static func isValidConcurrentEditArray(_ edits: [IncrementalEdit]) -> Bool { // Not quite sure if we should disallow creating an `IncrementalParseTransition` // object without edits but there doesn't seem to be much benefit if we do, // and there are 'lit' tests that want to test incremental re-parsing without edits. @@ -195,7 +195,7 @@ public struct ConcurrentEdits { } /// **Public for testing purposes only** - public static func _isValidConcurrentEditArray(_ edits: [SourceEdit]) -> Bool { + public static func _isValidConcurrentEditArray(_ edits: [IncrementalEdit]) -> Bool { return isValidConcurrentEditArray(edits) } } diff --git a/Sources/SwiftSyntax/Trivia.swift b/Sources/SwiftSyntax/Trivia.swift index 6a3117b5b27..f833a7344be 100644 --- a/Sources/SwiftSyntax/Trivia.swift +++ b/Sources/SwiftSyntax/Trivia.swift @@ -59,7 +59,11 @@ public struct Trivia { /// Creates a new ``Trivia`` by merging in the given trivia. Only includes one /// copy of a common prefix of `self` and `trivia`. - public func merging(_ trivia: Trivia) -> Trivia { + public func merging(_ trivia: Trivia?) -> Trivia { + guard let trivia else { + return self + } + let lhs = self.decomposed let rhs = trivia.decomposed for infixLength in (0...Swift.min(lhs.count, rhs.count)).reversed() { @@ -73,7 +77,10 @@ public struct Trivia { /// Creates a new ``Trivia`` by merging the leading and trailing ``Trivia`` /// of `triviaOf` into the end of `self`. Only includes one copy of any /// common prefixes. - public func merging(triviaOf node: some SyntaxProtocol) -> Trivia { + public func merging(triviaOf node: (some SyntaxProtocol)?) -> Trivia { + guard let node else { + return self + } return merging(node.leadingTrivia).merging(node.trailingTrivia) } diff --git a/Sources/SwiftSyntax/Utils.swift b/Sources/SwiftSyntax/Utils.swift index 1ab3148771f..856bac5ab6f 100644 --- a/Sources/SwiftSyntax/Utils.swift +++ b/Sources/SwiftSyntax/Utils.swift @@ -47,7 +47,7 @@ public struct ByteSourceRange: Equatable { } } -public struct SourceEdit: Equatable { +public struct IncrementalEdit: Equatable { /// The byte range of the original source buffer that the edit applies to. public let range: ByteSourceRange /// The length of the edit replacement in UTF8 bytes. diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift index fa6e048a8f5..b9f7d6c75a5 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift @@ -71,7 +71,7 @@ public struct AccessorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenInitEffectsAndBody, body, unexpectedAfterBody - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -340,7 +340,7 @@ public struct ActorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericWhereClauseAndMemberBlock, memberBlock, unexpectedAfterMemberBlock - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -668,7 +668,7 @@ public struct AssociatedtypeDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenInitializerAndGenericWhereClause, genericWhereClause, unexpectedAfterGenericWhereClause - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -983,7 +983,7 @@ public struct ClassDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericWhereClauseAndMemberBlock, memberBlock, unexpectedAfterMemberBlock - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -1290,7 +1290,7 @@ public struct DeinitializerDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenDeinitKeywordAndBody, body, unexpectedAfterBody - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -1496,7 +1496,7 @@ public struct EditorPlaceholderDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenModifiersAndPlaceholder, placeholder, unexpectedAfterPlaceholder - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -1683,7 +1683,7 @@ public struct EnumCaseDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenCaseKeywordAndElements, elements, unexpectedAfterElements - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -1928,7 +1928,7 @@ public struct EnumDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericWhereClauseAndMemberBlock, memberBlock, unexpectedAfterMemberBlock - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -2242,7 +2242,7 @@ public struct ExtensionDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericWhereClauseAndMemberBlock, memberBlock, unexpectedAfterMemberBlock - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -2530,7 +2530,7 @@ public struct FunctionDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericWhereClauseAndBody, body, unexpectedAfterBody - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -2816,7 +2816,7 @@ public struct IfConfigDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenClausesAndPoundEndif, poundEndif, unexpectedAfterPoundEndif - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeClauses?.raw, clauses.raw, @@ -2967,7 +2967,7 @@ public struct ImportDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenImportKindAndPath, path, unexpectedAfterPath - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -3242,7 +3242,7 @@ public struct InitializerDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericWhereClauseAndBody, body, unexpectedAfterBody - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -3560,7 +3560,7 @@ public struct MacroDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenDefinitionAndGenericWhereClause, genericWhereClause, unexpectedAfterGenericWhereClause - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -3878,7 +3878,7 @@ public struct MacroExpansionDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenTrailingClosureAndAdditionalTrailingClosures, additionalTrailingClosures, unexpectedAfterAdditionalTrailingClosures - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -4251,7 +4251,7 @@ public struct MissingDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenModifiersAndPlaceholder, placeholder, unexpectedAfterPlaceholder - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -4438,7 +4438,7 @@ public struct OperatorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenIdentifierAndOperatorPrecedenceAndTypes, operatorPrecedenceAndTypes, unexpectedAfterOperatorPrecedenceAndTypes - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeFixity?.raw, fixity.raw, @@ -4608,7 +4608,7 @@ public struct PoundSourceLocationSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenArgsAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforePoundSourceLocation?.raw, poundSourceLocation.raw, @@ -4788,7 +4788,7 @@ public struct PrecedenceGroupDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenGroupAttributesAndRightBrace, rightBrace, unexpectedAfterRightBrace - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -5105,7 +5105,7 @@ public struct ProtocolDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericWhereClauseAndMemberBlock, memberBlock, unexpectedAfterMemberBlock - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -5477,7 +5477,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericWhereClauseAndMemberBlock, memberBlock, unexpectedAfterMemberBlock - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -5837,7 +5837,7 @@ public struct SubscriptDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericWhereClauseAndAccessor, accessor, unexpectedAfterAccessor - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -6143,7 +6143,7 @@ public struct TypealiasDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenInitializerAndGenericWhereClause, genericWhereClause, unexpectedAfterGenericWhereClause - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -6415,7 +6415,7 @@ public struct VariableDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { unexpectedBetweenBindingKeywordAndBindings, bindings, unexpectedAfterBindings - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxExprNodes.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxExprNodes.swift index e30e61f050f..d4b908c970f 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxExprNodes.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxExprNodes.swift @@ -55,7 +55,7 @@ public struct ArrayExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenElementsAndRightSquare, rightSquare, unexpectedAfterRightSquare - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftSquare?.raw, leftSquare.raw, @@ -212,7 +212,7 @@ public struct ArrowExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenEffectSpecifiersAndArrowToken, arrowToken, unexpectedAfterArrowToken - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeEffectSpecifiers?.raw, effectSpecifiers?.raw, @@ -336,7 +336,7 @@ public struct AsExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenQuestionOrExclamationMarkAndTypeName, typeName, unexpectedAfterTypeName - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeExpression?.raw, expression.raw, @@ -488,7 +488,7 @@ public struct AssignmentExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeAssignToken, assignToken, unexpectedAfterAssignToken))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeAssignToken, assignToken, unexpectedAfterAssignToken))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeAssignToken?.raw, assignToken.raw, unexpectedAfterAssignToken?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.assignmentExpr, @@ -574,7 +574,7 @@ public struct AwaitExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenAwaitKeywordAndExpression, expression, unexpectedAfterExpression - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAwaitKeyword?.raw, awaitKeyword.raw, @@ -682,7 +682,7 @@ public struct BinaryOperatorExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeOperatorToken, operatorToken, unexpectedAfterOperatorToken))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeOperatorToken, operatorToken, unexpectedAfterOperatorToken))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeOperatorToken?.raw, operatorToken.raw, unexpectedAfterOperatorToken?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.binaryOperatorExpr, @@ -760,7 +760,7 @@ public struct BooleanLiteralExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeBooleanLiteral, booleanLiteral, unexpectedAfterBooleanLiteral))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeBooleanLiteral, booleanLiteral, unexpectedAfterBooleanLiteral))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeBooleanLiteral?.raw, booleanLiteral.raw, unexpectedAfterBooleanLiteral?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.booleanLiteralExpr, @@ -846,7 +846,7 @@ public struct BorrowExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenBorrowKeywordAndExpression, expression, unexpectedAfterExpression - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBorrowKeyword?.raw, borrowKeyword.raw, @@ -974,7 +974,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenVersionInfoAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeCanImportKeyword?.raw, canImportKeyword.raw, @@ -1164,7 +1164,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenColonAndVersionTuple, versionTuple, unexpectedAfterVersionTuple - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeComma?.raw, comma.raw, @@ -1332,7 +1332,7 @@ public struct ClosureExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenStatementsAndRightBrace, rightBrace, unexpectedAfterRightBrace - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftBrace?.raw, leftBrace.raw, @@ -1511,7 +1511,7 @@ public struct CopyExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenCopyKeywordAndExpression, expression, unexpectedAfterExpression - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeCopyKeyword?.raw, copyKeyword.raw, @@ -1673,7 +1673,7 @@ public struct DictionaryExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenContentAndRightSquare, rightSquare, unexpectedAfterRightSquare - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftSquare?.raw, leftSquare.raw, @@ -1803,7 +1803,7 @@ public struct DiscardAssignmentExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeWildcard, wildcard, unexpectedAfterWildcard))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeWildcard, wildcard, unexpectedAfterWildcard))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeWildcard?.raw, wildcard.raw, unexpectedAfterWildcard?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.discardAssignmentExpr, @@ -1881,7 +1881,7 @@ public struct EditorPlaceholderExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeIdentifier, identifier, unexpectedAfterIdentifier))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeIdentifier, identifier, unexpectedAfterIdentifier))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeIdentifier?.raw, identifier.raw, unexpectedAfterIdentifier?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.editorPlaceholderExpr, @@ -1959,7 +1959,7 @@ public struct FloatLiteralExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeFloatingDigits, floatingDigits, unexpectedAfterFloatingDigits))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeFloatingDigits, floatingDigits, unexpectedAfterFloatingDigits))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeFloatingDigits?.raw, floatingDigits.raw, unexpectedAfterFloatingDigits?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.floatLiteralExpr, @@ -2045,7 +2045,7 @@ public struct ForcedValueExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenExpressionAndExclamationMark, exclamationMark, unexpectedAfterExclamationMark - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeExpression?.raw, expression.raw, @@ -2177,7 +2177,7 @@ public struct FunctionCallExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenTrailingClosureAndAdditionalTrailingClosures, additionalTrailingClosures, unexpectedAfterAdditionalTrailingClosures - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeCalledExpression?.raw, calledExpression.raw, @@ -2419,7 +2419,7 @@ public struct IdentifierExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenIdentifierAndDeclNameArguments, declNameArguments, unexpectedAfterDeclNameArguments - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeIdentifier?.raw, identifier.raw, @@ -2589,7 +2589,7 @@ public struct IfExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenElseKeywordAndElseBody, elseBody, unexpectedAfterElseBody - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeIfKeyword?.raw, ifKeyword.raw, @@ -2790,7 +2790,7 @@ public struct InOutExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenAmpersandAndExpression, expression, unexpectedAfterExpression - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAmpersand?.raw, ampersand.raw, @@ -2910,7 +2910,7 @@ public struct InfixOperatorExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenOperatorOperandAndRightOperand, rightOperand, unexpectedAfterRightOperand - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftOperand?.raw, leftOperand.raw, @@ -3040,7 +3040,7 @@ public struct IntegerLiteralExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeDigits, digits, unexpectedAfterDigits))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeDigits, digits, unexpectedAfterDigits))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeDigits?.raw, digits.raw, unexpectedAfterDigits?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.integerLiteralExpr, @@ -3136,7 +3136,7 @@ public struct IsExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenIsTokAndTypeName, typeName, unexpectedAfterTypeName - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeExpression?.raw, expression.raw, @@ -3281,7 +3281,7 @@ public struct KeyPathExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenRootAndComponents, components, unexpectedAfterComponents - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBackslash?.raw, backslash.raw, @@ -3462,7 +3462,7 @@ public struct MacroExpansionExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenTrailingClosureAndAdditionalTrailingClosures, additionalTrailingClosures, unexpectedAfterAdditionalTrailingClosures - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforePoundToken?.raw, poundToken.raw, @@ -3757,7 +3757,7 @@ public struct MemberAccessExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndDeclNameArguments, declNameArguments, unexpectedAfterDeclNameArguments - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBase?.raw, base?.raw, @@ -3909,7 +3909,7 @@ public struct MissingExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePlaceholder, placeholder, unexpectedAfterPlaceholder))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePlaceholder, placeholder, unexpectedAfterPlaceholder))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforePlaceholder?.raw, placeholder.raw, unexpectedAfterPlaceholder?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.missingExpr, @@ -3996,7 +3996,7 @@ public struct MoveExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenMoveKeywordAndExpression, expression, unexpectedAfterExpression - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeMoveKeyword?.raw, moveKeyword.raw, @@ -4104,7 +4104,7 @@ public struct NilLiteralExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeNilKeyword, nilKeyword, unexpectedAfterNilKeyword))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeNilKeyword, nilKeyword, unexpectedAfterNilKeyword))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeNilKeyword?.raw, nilKeyword.raw, unexpectedAfterNilKeyword?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.nilLiteralExpr, @@ -4190,7 +4190,7 @@ public struct OptionalChainingExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenExpressionAndQuestionMark, questionMark, unexpectedAfterQuestionMark - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeExpression?.raw, expression.raw, @@ -4306,7 +4306,7 @@ public struct PackElementExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenEachKeywordAndPackRefExpr, packRefExpr, unexpectedAfterPackRefExpr - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeEachKeyword?.raw, eachKeyword.raw, @@ -4422,7 +4422,7 @@ public struct PackExpansionExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenRepeatKeywordAndPatternExpr, patternExpr, unexpectedAfterPatternExpr - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeRepeatKeyword?.raw, repeatKeyword.raw, @@ -4538,7 +4538,7 @@ public struct PostfixIfConfigExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenBaseAndConfig, config, unexpectedAfterConfig - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBase?.raw, base?.raw, @@ -4654,7 +4654,7 @@ public struct PostfixUnaryExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenExpressionAndOperatorToken, operatorToken, unexpectedAfterOperatorToken - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeExpression?.raw, expression.raw, @@ -4770,7 +4770,7 @@ public struct PrefixOperatorExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenOperatorTokenAndPostfixExpression, postfixExpression, unexpectedAfterPostfixExpression - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeOperatorToken?.raw, operatorToken?.raw, @@ -4898,7 +4898,7 @@ public struct RegexLiteralExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenCloseSlashAndClosingPounds, closingPounds, unexpectedAfterClosingPounds - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeOpeningPounds?.raw, openingPounds?.raw, @@ -5072,7 +5072,7 @@ public struct SequenceExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeElements, elements, unexpectedAfterElements))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeElements, elements, unexpectedAfterElements))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeElements?.raw, elements.raw, unexpectedAfterElements?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.sequenceExpr, @@ -5177,7 +5177,7 @@ public struct SpecializeExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenExpressionAndGenericArgumentClause, genericArgumentClause, unexpectedAfterGenericArgumentClause - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeExpression?.raw, expression.raw, @@ -5305,7 +5305,7 @@ public struct StringLiteralExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenCloseQuoteAndCloseDelimiter, closeDelimiter, unexpectedAfterCloseDelimiter - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeOpenDelimiter?.raw, openDelimiter?.raw, @@ -5522,7 +5522,7 @@ public struct SubscriptExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenTrailingClosureAndAdditionalTrailingClosures, additionalTrailingClosures, unexpectedAfterAdditionalTrailingClosures - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeCalledExpression?.raw, calledExpression.raw, @@ -5756,7 +5756,7 @@ public struct SuperRefExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeSuperKeyword, superKeyword, unexpectedAfterSuperKeyword))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeSuperKeyword, superKeyword, unexpectedAfterSuperKeyword))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeSuperKeyword?.raw, superKeyword.raw, unexpectedAfterSuperKeyword?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.superRefExpr, @@ -5854,7 +5854,7 @@ public struct SwitchExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenCasesAndRightBrace, rightBrace, unexpectedAfterRightBrace - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeSwitchKeyword?.raw, switchKeyword.raw, @@ -6067,7 +6067,7 @@ public struct TernaryExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenColonMarkAndSecondChoice, secondChoice, unexpectedAfterSecondChoice - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeConditionExpression?.raw, conditionExpression.raw, @@ -6253,7 +6253,7 @@ public struct TryExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenQuestionOrExclamationMarkAndExpression, expression, unexpectedAfterExpression - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeTryKeyword?.raw, tryKeyword.raw, @@ -6395,7 +6395,7 @@ public struct TupleExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenElementsAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, @@ -6544,7 +6544,7 @@ public struct TypeExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeType, type, unexpectedAfterType))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeType, type, unexpectedAfterType))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeType?.raw, type.raw, unexpectedAfterType?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.typeExpr, @@ -6630,7 +6630,7 @@ public struct UnresolvedAsExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenAsTokAndQuestionOrExclamationMark, questionOrExclamationMark, unexpectedAfterQuestionOrExclamationMark - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAsTok?.raw, asTok.raw, @@ -6738,7 +6738,7 @@ public struct UnresolvedIsExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeIsTok, isTok, unexpectedAfterIsTok))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeIsTok, isTok, unexpectedAfterIsTok))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeIsTok?.raw, isTok.raw, unexpectedAfterIsTok?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.unresolvedIsExpr, @@ -6816,7 +6816,7 @@ public struct UnresolvedPatternExprSyntax: ExprSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePattern, pattern, unexpectedAfterPattern))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePattern, pattern, unexpectedAfterPattern))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforePattern?.raw, pattern.raw, unexpectedAfterPattern?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.unresolvedPatternExpr, @@ -6906,7 +6906,7 @@ public struct UnresolvedTernaryExprSyntax: ExprSyntaxProtocol, SyntaxHashable { unexpectedBetweenFirstChoiceAndColonMark, colonMark, unexpectedAfterColonMark - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeQuestionMark?.raw, questionMark.raw, diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift index 39a3ea07c21..6bc12a3d4db 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift @@ -59,7 +59,7 @@ public struct AccessesEffectSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenPropertyListAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAccessesKeyword?.raw, accessesKeyword.raw, @@ -242,7 +242,7 @@ public struct AccessorBlockSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenAccessorsAndRightBrace, rightBrace, unexpectedAfterRightBrace - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftBrace?.raw, leftBrace.raw, @@ -399,7 +399,7 @@ public struct AccessorEffectSpecifiersSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenAsyncSpecifierAndThrowsSpecifier, throwsSpecifier, unexpectedAfterThrowsSpecifier - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAsyncSpecifier?.raw, asyncSpecifier?.raw, @@ -515,7 +515,7 @@ public struct AccessorInitEffectsSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenInitializesEffectAndAccessesEffect, accessesEffect, unexpectedAfterAccessesEffect - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeInitializesEffect?.raw, initializesEffect?.raw, @@ -635,7 +635,7 @@ public struct AccessorParameterSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, @@ -773,7 +773,7 @@ public struct ArrayElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenExpressionAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeExpression?.raw, expression.raw, @@ -1162,7 +1162,7 @@ public struct AttributeSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenArgumentAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAtSignToken?.raw, atSignToken.raw, @@ -1402,7 +1402,7 @@ public struct AvailabilityArgumentSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenEntryAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeEntry?.raw, entry.raw, @@ -1528,7 +1528,7 @@ public struct AvailabilityConditionSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenAvailabilityArgumentsAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAvailabilityKeyword?.raw, availabilityKeyword.raw, @@ -1715,7 +1715,7 @@ public struct AvailabilityEntrySyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenAvailabilityArgumentsAndSemicolon, semicolon, unexpectedAfterSemicolon - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLabel?.raw, label.raw, @@ -1942,7 +1942,7 @@ public struct AvailabilityLabeledArgumentSyntax: SyntaxProtocol, SyntaxHashable unexpectedBetweenColonAndValue, value, unexpectedAfterValue - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLabel?.raw, label.raw, @@ -2083,7 +2083,7 @@ public struct AvailabilityVersionRestrictionListEntrySyntax: SyntaxProtocol, Syn unexpectedBetweenAvailabilityVersionRestrictionAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAvailabilityVersionRestriction?.raw, availabilityVersionRestriction.raw, @@ -2200,7 +2200,7 @@ public struct AvailabilityVersionRestrictionSyntax: SyntaxProtocol, SyntaxHashab unexpectedBetweenPlatformAndVersion, version, unexpectedAfterVersion - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforePlatform?.raw, platform.raw, @@ -2321,7 +2321,7 @@ public struct BackDeployedAttributeSpecListSyntax: SyntaxProtocol, SyntaxHashabl unexpectedBetweenColonAndPlatforms, platforms, unexpectedAfterPlatforms - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBeforeLabel?.raw, beforeLabel.raw, @@ -2485,7 +2485,7 @@ public struct CaseItemSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenWhereClauseAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforePattern?.raw, pattern.raw, @@ -2627,7 +2627,7 @@ public struct CatchClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenCatchItemsAndBody, body, unexpectedAfterBody - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeCatchKeyword?.raw, catchKeyword.raw, @@ -2788,7 +2788,7 @@ public struct CatchItemSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenWhereClauseAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforePattern?.raw, pattern?.raw, @@ -2934,7 +2934,7 @@ public struct ClosureCaptureItemSpecifierSyntax: SyntaxProtocol, SyntaxHashable unexpectedBetweenDetailAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeSpecifier?.raw, specifier.raw, @@ -3106,7 +3106,7 @@ public struct ClosureCaptureItemSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenExpressionAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeSpecifier?.raw, specifier?.raw, @@ -3292,7 +3292,7 @@ public struct ClosureCaptureSignatureSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenItemsAndRightSquare, rightSquare, unexpectedAfterRightSquare - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftSquare?.raw, leftSquare.raw, @@ -3449,7 +3449,7 @@ public struct ClosureParamSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeName?.raw, name.raw, @@ -3569,7 +3569,7 @@ public struct ClosureParameterClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenParameterListAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, @@ -3753,7 +3753,7 @@ public struct ClosureParameterSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenEllipsisAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -4103,7 +4103,7 @@ public struct ClosureSignatureSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenOutputAndInTok, inTok, unexpectedAfterInTok - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -4379,7 +4379,7 @@ public struct CodeBlockItemSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenItemAndSemicolon, semicolon, unexpectedAfterSemicolon - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeItem?.raw, item.raw, @@ -4501,7 +4501,7 @@ public struct CodeBlockSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenStatementsAndRightBrace, rightBrace, unexpectedAfterRightBrace - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftBrace?.raw, leftBrace.raw, @@ -4658,7 +4658,7 @@ public struct CompositionTypeElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenTypeAndAmpersand, ampersand, unexpectedAfterAmpersand - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeType?.raw, type.raw, @@ -4843,7 +4843,7 @@ public struct ConditionElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenConditionAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeCondition?.raw, condition.raw, @@ -4963,7 +4963,7 @@ public struct ConformanceRequirementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenColonAndRightTypeIdentifier, rightTypeIdentifier, unexpectedAfterRightTypeIdentifier - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftTypeIdentifier?.raw, leftTypeIdentifier.raw, @@ -5113,7 +5113,7 @@ public struct ConventionAttributeArgumentsSyntax: SyntaxProtocol, SyntaxHashable unexpectedBetweenColonAndCTypeString, cTypeString, unexpectedAfterCTypeString - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeConventionLabel?.raw, conventionLabel.raw, @@ -5300,7 +5300,7 @@ public struct ConventionWitnessMethodAttributeArgumentsSyntax: SyntaxProtocol, S unexpectedBetweenColonAndProtocolName, protocolName, unexpectedAfterProtocolName - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeWitnessMethodLabel?.raw, witnessMethodLabel.raw, @@ -5442,7 +5442,7 @@ public struct DeclModifierDetailSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenDetailAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, @@ -5580,7 +5580,7 @@ public struct DeclModifierSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndDetail, detail, unexpectedAfterDetail - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeName?.raw, name.raw, @@ -5696,7 +5696,7 @@ public struct DeclNameArgumentSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndColon, colon, unexpectedAfterColon - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeName?.raw, name.raw, @@ -5816,7 +5816,7 @@ public struct DeclNameArgumentsSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenArgumentsAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, @@ -5973,7 +5973,7 @@ public struct DeclNameSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenDeclBaseNameAndDeclNameArguments, declNameArguments, unexpectedAfterDeclNameArguments - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeDeclBaseName?.raw, declBaseName.raw, @@ -6111,7 +6111,7 @@ public struct DerivativeRegistrationAttributeArgumentsSyntax: SyntaxProtocol, Sy unexpectedBetweenCommaAndDiffParams, diffParams, unexpectedAfterDiffParams - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeOfLabel?.raw, ofLabel.raw, @@ -6342,7 +6342,7 @@ public struct DesignatedTypeElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenLeadingCommaAndName, name, unexpectedAfterName - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeadingComma?.raw, leadingComma.raw, @@ -6466,7 +6466,7 @@ public struct DictionaryElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenValueExpressionAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeKeyExpression?.raw, keyExpression.raw, @@ -6626,7 +6626,7 @@ public struct DifferentiabilityParamSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenParameterAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeParameter?.raw, parameter.raw, @@ -6788,7 +6788,7 @@ public struct DifferentiabilityParamsClauseSyntax: SyntaxProtocol, SyntaxHashabl unexpectedBetweenColonAndParameters, parameters, unexpectedAfterParameters - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeWrtLabel?.raw, wrtLabel.raw, @@ -6932,7 +6932,7 @@ public struct DifferentiabilityParamsSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenDiffParamsAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, @@ -7102,7 +7102,7 @@ public struct DifferentiableAttributeArgumentsSyntax: SyntaxProtocol, SyntaxHash unexpectedBetweenDiffParamsCommaAndWhereClause, whereClause, unexpectedAfterWhereClause - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeDiffKind?.raw, diffKind?.raw, @@ -7336,7 +7336,7 @@ public struct DocumentationAttributeArgumentSyntax: SyntaxProtocol, SyntaxHashab unexpectedBetweenValueAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLabel?.raw, label.raw, @@ -7501,7 +7501,7 @@ public struct DynamicReplacementArgumentsSyntax: SyntaxProtocol, SyntaxHashable unexpectedBetweenColonAndDeclname, declname, unexpectedAfterDeclname - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeForLabel?.raw, forLabel.raw, @@ -7647,7 +7647,7 @@ public struct EnumCaseElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenRawValueAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeIdentifier?.raw, identifier.raw, @@ -7815,7 +7815,7 @@ public struct EnumCaseParameterClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenParameterListAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, @@ -7995,7 +7995,7 @@ public struct EnumCaseParameterSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenDefaultArgumentAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeModifiers?.raw, modifiers?.raw, @@ -8248,7 +8248,7 @@ public struct ExposeAttributeArgumentsSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenCommaAndCxxName, cxxName, unexpectedAfterCxxName - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLanguage?.raw, language.raw, @@ -8398,7 +8398,7 @@ public struct ExpressionSegmentSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenExpressionsAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBackslash?.raw, backslash.raw, @@ -8599,7 +8599,7 @@ public struct FunctionEffectSpecifiersSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenAsyncSpecifierAndThrowsSpecifier, throwsSpecifier, unexpectedAfterThrowsSpecifier - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAsyncSpecifier?.raw, asyncSpecifier?.raw, @@ -8743,7 +8743,7 @@ public struct FunctionParameterSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenDefaultArgumentAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -9055,7 +9055,7 @@ public struct FunctionSignatureSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenEffectSpecifiersAndOutput, output, unexpectedAfterOutput - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeInput?.raw, input.raw, @@ -9197,7 +9197,7 @@ public struct GenericArgumentClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenArgumentsAndRightAngleBracket, rightAngleBracket, unexpectedAfterRightAngleBracket - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftAngleBracket?.raw, leftAngleBracket.raw, @@ -9354,7 +9354,7 @@ public struct GenericArgumentSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenArgumentTypeAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeArgumentType?.raw, argumentType.raw, @@ -9478,7 +9478,7 @@ public struct GenericParameterClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericWhereClauseAndRightAngleBracket, rightAngleBracket, unexpectedAfterRightAngleBracket - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftAngleBracket?.raw, leftAngleBracket.raw, @@ -9673,7 +9673,7 @@ public struct GenericParameterSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenInheritedTypeAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAttributes?.raw, attributes?.raw, @@ -9949,7 +9949,7 @@ public struct GenericRequirementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenBodyAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBody?.raw, body.raw, @@ -10065,7 +10065,7 @@ public struct GenericWhereClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenWhereKeywordAndRequirementList, requirementList, unexpectedAfterRequirementList - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeWhereKeyword?.raw, whereKeyword.raw, @@ -10285,7 +10285,7 @@ public struct IfConfigClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenConditionAndElements, elements, unexpectedAfterElements - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforePoundKeyword?.raw, poundKeyword.raw, @@ -10431,7 +10431,7 @@ public struct ImplementsAttributeArgumentsSyntax: SyntaxProtocol, SyntaxHashable unexpectedBetweenDeclBaseNameAndDeclNameArguments, declNameArguments, unexpectedAfterDeclNameArguments - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeType?.raw, type.raw, @@ -10595,7 +10595,7 @@ public struct ImportPathComponentSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndTrailingDot, trailingDot, unexpectedAfterTrailingDot - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeName?.raw, name.raw, @@ -10711,7 +10711,7 @@ public struct InheritedTypeSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenTypeNameAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeTypeName?.raw, typeName.raw, @@ -10827,7 +10827,7 @@ public struct InitializerClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenEqualAndValue, value, unexpectedAfterValue - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeEqual?.raw, equal.raw, @@ -10951,7 +10951,7 @@ public struct InitializesEffectSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenPropertyListAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeInitializesKeyword?.raw, initializesKeyword.raw, @@ -11183,7 +11183,7 @@ public struct KeyPathComponentSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenPeriodAndComponent, component, unexpectedAfterComponent - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforePeriod?.raw, period?.raw, @@ -11291,7 +11291,7 @@ public struct KeyPathOptionalComponentSyntax: SyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeQuestionOrExclamationMark, questionOrExclamationMark, unexpectedAfterQuestionOrExclamationMark))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeQuestionOrExclamationMark, questionOrExclamationMark, unexpectedAfterQuestionOrExclamationMark))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeQuestionOrExclamationMark?.raw, questionOrExclamationMark.raw, unexpectedAfterQuestionOrExclamationMark?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.keyPathOptionalComponent, @@ -11381,7 +11381,7 @@ public struct KeyPathPropertyComponentSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenDeclNameArgumentsAndGenericArgumentClause, genericArgumentClause, unexpectedAfterGenericArgumentClause - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeIdentifier?.raw, identifier.raw, @@ -11523,7 +11523,7 @@ public struct KeyPathSubscriptComponentSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenArgumentListAndRightBracket, rightBracket, unexpectedAfterRightBracket - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftBracket?.raw, leftBracket.raw, @@ -11688,7 +11688,7 @@ public struct LabeledSpecializeEntrySyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenValueAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLabel?.raw, label.raw, @@ -11876,7 +11876,7 @@ public struct LayoutRequirementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenAlignmentAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeTypeIdentifier?.raw, typeIdentifier.raw, @@ -12132,7 +12132,7 @@ public struct MatchingPatternConditionSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenTypeAnnotationAndInitializer, initializer, unexpectedAfterInitializer - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeCaseKeyword?.raw, caseKeyword.raw, @@ -12296,7 +12296,7 @@ public struct MemberDeclBlockSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenMembersAndRightBrace, rightBrace, unexpectedAfterRightBrace - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftBrace?.raw, leftBrace.raw, @@ -12453,7 +12453,7 @@ public struct MemberDeclListItemSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenDeclAndSemicolon, semicolon, unexpectedAfterSemicolon - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeDecl?.raw, decl.raw, @@ -12563,7 +12563,7 @@ public struct MissingSyntax: SyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePlaceholder, placeholder, unexpectedAfterPlaceholder))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePlaceholder, placeholder, unexpectedAfterPlaceholder))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforePlaceholder?.raw, placeholder.raw, unexpectedAfterPlaceholder?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.missing, @@ -12654,7 +12654,7 @@ public struct MultipleTrailingClosureElementSyntax: SyntaxProtocol, SyntaxHashab unexpectedBetweenColonAndClosure, closure, unexpectedAfterClosure - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLabel?.raw, label.raw, @@ -12792,7 +12792,7 @@ public struct ObjCSelectorPieceSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndColon, colon, unexpectedAfterColon - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeName?.raw, name?.raw, @@ -12912,7 +12912,7 @@ public struct OpaqueReturnTypeOfAttributeArgumentsSyntax: SyntaxProtocol, Syntax unexpectedBetweenCommaAndOrdinal, ordinal, unexpectedAfterOrdinal - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeMangledName?.raw, mangledName.raw, @@ -13056,7 +13056,7 @@ public struct OperatorPrecedenceAndTypesSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenPrecedenceGroupAndDesignatedTypes, designatedTypes, unexpectedAfterDesignatedTypes - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeColon?.raw, colon.raw, @@ -13223,7 +13223,7 @@ public struct OptionalBindingConditionSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenTypeAnnotationAndInitializer, initializer, unexpectedAfterInitializer - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBindingKeyword?.raw, bindingKeyword.raw, @@ -13395,7 +13395,7 @@ public struct OriginallyDefinedInArgumentsSyntax: SyntaxProtocol, SyntaxHashable unexpectedBetweenCommaAndPlatforms, platforms, unexpectedAfterPlatforms - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeModuleLabel?.raw, moduleLabel.raw, @@ -13600,7 +13600,7 @@ public struct ParameterClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenParameterListAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, @@ -13811,7 +13811,7 @@ public struct PatternBindingSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenAccessorAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforePattern?.raw, pattern.raw, @@ -14013,7 +14013,7 @@ public struct PoundSourceLocationArgsSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenLineArgColonAndLineNumber, lineNumber, unexpectedAfterLineNumber - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeFileArgLabel?.raw, fileArgLabel.raw, @@ -14243,7 +14243,7 @@ public struct PrecedenceGroupAssignmentSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenColonAndFlag, flag, unexpectedAfterFlag - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAssignmentKeyword?.raw, assignmentKeyword.raw, @@ -14386,7 +14386,7 @@ public struct PrecedenceGroupAssociativitySyntax: SyntaxProtocol, SyntaxHashable unexpectedBetweenColonAndValue, value, unexpectedAfterValue - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAssociativityKeyword?.raw, associativityKeyword.raw, @@ -14525,7 +14525,7 @@ public struct PrecedenceGroupNameElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeName?.raw, name.raw, @@ -14645,7 +14645,7 @@ public struct PrecedenceGroupRelationSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenColonAndOtherNames, otherNames, unexpectedAfterOtherNames - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeHigherThanOrLowerThanKeyword?.raw, higherThanOrLowerThanKeyword.raw, @@ -14808,7 +14808,7 @@ public struct PrimaryAssociatedTypeClauseSyntax: SyntaxProtocol, SyntaxHashable unexpectedBetweenPrimaryAssociatedTypeListAndRightAngleBracket, rightAngleBracket, unexpectedAfterRightAngleBracket - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftAngleBracket?.raw, leftAngleBracket.raw, @@ -14965,7 +14965,7 @@ public struct PrimaryAssociatedTypeSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeName?.raw, name.raw, @@ -15089,7 +15089,7 @@ public struct QualifiedDeclNameSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndArguments, arguments, unexpectedAfterArguments - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBaseType?.raw, baseType?.raw, @@ -15252,7 +15252,7 @@ public struct ReturnClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenArrowAndReturnType, returnType, unexpectedAfterReturnType - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeArrow?.raw, arrow.raw, @@ -15372,7 +15372,7 @@ public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenEqualityTokenAndRightTypeIdentifier, rightTypeIdentifier, unexpectedAfterRightTypeIdentifier - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftTypeIdentifier?.raw, leftTypeIdentifier.raw, @@ -15510,7 +15510,7 @@ public struct SourceFileSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenStatementsAndEOFToken, eofToken, unexpectedAfterEOFToken - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeStatements?.raw, statements.raw, @@ -15637,7 +15637,7 @@ public struct StringSegmentSyntax: SyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeContent, content, unexpectedAfterContent))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeContent, content, unexpectedAfterContent))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeContent?.raw, content.raw, unexpectedAfterContent?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.stringSegment, @@ -15727,7 +15727,7 @@ public struct SwitchCaseLabelSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenCaseItemsAndColon, colon, unexpectedAfterColon - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeCaseKeyword?.raw, caseKeyword.raw, @@ -15930,7 +15930,7 @@ public struct SwitchCaseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenLabelAndStatements, statements, unexpectedAfterStatements - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeUnknownAttr?.raw, unknownAttr?.raw, @@ -16087,7 +16087,7 @@ public struct SwitchDefaultLabelSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenDefaultKeywordAndColon, colon, unexpectedAfterColon - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeDefaultKeyword?.raw, defaultKeyword.raw, @@ -16211,7 +16211,7 @@ public struct TargetFunctionEntrySyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenDeclnameAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLabel?.raw, label.raw, @@ -16383,7 +16383,7 @@ public struct TupleExprElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenExpressionAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLabel?.raw, label?.raw, @@ -16551,7 +16551,7 @@ public struct TuplePatternElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenPatternAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLabelName?.raw, labelName?.raw, @@ -16735,7 +16735,7 @@ public struct TupleTypeElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenInitializerAndTrailingComma, trailingComma, unexpectedAfterTrailingComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeInOut?.raw, inOut?.raw, @@ -16983,7 +16983,7 @@ public struct TypeAnnotationSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenColonAndType, type, unexpectedAfterType - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeColon?.raw, colon.raw, @@ -17099,7 +17099,7 @@ public struct TypeEffectSpecifiersSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenAsyncSpecifierAndThrowsSpecifier, throwsSpecifier, unexpectedAfterThrowsSpecifier - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeAsyncSpecifier?.raw, asyncSpecifier?.raw, @@ -17215,7 +17215,7 @@ public struct TypeInheritanceClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenColonAndInheritedTypeCollection, inheritedTypeCollection, unexpectedAfterInheritedTypeCollection - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeColon?.raw, colon.raw, @@ -17350,7 +17350,7 @@ public struct TypeInitializerClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenEqualAndValue, value, unexpectedAfterValue - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeEqual?.raw, equal.raw, @@ -17470,7 +17470,7 @@ public struct UnavailableFromAsyncArgumentsSyntax: SyntaxProtocol, SyntaxHashabl unexpectedBetweenColonAndMessage, message, unexpectedAfterMessage - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeMessageLabel?.raw, messageLabel.raw, @@ -17612,7 +17612,7 @@ public struct UnderscorePrivateAttributeArgumentsSyntax: SyntaxProtocol, SyntaxH unexpectedBetweenColonAndFilename, filename, unexpectedAfterFilename - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeSourceFileLabel?.raw, sourceFileLabel.raw, @@ -17750,7 +17750,7 @@ public struct VersionComponentSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenPeriodAndNumber, number, unexpectedAfterNumber - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforePeriod?.raw, period.raw, @@ -17868,7 +17868,7 @@ public struct VersionTupleSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenMajorAndComponents, components, unexpectedAfterComponents - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeMajor?.raw, major.raw, @@ -18005,7 +18005,7 @@ public struct WhereClauseSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenWhereKeywordAndGuardResult, guardResult, unexpectedAfterGuardResult - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeWhereKeyword?.raw, whereKeyword.raw, @@ -18121,7 +18121,7 @@ public struct YieldExprListElementSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenExpressionAndComma, comma, unexpectedAfterComma - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeExpression?.raw, expression.raw, @@ -18241,7 +18241,7 @@ public struct YieldListSyntax: SyntaxProtocol, SyntaxHashable { unexpectedBetweenElementListAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxPatternNodes.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxPatternNodes.swift index 67db26c172c..4793a5d30e3 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxPatternNodes.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxPatternNodes.swift @@ -43,7 +43,7 @@ public struct ExpressionPatternSyntax: PatternSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeExpression, expression, unexpectedAfterExpression))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeExpression, expression, unexpectedAfterExpression))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeExpression?.raw, expression.raw, unexpectedAfterExpression?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.expressionPattern, @@ -121,7 +121,7 @@ public struct IdentifierPatternSyntax: PatternSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeIdentifier, identifier, unexpectedAfterIdentifier))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeIdentifier, identifier, unexpectedAfterIdentifier))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeIdentifier?.raw, identifier.raw, unexpectedAfterIdentifier?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.identifierPattern, @@ -207,7 +207,7 @@ public struct IsTypePatternSyntax: PatternSyntaxProtocol, SyntaxHashable { unexpectedBetweenIsKeywordAndType, type, unexpectedAfterType - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeIsKeyword?.raw, isKeyword.raw, @@ -315,7 +315,7 @@ public struct MissingPatternSyntax: PatternSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePlaceholder, placeholder, unexpectedAfterPlaceholder))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePlaceholder, placeholder, unexpectedAfterPlaceholder))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforePlaceholder?.raw, placeholder.raw, unexpectedAfterPlaceholder?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.missingPattern, @@ -406,7 +406,7 @@ public struct TuplePatternSyntax: PatternSyntaxProtocol, SyntaxHashable { unexpectedBetweenElementsAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, @@ -563,7 +563,7 @@ public struct ValueBindingPatternSyntax: PatternSyntaxProtocol, SyntaxHashable { unexpectedBetweenBindingKeywordAndValuePattern, valuePattern, unexpectedAfterValuePattern - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBindingKeyword?.raw, bindingKeyword.raw, @@ -679,7 +679,7 @@ public struct WildcardPatternSyntax: PatternSyntaxProtocol, SyntaxHashable { unexpectedBetweenWildcardAndTypeAnnotation, typeAnnotation, unexpectedAfterTypeAnnotation - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeWildcard?.raw, wildcard.raw, diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxStmtNodes.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxStmtNodes.swift index 1f16edd40b1..437b725b7e8 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxStmtNodes.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxStmtNodes.swift @@ -51,7 +51,7 @@ public struct BreakStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenBreakKeywordAndLabel, label, unexpectedAfterLabel - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBreakKeyword?.raw, breakKeyword.raw, @@ -167,7 +167,7 @@ public struct ContinueStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenContinueKeywordAndLabel, label, unexpectedAfterLabel - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeContinueKeyword?.raw, continueKeyword.raw, @@ -283,7 +283,7 @@ public struct DeferStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenDeferKeywordAndBody, body, unexpectedAfterBody - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeDeferKeyword?.raw, deferKeyword.raw, @@ -399,7 +399,7 @@ public struct DiscardStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenDiscardKeywordAndExpression, expression, unexpectedAfterExpression - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeDiscardKeyword?.raw, discardKeyword.raw, @@ -519,7 +519,7 @@ public struct DoStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenBodyAndCatchClauses, catchClauses, unexpectedAfterCatchClauses - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeDoKeyword?.raw, doKeyword.raw, @@ -668,7 +668,7 @@ public struct ExpressionStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeExpression, expression, unexpectedAfterExpression))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeExpression, expression, unexpectedAfterExpression))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeExpression?.raw, expression.raw, unexpectedAfterExpression?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.expressionStmt, @@ -746,7 +746,7 @@ public struct FallthroughStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeFallthroughKeyword, fallthroughKeyword, unexpectedAfterFallthroughKeyword))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeFallthroughKeyword, fallthroughKeyword, unexpectedAfterFallthroughKeyword))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeFallthroughKeyword?.raw, fallthroughKeyword.raw, unexpectedAfterFallthroughKeyword?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.fallthroughStmt, @@ -864,7 +864,7 @@ public struct ForInStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenWhereClauseAndBody, body, unexpectedAfterBody - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeForKeyword?.raw, forKeyword.raw, @@ -1164,7 +1164,7 @@ public struct GuardStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenElseKeywordAndBody, body, unexpectedAfterBody - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeGuardKeyword?.raw, guardKeyword.raw, @@ -1347,7 +1347,7 @@ public struct LabeledStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenLabelColonAndStatement, statement, unexpectedAfterStatement - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLabelName?.raw, labelName.raw, @@ -1477,7 +1477,7 @@ public struct MissingStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePlaceholder, placeholder, unexpectedAfterPlaceholder))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePlaceholder, placeholder, unexpectedAfterPlaceholder))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforePlaceholder?.raw, placeholder.raw, unexpectedAfterPlaceholder?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.missingStmt, @@ -1572,7 +1572,7 @@ public struct RepeatWhileStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenWhileKeywordAndCondition, condition, unexpectedAfterCondition - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeRepeatKeyword?.raw, repeatKeyword.raw, @@ -1732,7 +1732,7 @@ public struct ReturnStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenReturnKeywordAndExpression, expression, unexpectedAfterExpression - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeReturnKeyword?.raw, returnKeyword.raw, @@ -1848,7 +1848,7 @@ public struct ThrowStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenThrowKeywordAndExpression, expression, unexpectedAfterExpression - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeThrowKeyword?.raw, throwKeyword.raw, @@ -1968,7 +1968,7 @@ public struct WhileStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenConditionsAndBody, body, unexpectedAfterBody - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeWhileKeyword?.raw, whileKeyword.raw, @@ -2167,7 +2167,7 @@ public struct YieldStmtSyntax: StmtSyntaxProtocol, SyntaxHashable { unexpectedBetweenYieldKeywordAndYields, yields, unexpectedAfterYields - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeYieldKeyword?.raw, yieldKeyword.raw, diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxTypeNodes.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxTypeNodes.swift index a09f96540de..8a5ba24270e 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxTypeNodes.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxTypeNodes.swift @@ -55,7 +55,7 @@ public struct ArrayTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenElementTypeAndRightSquare, rightSquare, unexpectedAfterRightSquare - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftSquare?.raw, leftSquare.raw, @@ -197,7 +197,7 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenAttributesAndBaseType, baseType, unexpectedAfterBaseType - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeSpecifier?.raw, specifier?.raw, @@ -346,7 +346,7 @@ public struct ClassRestrictionTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeClassKeyword, classKeyword, unexpectedAfterClassKeyword))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeClassKeyword, classKeyword, unexpectedAfterClassKeyword))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeClassKeyword?.raw, classKeyword.raw, unexpectedAfterClassKeyword?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.classRestrictionType, @@ -424,7 +424,7 @@ public struct CompositionTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeElements, elements, unexpectedAfterElements))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeElements, elements, unexpectedAfterElements))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforeElements?.raw, elements.raw, unexpectedAfterElements?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.compositionType, @@ -529,7 +529,7 @@ public struct ConstrainedSugarTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenSomeOrAnySpecifierAndBaseType, baseType, unexpectedAfterBaseType - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeSomeOrAnySpecifier?.raw, someOrAnySpecifier.raw, @@ -657,7 +657,7 @@ public struct DictionaryTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenValueTypeAndRightSquare, rightSquare, unexpectedAfterRightSquare - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftSquare?.raw, leftSquare.raw, @@ -851,7 +851,7 @@ public struct FunctionTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenEffectSpecifiersAndOutput, output, unexpectedAfterOutput - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, @@ -1052,7 +1052,7 @@ public struct ImplicitlyUnwrappedOptionalTypeSyntax: TypeSyntaxProtocol, SyntaxH unexpectedBetweenWrappedTypeAndExclamationMark, exclamationMark, unexpectedAfterExclamationMark - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeWrappedType?.raw, wrappedType.raw, @@ -1176,7 +1176,7 @@ public struct MemberTypeIdentifierSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndGenericArgumentClause, genericArgumentClause, unexpectedAfterGenericArgumentClause - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBaseType?.raw, baseType.raw, @@ -1340,7 +1340,7 @@ public struct MetatypeTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenPeriodAndTypeOrProtocol, typeOrProtocol, unexpectedAfterTypeOrProtocol - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeBaseType?.raw, baseType.raw, @@ -1470,7 +1470,7 @@ public struct MissingTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { ) { // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. - let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePlaceholder, placeholder, unexpectedAfterPlaceholder))) {(arena, _) in + let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforePlaceholder, placeholder, unexpectedAfterPlaceholder))) { (arena, _) in let layout: [RawSyntax?] = [unexpectedBeforePlaceholder?.raw, placeholder.raw, unexpectedAfterPlaceholder?.raw] let raw = RawSyntax.makeLayout( kind: SyntaxKind.missingType, @@ -1557,7 +1557,7 @@ public struct NamedOpaqueReturnTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenGenericParameterClauseAndBaseType, baseType, unexpectedAfterBaseType - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeGenericParameterClause?.raw, genericParameterClause.raw, @@ -1673,7 +1673,7 @@ public struct OptionalTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenWrappedTypeAndQuestionMark, questionMark, unexpectedAfterQuestionMark - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeWrappedType?.raw, wrappedType.raw, @@ -1789,7 +1789,7 @@ public struct PackExpansionTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenRepeatKeywordAndPatternType, patternType, unexpectedAfterPatternType - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeRepeatKeyword?.raw, repeatKeyword.raw, @@ -1905,7 +1905,7 @@ public struct PackReferenceTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenEachKeywordAndPackType, packType, unexpectedAfterPackType - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeEachKeyword?.raw, eachKeyword.raw, @@ -2021,7 +2021,7 @@ public struct SimpleTypeIdentifierSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenNameAndGenericArgumentClause, genericArgumentClause, unexpectedAfterGenericArgumentClause - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeName?.raw, name.raw, @@ -2137,7 +2137,7 @@ public struct SuppressedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenWithoutTildeAndPatternType, patternType, unexpectedAfterPatternType - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeWithoutTilde?.raw, withoutTilde.raw, @@ -2257,7 +2257,7 @@ public struct TupleTypeSyntax: TypeSyntaxProtocol, SyntaxHashable { unexpectedBetweenElementsAndRightParen, rightParen, unexpectedAfterRightParen - ))) {(arena, _) in + ))) { (arena, _) in let layout: [RawSyntax?] = [ unexpectedBeforeLeftParen?.raw, leftParen.raw, diff --git a/Sources/_SwiftSyntaxTestSupport/IncrementalParseTestUtils.swift b/Sources/_SwiftSyntaxTestSupport/IncrementalParseTestUtils.swift index 4082da63e0a..6f7699bc633 100644 --- a/Sources/_SwiftSyntaxTestSupport/IncrementalParseTestUtils.swift +++ b/Sources/_SwiftSyntaxTestSupport/IncrementalParseTestUtils.swift @@ -135,3 +135,83 @@ public struct ReusedNodeSpec { self.line = line } } + +/// Get `ConcurrentEdits` in source whose edited zones are marked with markers +/// Also extract the markers from source to get original source and edited source +/// +/// `⏩️` is *start marker*, `⏸️` is *separate marker*, `⏪️` is *end marker* +/// Contents between `⏩️` and `⏸️` are source text that before modification, contents +/// betwwen `⏸️` and `⏪️` are source text that after modification +/// i.e. `⏩️foo⏸️bar⏪️`, the original source is `foo` and the edited source is `bar` +public func getEditsAndSources(_ source: String) -> (edits: ConcurrentEdits, orignialSource: Substring, editedSource: Substring) { + var editedSource = Substring() + var originalSource = Substring() + var concurrentEdits: [IncrementalEdit] = [] + + var lastStartIndex = source.startIndex + while let startIndex = source[lastStartIndex...].firstIndex(where: { $0 == "⏩️" }), + let separateIndex = source[startIndex...].firstIndex(where: { $0 == "⏸️" }), + let endIndex = source[separateIndex...].firstIndex(where: { $0 == "⏪️" }) + { + + originalSource += source[lastStartIndex.. String { + guard let replacementAscii = replacementChar.asciiValue else { + fatalError("replacementChar must be an ASCII character") + } + var edits = edits + if concurrent { + XCTAssert(ConcurrentEdits._isValidConcurrentEditArray(edits)) + + // If the edits are concurrent, sorted and not overlapping (as guaranteed by + // the check above, we can apply them sequentially to the string in reverse + // order because later edits don't affect earlier edits. + edits = edits.reversed() + } + var bytes = Array(testString.utf8) + for edit in edits { + assert(edit.endOffset <= bytes.count) + bytes.removeSubrange(edit.offset.. (edits: ConcurrentEdits, orignialSource: Substring, editedSource: Substring) { - var editedSource = Substring() - var originalSource = Substring() - var concurrentEdits: [SourceEdit] = [] - - var lastStartIndex = source.startIndex - while let startIndex = source[lastStartIndex...].firstIndex(where: { $0 == "⏩️" }), - let separateIndex = source[startIndex...].firstIndex(where: { $0 == "⏸️" }), - let endIndex = source[separateIndex...].firstIndex(where: { $0 == "⏪️" }) - { - - originalSource += source[lastStartIndex.. String { - guard let replacementAscii = replacementChar.asciiValue else { - fatalError("replacementChar must be an ASCII character") - } - var edits = edits - if concurrent { - XCTAssert(ConcurrentEdits._isValidConcurrentEditArray(edits)) - - // If the edits are concurrent, sorted and not overlapping (as guaranteed by - // the check above, we can apply them sequentially to the string in reverse - // order because later edits don't affect earlier edits. - edits = edits.reversed() - } - var bytes = Array(testString.utf8) - for edit in edits { - assert(edit.endOffset <= bytes.count) - bytes.removeSubrange(edit.offset.. [IncrementalEdit] { + func getIncrementalEdits() throws -> [IncrementalEditSpec] { let regex = try NSRegularExpression( pattern: "([0-9]+):([0-9]+)-([0-9]+):([0-9]+)=(.*)" ) - var parsedEdits = [IncrementalEdit]() + var parsedEdits = [IncrementalEditSpec]() let editArgs = try self.getValues("-incremental-edit") for edit in editArgs { guard @@ -111,7 +111,7 @@ extension CommandLineArguments { let region = getSourceRegion(match, text: edit) let replacement = match.match(at: 5, text: edit) parsedEdits.append( - IncrementalEdit( + IncrementalEditSpec( region: region, replacement: replacement ) @@ -232,7 +232,7 @@ struct SourceRegion { let endColumn: Int } -struct IncrementalEdit { +struct IncrementalEditSpec { let region: SourceRegion let replacement: String } @@ -312,8 +312,8 @@ func getByteRange( func parseIncrementalEditArguments( args: CommandLineArguments -) throws -> [SourceEdit] { - var edits = [SourceEdit]() +) throws -> [IncrementalEdit] { + var edits = [IncrementalEdit]() let argEdits = try args.getIncrementalEdits() let preEditURL = URL(fileURLWithPath: try args.getRequired("-old-source-file")) @@ -326,7 +326,7 @@ func parseIncrementalEditArguments( argName: "-incremental-edit" ) let replacementLength = argEdit.replacement.utf8.count - edits.append(SourceEdit(range: range, replacementLength: replacementLength)) + edits.append(IncrementalEdit(range: range, replacementLength: replacementLength)) } return edits } diff --git a/Tests/SwiftBasicFormatTest/BasicFormatTests.swift b/Tests/SwiftBasicFormatTest/BasicFormatTests.swift index ca727c91132..c815d9b960e 100644 --- a/Tests/SwiftBasicFormatTest/BasicFormatTests.swift +++ b/Tests/SwiftBasicFormatTest/BasicFormatTests.swift @@ -327,4 +327,18 @@ final class BasicFormatTest: XCTestCase { using: BasicFormat(indentationWidth: .spaces(2)) ) } + + func testClosureExprParam() { + let source = """ + _ = {foo in} + """ + + assertFormatted( + source: source, + expected: """ + _ = { foo in + } + """ + ) + } } diff --git a/Tests/SwiftParserTest/ExpressionTests.swift b/Tests/SwiftParserTest/ExpressionTests.swift index a35d0971ed2..dee4ec33c65 100644 --- a/Tests/SwiftParserTest/ExpressionTests.swift +++ b/Tests/SwiftParserTest/ExpressionTests.swift @@ -1898,7 +1898,7 @@ final class StatementExpressionTests: XCTestCase { ], fixedSource: #""" """ - \({(<#expression#>)}) + \({(<#expression#>) }) """ """# ) diff --git a/Tests/SwiftParserTest/translated/ForeachAsyncTests.swift b/Tests/SwiftParserTest/translated/ForeachAsyncTests.swift index 30c9b0ba773..92dc7be034f 100644 --- a/Tests/SwiftParserTest/translated/ForeachAsyncTests.swift +++ b/Tests/SwiftParserTest/translated/ForeachAsyncTests.swift @@ -138,7 +138,7 @@ final class ForeachAsyncTests: XCTestCase { fixedSource: """ func for_each(r: AsyncRange, iir: AsyncIntRange) async { var sum = 0 - for await i in r {sum = sum + i; + for await i in r { sum = sum + i; } } """ diff --git a/Tests/SwiftParserTest/translated/ForeachTests.swift b/Tests/SwiftParserTest/translated/ForeachTests.swift index 5aa1edcd5b6..aaf869cf8f7 100644 --- a/Tests/SwiftParserTest/translated/ForeachTests.swift +++ b/Tests/SwiftParserTest/translated/ForeachTests.swift @@ -102,7 +102,7 @@ final class ForeachTests: XCTestCase { fixedSource: """ func for_each(r: Range, iir: IntRange) { var sum = 0 - for i in r {sum = sum + i; + for i in r { sum = sum + i; } } """ diff --git a/Tests/SwiftParserTest/translated/RecoveryTests.swift b/Tests/SwiftParserTest/translated/RecoveryTests.swift index a39fc0afcbe..be919f619c8 100644 --- a/Tests/SwiftParserTest/translated/RecoveryTests.swift +++ b/Tests/SwiftParserTest/translated/RecoveryTests.swift @@ -2348,7 +2348,7 @@ final class RecoveryTests: XCTestCase { ), ], fixedSource: """ - func F() { init< >()} )} + func F() { init< >() } )} struct InitializerWithName { init() {} } diff --git a/Tests/SwiftRefactorTest/CallToTrailingClosureTests.swift b/Tests/SwiftRefactorTest/CallToTrailingClosureTests.swift new file mode 100644 index 00000000000..e372401b214 --- /dev/null +++ b/Tests/SwiftRefactorTest/CallToTrailingClosureTests.swift @@ -0,0 +1,237 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftBasicFormat +import SwiftRefactor +import SwiftSyntax +import SwiftSyntaxBuilder +import XCTest +import _SwiftSyntaxTestSupport + +final class CallToTrailingClosuresTest: XCTestCase { + func testSingleClosure() throws { + let baseline: ExprSyntax = """ + foo({ label in + return 1 + }) + """ + + let expected: ExprSyntax = """ + foo { label in + return 1 + } + """ + + try assertRefactorCall(baseline, expected: expected) + } + + func testSingleNamedClosure() throws { + let baseline: ExprSyntax = """ + foo(arg: { label in + return 1 + }) + """ + + let expected: ExprSyntax = """ + foo { label in + return 1 + } + """ + + try assertRefactorCall(baseline, expected: expected) + } + + func testSuffixClosure() throws { + let baseline: ExprSyntax = """ + foo(1, { label in + return 1 + }) + """ + + let expected: ExprSyntax = """ + foo(1) { label in + return 1 + } + """ + + try assertRefactorCall(baseline, expected: expected) + } + + func testSuffixClosures() throws { + let baseline: ExprSyntax = """ + foo({ label in + return 1 + }, 1, { label2 in + return 2 + }, { label3 in + return 3 + }, named: { label4 in + return 4 + }) + """ + + // TODO: The ident here is not great. + // https://github.com/apple/swift-syntax/issues/1473 + let expected: ExprSyntax = """ + foo({ label in + return 1 + }, 1) { label2 in + return 2 + } _: { label3 in + return 3 + } named: { label4 in + return 4 + } + """ + + try assertRefactorCall(baseline, expected: expected) + } + + func testSomeSuffixClosures() throws { + let baseline: ExprSyntax = """ + foo({ label in + return 1 + }, 1, { label2 in + return 2 + }, { label3 in + return 3 + }, named: { label4 in + return 4 + }) + """ + + // TODO: BasicFormat is pretty messed up here + let expected: ExprSyntax = """ + foo({ label in + return 1 + }, 1, { label2 in + return 2 + }) { label3 in + return 3 + } named: { label4 in + return 4 + } + """ + + try assertRefactorCall(baseline, startAtArgument: 3, expected: expected) + } + + func testNoArgs() throws { + let baseline: ExprSyntax = """ + foo() + """ + + try assertRefactorCall(baseline, expected: nil) + } + + func testNonSuffixClosure() throws { + let baseline: ExprSyntax = """ + foo({ _ in }, 1) + """ + + try assertRefactorCall(baseline, expected: nil) + } + + func testExistingTrailingClosure() throws { + let baseline: ExprSyntax = """ + foo({ _ in }) { _ in } + """ + + try assertRefactorCall(baseline, expected: nil) + } + + func testExistingAdditionalTrailingClosure() throws { + let baseline = ExprSyntax( + """ + foo({ _ in }) { _ in + } another: { _ in + } + """ + ) + .cast(FunctionCallExprSyntax.self) + .with(\.trailingClosure, nil) + + try assertRefactorCall(ExprSyntax(baseline), expected: nil) + } + + func testMissingParens() throws { + let baseline = ExprSyntax( + """ + foo(1, { label in + return 1 + }) + """ + ) + .cast(FunctionCallExprSyntax.self) + .with(\.leftParen, nil) + .with(\.rightParen, nil) + + try assertRefactorCall(ExprSyntax(baseline), expected: nil) + } + + func testBadContext() throws { + try assertRefactorCall("foo({ _ in })", startAtArgument: 1, expected: nil) + } + + func testSingleClosureComments() throws { + let baseline: ExprSyntax = """ + /*c1*/foo/*c2*/(/*c3*/1/*c4*/, /*c5*/arg/*c6*/:/*c7*/ {/*c8*/ label in + return 1 + /*c9*/}/*c10*/)/*c11*/ + """ + + let expected: ExprSyntax = """ + /*c1*/foo/*c2*/(/*c3*/1/*c4*/) /*c5*/ /*c6*//*c7*/ {/*c8*/ label in + return 1 + /*c9*/}/*c10*//*c11*/ + """ + + try assertRefactorCall(baseline, expected: expected) + } + + func testTrailingClosureComments() throws { + let baseline: ExprSyntax = """ + /*c1*/foo/*c2*/(/*c3*/1/*c4*/, /*c5*/arg/*c6*/: /*c7*/{/*c8*/ label in + return 1 + /*c9*/}/*c10*/, /*c11*/named/*c12*/: /*c13*/{/*c14*/ label2 in + return 2 + /*c15*/}/*c16*/)/*c17*/ + """ + + let expected: ExprSyntax = """ + /*c1*/foo/*c2*/(/*c3*/1/*c4*/) /*c5*/ /*c6*/ /*c7*/{/*c8*/ label in + return 1 + /*c9*/}/*c10*/ /*c11*/ named/*c12*/: /*c13*/ {/*c14*/ label2 in + return 2 + /*c15*/}/*c16*//*c17*/ + """ + + try assertRefactorCall(baseline, expected: expected) + } +} + +fileprivate func assertRefactorCall( + _ callExpr: ExprSyntax, + startAtArgument: Int = 0, + expected: ExprSyntax?, + file: StaticString = #file, + line: UInt = #line +) throws { + try assertRefactor( + callExpr, + context: CallToTrailingClosures.Context(startAtArgument: startAtArgument), + provider: CallToTrailingClosures.self, + expected: expected, + file: file, + line: line + ) +} diff --git a/Tests/SwiftRefactorTest/ExpandEditorPlaceholderTests.swift b/Tests/SwiftRefactorTest/ExpandEditorPlaceholderTests.swift new file mode 100644 index 00000000000..0bab9f931e3 --- /dev/null +++ b/Tests/SwiftRefactorTest/ExpandEditorPlaceholderTests.swift @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftBasicFormat +import SwiftRefactor +import SwiftSyntax +import SwiftSyntaxBuilder +import XCTest +import _SwiftSyntaxTestSupport + +final class ExpandEditorPlaceholderTest: XCTestCase { + func testSimple() throws { + try assertRefactorPlaceholder("displayOnly", expected: "displayOnly") + try assertRefactorPlaceholder("T##typed", expected: "typed") + try assertRefactorPlaceholder("T##displayAndType##Int", expected: "Int") + try assertRefactorPlaceholder("T##bothTypes##Int##BetterInt", expected: "BetterInt") + try assertRefactorPlaceholder("T##bothTypesFirstEmpty####BetterInt", expected: "BetterInt") + } + + func testEmpty() throws { + try assertRefactorPlaceholder("", expected: "") + try assertRefactorPlaceholder("T##", expected: "") + try assertRefactorPlaceholder("T##displayEmptyType##", expected: "displayEmptyType") + try assertRefactorPlaceholder("T####EmptyDisplay", expected: "EmptyDisplay") + try assertRefactorPlaceholder("T######EmptyTypeAndDisplay", expected: "EmptyTypeAndDisplay") + try assertRefactorPlaceholder("T##bothTypesFirstNotEmpty##Int##", expected: "Int") + try assertRefactorPlaceholder("T##bothTypesEmpty####", expected: "bothTypesEmpty") + } + + func testVoidClosure() throws { + let expected = """ + { + \(ExpandEditorPlaceholder.wrapInPlaceholder("T##code##Void")) + } + """ + try assertRefactorPlaceholder("T##display##() -> Void", expected: expected) + } + + func testTypedReturnClosure() throws { + let expected = """ + { + \(ExpandEditorPlaceholder.wrapInPlaceholder("T##Int##Int")) + } + """ + try assertRefactorPlaceholder("T##display##() -> Int", expected: expected) + } + + func testClosureWithArg() throws { + let expected = """ + { arg in + \(ExpandEditorPlaceholder.wrapInPlaceholder("T##Int##Int")) + } + """ + try assertRefactorPlaceholder("T##display##(arg: String) -> Int", expected: expected) + try assertRefactorPlaceholder("T##display##(_ arg: String) -> Int", expected: expected) + } + + func testClosureWithMultipleArgs() throws { + let expected = """ + { arg, arg2 in + \(ExpandEditorPlaceholder.wrapInPlaceholder("T##Int##Int")) + } + """ + try assertRefactorPlaceholder("T##display##(arg: String, arg2: String) -> Int", expected: expected) + } + + func testSimpleComments() throws { + let placeholder = ExpandEditorPlaceholder.wrapInPlaceholder("simple") + try assertRefactorPlaceholder("/*c1*/\(placeholder)/*c2*/", wrap: false, expected: "/*c1*/simple/*c2*/") + } + + func testClosureComments() throws { + let placeholder = ExpandEditorPlaceholder.wrapInPlaceholder("T##display##(arg: String) -> Int") + let expected = """ + /*c1*/{ arg in + \(ExpandEditorPlaceholder.wrapInPlaceholder("T##Int##Int")) + }/*c2*/ + """ + try assertRefactorPlaceholder("/*c1*/\(placeholder)/*c2*/", wrap: false, expected: expected) + } +} + +fileprivate func assertRefactorPlaceholder( + _ placeholder: String, + wrap: Bool = true, + expected: String, + file: StaticString = #file, + line: UInt = #line +) throws { + let token: TokenSyntax + if wrap { + token = "\(raw: ExpandEditorPlaceholder.wrapInPlaceholder(placeholder))" + } else { + let expr: ExprSyntax = "\(raw: placeholder)" + token = try XCTUnwrap(expr.as(EditorPlaceholderExprSyntax.self)?.identifier, file: file, line: line) + } + + try assertRefactor(token, context: (), provider: ExpandEditorPlaceholder.self, expected: [SourceEdit.replace(token, with: expected)], file: file, line: line) +} diff --git a/Tests/SwiftRefactorTest/ExpandEditorPlaceholdersTests.swift b/Tests/SwiftRefactorTest/ExpandEditorPlaceholdersTests.swift new file mode 100644 index 00000000000..2f11dbaf5ca --- /dev/null +++ b/Tests/SwiftRefactorTest/ExpandEditorPlaceholdersTests.swift @@ -0,0 +1,131 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftBasicFormat +import SwiftParser +import SwiftRefactor +import SwiftSyntax +import SwiftSyntaxBuilder +import XCTest +import _SwiftSyntaxTestSupport + +fileprivate let closurePlaceholder = ExpandEditorPlaceholder.wrapInPlaceholder("T##closure##() -> Void") +fileprivate let voidPlaceholder = ExpandEditorPlaceholder.wrapInPlaceholder("T##code##Void") +fileprivate let intPlaceholder = ExpandEditorPlaceholder.wrapInPlaceholder("T##Int##Int") + +final class ExpandEditorPlaceholdersTest: XCTestCase { + func testSingleClosureArg() throws { + let baseline = "call(\(closurePlaceholder))" + + let expected: String = """ + call { + \(voidPlaceholder) + } + """ + + try assertRefactorPlaceholderCall(baseline, expected: expected) + } + + func testSingleNonClosureArg() throws { + try assertRefactorPlaceholderToken("call(\(intPlaceholder))", expected: "Int") + } + + func testTypeForExpansionPreferred() throws { + let placeholder = ExpandEditorPlaceholder.wrapInPlaceholder("T##closure##BadType##() -> Int") + let baseline = "call(\(placeholder))" + + let expected: String = """ + call { + \(intPlaceholder) + } + """ + + try assertRefactorPlaceholderCall(baseline, expected: expected) + } + + func testMultipleClosureArgs() throws { + let baseline = "call(arg1: \(closurePlaceholder), arg2: \(closurePlaceholder))" + + let expected: String = """ + call { + \(voidPlaceholder) + } arg2: { + \(voidPlaceholder) + } + """ + + try assertRefactorPlaceholderCall(baseline, expected: expected) + try assertRefactorPlaceholderCall(baseline, placeholder: 1, expected: expected) + } + + func testNonClosureAfterClosure() throws { + let baseline = "call(arg1: \(closurePlaceholder), arg2: \(intPlaceholder))" + + let expected: String = """ + { + \(voidPlaceholder) + } + """ + + try assertRefactorPlaceholderToken(baseline, expected: expected) + } + + func testComments() throws { + let baseline = """ + /*c1*/foo/*c2*/(/*c3*/arg/*c4*/: /*c5*/\(closurePlaceholder)/*c6*/,/*c7*/ + /*c8*/\(closurePlaceholder)/*c9*/)/*c10*/ + """ + + // TODO: Should we remove whitespace from the merged trivia? The space + // between c2 and c3 is the one added for the `{`. The space between c4 + // and c5 is the space between the `:` and c5 (added by merging the + // colon's trivia since it was removed). + let expected: String = """ + /*c1*/foo/*c2*/ /*c3*//*c4*/ /*c5*/{ + \(voidPlaceholder) + }/*c6*//*c7*/ _: + /*c8*/{ + \(voidPlaceholder) + }/*c9*//*c10*/ + """ + + try assertRefactorPlaceholderCall(baseline, placeholder: 1, expected: expected) + } +} + +fileprivate func assertRefactorPlaceholderCall( + _ expr: String, + placeholder: Int = 0, + expected: String, + file: StaticString = #file, + line: UInt = #line +) throws { + let call = try XCTUnwrap(ExprSyntax("\(raw: expr)").as(FunctionCallExprSyntax.self), file: file, line: line) + let arg = try XCTUnwrap(call.argumentList[placeholder].as(TupleExprElementSyntax.self), file: file, line: line) + let token: TokenSyntax = try XCTUnwrap(arg.expression.as(EditorPlaceholderExprSyntax.self), file: file, line: line).identifier + + try assertRefactor(token, context: (), provider: ExpandEditorPlaceholders.self, expected: [SourceEdit.replace(call, with: expected)], file: file, line: line) +} + +fileprivate func assertRefactorPlaceholderToken( + _ expr: String, + placeholder: Int = 0, + expected: String, + file: StaticString = #file, + line: UInt = #line +) throws { + let call = try XCTUnwrap(ExprSyntax("\(raw: expr)").as(FunctionCallExprSyntax.self), file: file, line: line) + let arg = try XCTUnwrap(call.argumentList[placeholder].as(TupleExprElementSyntax.self), file: file, line: line) + let token: TokenSyntax = try XCTUnwrap(arg.expression.as(EditorPlaceholderExprSyntax.self), file: file, line: line).identifier + + try assertRefactor(token, context: (), provider: ExpandEditorPlaceholders.self, expected: [SourceEdit.replace(token, with: expected)], file: file, line: line) +} diff --git a/Tests/SwiftRefactorTest/FormatRawStringLiteral.swift b/Tests/SwiftRefactorTest/FormatRawStringLiteral.swift index ba1354ae925..72c2b53ad49 100644 --- a/Tests/SwiftRefactorTest/FormatRawStringLiteral.swift +++ b/Tests/SwiftRefactorTest/FormatRawStringLiteral.swift @@ -34,8 +34,7 @@ final class FormatRawStringLiteralTest: XCTestCase { for (line, literal, expectation) in tests { let literal = try XCTUnwrap(StringLiteralExprSyntax.parseWithoutDiagnostics(from: literal)) let expectation = try XCTUnwrap(StringLiteralExprSyntax.parseWithoutDiagnostics(from: expectation)) - let refactored = try XCTUnwrap(FormatRawStringLiteral.refactor(syntax: literal)) - assertStringsEqualWithDiff(refactored.description, expectation.description, line: UInt(line)) + try assertRefactor(literal, context: (), provider: FormatRawStringLiteral.self, expected: expectation, line: UInt(line)) } } } diff --git a/Tests/SwiftRefactorTest/MigrateToNewIfLetSyntax.swift b/Tests/SwiftRefactorTest/MigrateToNewIfLetSyntax.swift index 14b1de3f80e..2af5cd3424c 100644 --- a/Tests/SwiftRefactorTest/MigrateToNewIfLetSyntax.swift +++ b/Tests/SwiftRefactorTest/MigrateToNewIfLetSyntax.swift @@ -17,32 +17,6 @@ import SwiftSyntaxBuilder import XCTest import _SwiftSyntaxTestSupport -func assertRefactorIfLet( - _ syntax: ExprSyntax, - expected: ExprSyntax, - file: StaticString = #file, - line: UInt = #line -) throws { - let ifExpr = try XCTUnwrap( - syntax.as(IfExprSyntax.self), - file: file, - line: line - ) - - let refactored = try XCTUnwrap( - MigrateToNewIfLetSyntax.refactor(syntax: ifExpr), - file: file, - line: line - ) - - assertStringsEqualWithDiff( - expected.description, - refactored.description, - file: file, - line: line - ) -} - final class MigrateToNewIfLetSyntaxTest: XCTestCase { func testRefactoring() throws { let baselineSyntax: ExprSyntax = """ @@ -53,7 +27,7 @@ final class MigrateToNewIfLetSyntaxTest: XCTestCase { if let x {} """ - try assertRefactorIfLet(baselineSyntax, expected: expectedSyntax) + try assertRefactor(baselineSyntax, context: (), provider: MigrateToNewIfLetSyntax.self, expected: expectedSyntax) } func testIdempotence() throws { @@ -65,8 +39,7 @@ final class MigrateToNewIfLetSyntaxTest: XCTestCase { if let x {} """ - try assertRefactorIfLet(baselineSyntax, expected: expectedSyntax) - try assertRefactorIfLet(expectedSyntax, expected: expectedSyntax) + try assertRefactor(baselineSyntax, context: (), provider: MigrateToNewIfLetSyntax.self, expected: expectedSyntax) } func testMultiBinding() throws { @@ -78,7 +51,7 @@ final class MigrateToNewIfLetSyntaxTest: XCTestCase { if let x, var y, let z {} """ - try assertRefactorIfLet(baselineSyntax, expected: expectedSyntax) + try assertRefactor(baselineSyntax, context: (), provider: MigrateToNewIfLetSyntax.self, expected: expectedSyntax) } func testMixedBinding() throws { @@ -90,7 +63,7 @@ final class MigrateToNewIfLetSyntaxTest: XCTestCase { if let x, var y = x, let z = y.w {} """ - try assertRefactorIfLet(baselineSyntax, expected: expectedSyntax) + try assertRefactor(baselineSyntax, context: (), provider: MigrateToNewIfLetSyntax.self, expected: expectedSyntax) } func testConditions() throws { @@ -102,7 +75,7 @@ final class MigrateToNewIfLetSyntaxTest: XCTestCase { if let x = x + 1, x == x, !x {} """ - try assertRefactorIfLet(baselineSyntax, expected: expectedSyntax) + try assertRefactor(baselineSyntax, context: (), provider: MigrateToNewIfLetSyntax.self, expected: expectedSyntax) } func testWhitespaceNormalization() throws { @@ -114,7 +87,7 @@ final class MigrateToNewIfLetSyntaxTest: XCTestCase { if let x, let y {} """ - try assertRefactorIfLet(baselineSyntax, expected: expectedSyntax) + try assertRefactor(baselineSyntax, context: (), provider: MigrateToNewIfLetSyntax.self, expected: expectedSyntax) } func testIfStmt() throws { @@ -127,6 +100,6 @@ final class MigrateToNewIfLetSyntaxTest: XCTestCase { """ let exprStmt = try XCTUnwrap(baselineSyntax.as(ExpressionStmtSyntax.self)) - try assertRefactorIfLet(exprStmt.expression, expected: expectedSyntax) + try assertRefactor(exprStmt.expression, context: (), provider: MigrateToNewIfLetSyntax.self, expected: expectedSyntax) } } diff --git a/Tests/SwiftRefactorTest/OpaqueParameterToGeneric.swift b/Tests/SwiftRefactorTest/OpaqueParameterToGeneric.swift index 5c5f9ae41db..c78bba9ce75 100644 --- a/Tests/SwiftRefactorTest/OpaqueParameterToGeneric.swift +++ b/Tests/SwiftRefactorTest/OpaqueParameterToGeneric.swift @@ -33,9 +33,7 @@ final class OpaqueParameterToGenericTest: XCTestCase { ) -> some Equatable { } """ - let refactored = try XCTUnwrap(OpaqueParameterToGeneric.refactor(syntax: baseline)) - - assertStringsEqualWithDiff(expected.description, refactored.description) + try assertRefactor(baseline, context: (), provider: OpaqueParameterToGeneric.self, expected: expected) } func testRefactoringInit() throws { @@ -53,9 +51,7 @@ final class OpaqueParameterToGenericTest: XCTestCase { ) { } """ - let refactored = try XCTUnwrap(OpaqueParameterToGeneric.refactor(syntax: baseline)) - - assertStringsEqualWithDiff(expected.description, refactored.description) + try assertRefactor(baseline, context: (), provider: OpaqueParameterToGeneric.self, expected: expected) } func testRefactoringSubscript() throws { @@ -67,8 +63,6 @@ final class OpaqueParameterToGenericTest: XCTestCase { subscript(index: T1) -> String """ - let refactored = try XCTUnwrap(OpaqueParameterToGeneric.refactor(syntax: baseline)) - - assertStringsEqualWithDiff(expected.description, refactored.description) + try assertRefactor(baseline, context: (), provider: OpaqueParameterToGeneric.self, expected: expected) } } diff --git a/Tests/SwiftRefactorTest/RefactorTestUtils.swift b/Tests/SwiftRefactorTest/RefactorTestUtils.swift new file mode 100644 index 00000000000..98adebe58e4 --- /dev/null +++ b/Tests/SwiftRefactorTest/RefactorTestUtils.swift @@ -0,0 +1,148 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftBasicFormat +import SwiftRefactor +import SwiftSyntax +import SwiftSyntaxBuilder +import XCTest +import _SwiftSyntaxTestSupport + +func assertRefactor( + _ input: R.Input, + context: R.Context, + provider: R.Type, + expected: [SourceEdit], + file: StaticString = #file, + line: UInt = #line +) throws { + let edits = R.textRefactor(syntax: input, in: context) + guard !edits.isEmpty else { + if !expected.isEmpty { + XCTFail( + """ + Refactoring produced empty result, expected: + \(expected) + """, + file: file, + line: line + ) + } + return + } + + if edits.count != expected.count { + XCTFail( + """ + Refactoring produced incorrect number of edits, expected \(expected.count) not \(edits.count). + + Actual: + \(edits.map({ $0.debugDescription }).joined(separator: "\n")) + + Expected: + \(expected.map({ $0.debugDescription }).joined(separator: "\n")) + + """, + file: file, + line: line + ) + return + } + + for (actualEdit, expectedEdit) in zip(edits, expected) { + XCTAssertEqual( + actualEdit, + expectedEdit, + "Incorrect edit, expected \(expectedEdit.debugDescription) but actual was \(actualEdit.debugDescription)", + file: file, + line: line + ) + assertStringsEqualWithDiff( + actualEdit.replacement, + expectedEdit.replacement, + file: file, + line: line + ) + } +} + +func assertRefactor( + _ input: R.Input, + context: R.Context, + provider: R.Type, + expected: R.Output?, + file: StaticString = #file, + line: UInt = #line +) throws { + let refactored = R.refactor(syntax: input, in: context) + guard let refactored = refactored else { + if expected != nil { + XCTFail( + """ + Refactoring produced nil result, expected: + \(expected?.description ?? "") + """, + file: file, + line: line + ) + } + return + } + guard let expected = expected else { + XCTFail( + """ + Expected nil result, actual: + \(refactored.description) + """, + file: file, + line: line + ) + return + } + + assertStringsEqualWithDiff( + refactored.description, + expected.description, + file: file, + line: line + ) +} + +func assertRefactor( + _ input: I, + context: R.Context, + provider: R.Type, + expected: [SourceEdit], + file: StaticString = #file, + line: UInt = #line +) throws { + let castInput = try XCTUnwrap(input.as(R.Input.self)) + try assertRefactor(castInput, context: context, provider: provider, expected: expected, file: file, line: line) +} + +func assertRefactor( + _ input: I, + context: R.Context, + provider: R.Type, + expected: E?, + file: StaticString = #file, + line: UInt = #line +) throws { + let castInput = try XCTUnwrap(input.as(R.Input.self)) + let castExpected: R.Output? + if let expected = expected { + castExpected = try XCTUnwrap(expected.as(R.Output.self)) + } else { + castExpected = nil + } + try assertRefactor(castInput, context: context, provider: provider, expected: castExpected, file: file, line: line) +} diff --git a/Tests/SwiftRefactorTest/ReformatIntegerLiteral.swift b/Tests/SwiftRefactorTest/ReformatIntegerLiteral.swift index c3958eb8fe6..ed48f878582 100644 --- a/Tests/SwiftRefactorTest/ReformatIntegerLiteral.swift +++ b/Tests/SwiftRefactorTest/ReformatIntegerLiteral.swift @@ -47,8 +47,7 @@ final class ReformatIntegerLiteralTest: XCTestCase { ] for (line, literal, expectation) in tests { - let refactored = try XCTUnwrap(AddSeparatorsToIntegerLiteral.refactor(syntax: literal)) - assertStringsEqualWithDiff(refactored.description, expectation.description, line: UInt(line)) + try assertRefactor(literal, context: (), provider: AddSeparatorsToIntegerLiteral.self, expected: expectation, line: UInt(line)) } } @@ -72,8 +71,7 @@ final class ReformatIntegerLiteralTest: XCTestCase { ] for (line, literal, expectation) in tests { - let refactored = try XCTUnwrap(RemoveSeparatorsFromIntegerLiteral.refactor(syntax: literal)) - assertStringsEqualWithDiff(refactored.description, expectation.description, line: UInt(line)) + try assertRefactor(literal, context: (), provider: RemoveSeparatorsFromIntegerLiteral.self, expected: expectation, line: UInt(line)) } } } diff --git a/Tests/SwiftSyntaxBuilderTest/ClosureExprTests.swift b/Tests/SwiftSyntaxBuilderTest/ClosureExprTests.swift index 8416f06abfa..e9df80190dd 100644 --- a/Tests/SwiftSyntaxBuilderTest/ClosureExprTests.swift +++ b/Tests/SwiftSyntaxBuilderTest/ClosureExprTests.swift @@ -29,7 +29,7 @@ final class ClosureExprTests: XCTestCase { assertBuildResult( buildable, """ - {area in + { area in } """ ) @@ -52,7 +52,7 @@ final class ClosureExprTests: XCTestCase { assertBuildResult( buildable, """ - {area async throws in + { area async throws in } """ ) diff --git a/Tests/SwiftSyntaxTest/SequentialToConcurrentEditTranslationTests.swift b/Tests/SwiftSyntaxTest/SequentialToConcurrentEditTranslationTests.swift index b6bc87d55e8..974d6d01f52 100644 --- a/Tests/SwiftSyntaxTest/SequentialToConcurrentEditTranslationTests.swift +++ b/Tests/SwiftSyntaxTest/SequentialToConcurrentEditTranslationTests.swift @@ -33,8 +33,8 @@ let longString = """ /// 2. applying the `sequential` and concurrent edits to `testString` results /// in the same post-edit string func verifySequentialToConcurrentTranslation( - _ sequential: [SourceEdit], - _ expectedConcurrent: [SourceEdit], + _ sequential: [IncrementalEdit], + _ expectedConcurrent: [IncrementalEdit], testString: String = longString ) { let concurrent = ConcurrentEdits(fromSequential: sequential) @@ -54,8 +54,8 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { XCTAssertThrowsError( try { try ConcurrentEdits(concurrent: [ - SourceEdit(offset: 5, length: 1, replacementLength: 0), - SourceEdit(offset: 5, length: 1, replacementLength: 0), + IncrementalEdit(offset: 5, length: 1, replacementLength: 0), + IncrementalEdit(offset: 5, length: 1, replacementLength: 0), ]) }() ) @@ -64,10 +64,10 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { func testSingleEdit1() { verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 1, replacementLength: 0) + IncrementalEdit(offset: 5, length: 1, replacementLength: 0) ], [ - SourceEdit(offset: 5, length: 1, replacementLength: 0) + IncrementalEdit(offset: 5, length: 1, replacementLength: 0) ] ) } @@ -75,10 +75,10 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { func testSingleEdit2() { verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 0, replacementLength: 1) + IncrementalEdit(offset: 5, length: 0, replacementLength: 1) ], [ - SourceEdit(offset: 5, length: 0, replacementLength: 1) + IncrementalEdit(offset: 5, length: 0, replacementLength: 1) ] ) } @@ -86,12 +86,12 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { func testTwoNonOverlappingDeletesInFrontToBackOrder() { verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 1, replacementLength: 0), - SourceEdit(offset: 10, length: 2, replacementLength: 0), + IncrementalEdit(offset: 5, length: 1, replacementLength: 0), + IncrementalEdit(offset: 10, length: 2, replacementLength: 0), ], [ - SourceEdit(offset: 5, length: 1, replacementLength: 0), - SourceEdit(offset: 11, length: 2, replacementLength: 0), + IncrementalEdit(offset: 5, length: 1, replacementLength: 0), + IncrementalEdit(offset: 11, length: 2, replacementLength: 0), ] ) } @@ -99,12 +99,12 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { func testTwoNonOverlappingDeletesInBackToFrontOrder() { verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 10, length: 2, replacementLength: 0), - SourceEdit(offset: 5, length: 1, replacementLength: 0), + IncrementalEdit(offset: 10, length: 2, replacementLength: 0), + IncrementalEdit(offset: 5, length: 1, replacementLength: 0), ], [ - SourceEdit(offset: 5, length: 1, replacementLength: 0), - SourceEdit(offset: 10, length: 2, replacementLength: 0), + IncrementalEdit(offset: 5, length: 1, replacementLength: 0), + IncrementalEdit(offset: 10, length: 2, replacementLength: 0), ] ) } @@ -112,12 +112,12 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { func testTwoNonOverlappingInsertionsInFrontToBackOrder() { verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 0, replacementLength: 2), - SourceEdit(offset: 10, length: 0, replacementLength: 3), + IncrementalEdit(offset: 5, length: 0, replacementLength: 2), + IncrementalEdit(offset: 10, length: 0, replacementLength: 3), ], [ - SourceEdit(offset: 5, length: 0, replacementLength: 2), - SourceEdit(offset: 8, length: 0, replacementLength: 3), + IncrementalEdit(offset: 5, length: 0, replacementLength: 2), + IncrementalEdit(offset: 8, length: 0, replacementLength: 3), ] ) } @@ -125,12 +125,12 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { func testTwoNonOverlappingInsertionsInBackToFrontOrder() { verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 10, length: 0, replacementLength: 3), - SourceEdit(offset: 5, length: 0, replacementLength: 2), + IncrementalEdit(offset: 10, length: 0, replacementLength: 3), + IncrementalEdit(offset: 5, length: 0, replacementLength: 2), ], [ - SourceEdit(offset: 5, length: 0, replacementLength: 2), - SourceEdit(offset: 10, length: 0, replacementLength: 3), + IncrementalEdit(offset: 5, length: 0, replacementLength: 2), + IncrementalEdit(offset: 10, length: 0, replacementLength: 3), ] ) } @@ -138,12 +138,12 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { func testTwoNonOverlappingReplacementsInFrontToBackOrder() { verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 4, replacementLength: 2), - SourceEdit(offset: 20, length: 5, replacementLength: 3), + IncrementalEdit(offset: 5, length: 4, replacementLength: 2), + IncrementalEdit(offset: 20, length: 5, replacementLength: 3), ], [ - SourceEdit(offset: 5, length: 4, replacementLength: 2), - SourceEdit(offset: 22, length: 5, replacementLength: 3), + IncrementalEdit(offset: 5, length: 4, replacementLength: 2), + IncrementalEdit(offset: 22, length: 5, replacementLength: 3), ] ) } @@ -151,12 +151,12 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { func testTwoNonOverlappingReplacementsInBackToFrontOrder() { verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 20, length: 5, replacementLength: 3), - SourceEdit(offset: 5, length: 4, replacementLength: 2), + IncrementalEdit(offset: 20, length: 5, replacementLength: 3), + IncrementalEdit(offset: 5, length: 4, replacementLength: 2), ], [ - SourceEdit(offset: 5, length: 4, replacementLength: 2), - SourceEdit(offset: 20, length: 5, replacementLength: 3), + IncrementalEdit(offset: 5, length: 4, replacementLength: 2), + IncrementalEdit(offset: 20, length: 5, replacementLength: 3), ] ) } @@ -164,16 +164,16 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { func testMultipleNonOverlappingEdits() { verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 0, length: 6, replacementLength: 0), - SourceEdit(offset: 15, length: 7, replacementLength: 9), - SourceEdit(offset: 10, length: 0, replacementLength: 3), - SourceEdit(offset: 30, length: 2, replacementLength: 2), + IncrementalEdit(offset: 0, length: 6, replacementLength: 0), + IncrementalEdit(offset: 15, length: 7, replacementLength: 9), + IncrementalEdit(offset: 10, length: 0, replacementLength: 3), + IncrementalEdit(offset: 30, length: 2, replacementLength: 2), ], [ - SourceEdit(offset: 0, length: 6, replacementLength: 0), - SourceEdit(offset: 16, length: 0, replacementLength: 3), - SourceEdit(offset: 21, length: 7, replacementLength: 9), - SourceEdit(offset: 31, length: 2, replacementLength: 2), + IncrementalEdit(offset: 0, length: 6, replacementLength: 0), + IncrementalEdit(offset: 16, length: 0, replacementLength: 3), + IncrementalEdit(offset: 21, length: 7, replacementLength: 9), + IncrementalEdit(offset: 31, length: 2, replacementLength: 2), ] ) } @@ -183,11 +183,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { // [--- edit2 ----] verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 10, length: 1, replacementLength: 3), - SourceEdit(offset: 5, length: 5, replacementLength: 1), + IncrementalEdit(offset: 10, length: 1, replacementLength: 3), + IncrementalEdit(offset: 5, length: 5, replacementLength: 1), ], [ - SourceEdit(offset: 5, length: 6, replacementLength: 4) + IncrementalEdit(offset: 5, length: 6, replacementLength: 4) ] ) } @@ -197,11 +197,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { // [--- edit2 ----] verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 10, length: 1, replacementLength: 3), - SourceEdit(offset: 5, length: 5, replacementLength: 0), + IncrementalEdit(offset: 10, length: 1, replacementLength: 3), + IncrementalEdit(offset: 5, length: 5, replacementLength: 0), ], [ - SourceEdit(offset: 5, length: 6, replacementLength: 3) + IncrementalEdit(offset: 5, length: 6, replacementLength: 3) ] ) } @@ -211,11 +211,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { // [--- edit2 ----] verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 3, replacementLength: 1), - SourceEdit(offset: 4, length: 2, replacementLength: 2), + IncrementalEdit(offset: 5, length: 3, replacementLength: 1), + IncrementalEdit(offset: 4, length: 2, replacementLength: 2), ], [ - SourceEdit(offset: 4, length: 4, replacementLength: 2) + IncrementalEdit(offset: 4, length: 4, replacementLength: 2) ] ) } @@ -225,11 +225,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { // [------- edit2 --------] verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 3, replacementLength: 1), - SourceEdit(offset: 4, length: 4, replacementLength: 2), + IncrementalEdit(offset: 5, length: 3, replacementLength: 1), + IncrementalEdit(offset: 4, length: 4, replacementLength: 2), ], [ - SourceEdit(offset: 4, length: 6, replacementLength: 2) + IncrementalEdit(offset: 4, length: 6, replacementLength: 2) ] ) } @@ -239,11 +239,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { // [--- edit2 (length 0) ----] verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 0, replacementLength: 1), - SourceEdit(offset: 5, length: 0, replacementLength: 2), + IncrementalEdit(offset: 5, length: 0, replacementLength: 1), + IncrementalEdit(offset: 5, length: 0, replacementLength: 2), ], [ - SourceEdit(offset: 5, length: 0, replacementLength: 3) + IncrementalEdit(offset: 5, length: 0, replacementLength: 3) ] ) } @@ -253,11 +253,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { // [--- edit2 ----] verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 1, replacementLength: 2), - SourceEdit(offset: 5, length: 1, replacementLength: 3), + IncrementalEdit(offset: 5, length: 1, replacementLength: 2), + IncrementalEdit(offset: 5, length: 1, replacementLength: 3), ], [ - SourceEdit(offset: 5, length: 1, replacementLength: 4) + IncrementalEdit(offset: 5, length: 1, replacementLength: 4) ] ) } @@ -267,11 +267,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { // [--- edit2 ----] verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 2, replacementLength: 2), - SourceEdit(offset: 5, length: 1, replacementLength: 3), + IncrementalEdit(offset: 5, length: 2, replacementLength: 2), + IncrementalEdit(offset: 5, length: 1, replacementLength: 3), ], [ - SourceEdit(offset: 5, length: 2, replacementLength: 4) + IncrementalEdit(offset: 5, length: 2, replacementLength: 4) ] ) } @@ -281,11 +281,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { // [--- edit2 ----] verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 5, replacementLength: 2), - SourceEdit(offset: 6, length: 1, replacementLength: 0), + IncrementalEdit(offset: 5, length: 5, replacementLength: 2), + IncrementalEdit(offset: 6, length: 1, replacementLength: 0), ], [ - SourceEdit(offset: 5, length: 5, replacementLength: 1) + IncrementalEdit(offset: 5, length: 5, replacementLength: 1) ] ) } @@ -295,11 +295,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { // [--- edit2 ----] verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 3, length: 3, replacementLength: 2), - SourceEdit(offset: 4, length: 3, replacementLength: 2), + IncrementalEdit(offset: 3, length: 3, replacementLength: 2), + IncrementalEdit(offset: 4, length: 3, replacementLength: 2), ], [ - SourceEdit(offset: 3, length: 5, replacementLength: 3) + IncrementalEdit(offset: 3, length: 5, replacementLength: 3) ] ) } @@ -307,11 +307,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { func testTwoOverlappingInsertions() { verifySequentialToConcurrentTranslation( [ - SourceEdit(offset: 5, length: 0, replacementLength: 3), - SourceEdit(offset: 6, length: 0, replacementLength: 2), + IncrementalEdit(offset: 5, length: 0, replacementLength: 3), + IncrementalEdit(offset: 6, length: 0, replacementLength: 2), ], [ - SourceEdit(offset: 5, length: 0, replacementLength: 5) + IncrementalEdit(offset: 5, length: 0, replacementLength: 5) ] ) } @@ -322,11 +322,11 @@ final class TranslateSequentialToConcurrentEditsTests: XCTestCase { var i = 0 while true { i += 1 - var edits: [SourceEdit] = [] + var edits: [IncrementalEdit] = [] let numEdits = Int.random(in: 1..<10) for _ in 0..