Skip to content

Commit a4088dd

Browse files
committed
Migrate FunctionSignatureSyntax diagnostic to exchangeTokens
1 parent 4cc7c62 commit a4088dd

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

Sources/SwiftParser/Diagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,13 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
274274
if shouldSkip(node) {
275275
return .skipChildren
276276
}
277-
if let output = node.output,
278-
let missingThrowsKeyword = node.throwsOrRethrowsKeyword,
279-
missingThrowsKeyword.presence == .missing,
280-
let unexpectedBeforeReturnType = output.unexpectedBetweenArrowAndReturnType,
281-
let throwsInReturnPosition = unexpectedBeforeReturnType.tokens(withKind: .throwsKeyword).first {
282-
addDiagnostic(throwsInReturnPosition, .throwsInReturnPosition, fixIts: [
283-
FixIt(message: MoveTokensInFrontOfFixIt(movedTokens: [missingThrowsKeyword], inFrontOf: .arrow), changes: [
284-
.makeMissing(node: throwsInReturnPosition),
285-
.makePresent(node: missingThrowsKeyword),
286-
])
287-
], handledNodes: [unexpectedBeforeReturnType.id, missingThrowsKeyword.id, throwsInReturnPosition.id])
288-
return .visitChildren
289-
}
277+
exchangeTokens(
278+
unexpected: node.output?.unexpectedBetweenArrowAndReturnType,
279+
unexpectedTokenCondition: { $0.tokenKind == .throwsKeyword },
280+
correctTokens: [node.throwsOrRethrowsKeyword],
281+
message: { _ in StaticParserError.throwsInReturnPosition },
282+
fixIt: { MoveTokensInFrontOfFixIt(movedTokens: $0, inFrontOf: .arrow) }
283+
)
290284
return .visitChildren
291285
}
292286

0 commit comments

Comments
 (0)