Skip to content

Commit 0287d59

Browse files
committed
fix: cr
1 parent d6b9cd2 commit 0287d59

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

Sources/SwiftParserDiagnostics/SyntaxExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ extension Syntax {
8585
extension SyntaxProtocol {
8686
/// A name that can be used to describe this node's type in diagnostics or `nil` if there is no good name for this node.
8787
/// If `allowBlockNames` is `false`, ``CodeBlockSyntax`` and ``MemberDeclBlockSyntax`` are not considered to have a good name and will return `nil`.
88-
public func nodeTypeNameForDiagnostics(allowBlockNames: Bool) -> String? {
88+
func nodeTypeNameForDiagnostics(allowBlockNames: Bool) -> String? {
8989
let syntax = Syntax(self)
9090
if !allowBlockNames && (syntax.is(CodeBlockSyntax.self) || syntax.is(MemberBlockSyntax.self)) {
9191
return nil

Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#endif
2020

2121
extension SyntaxKind {
22-
var nameForDiagnostics: String? {
22+
public var nameForDiagnostics: String? {
2323
switch self {
2424
case .token:
2525
return "token"

Sources/SwiftSyntaxMacroExpansion/MacroExpansion.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SwiftSyntax
2020
@_spi(MacroExpansion) @_spi(ExperimentalLanguageFeature) import SwiftSyntaxMacros
2121
#endif
2222

23-
public enum MacroRole: String, Sendable {
23+
public enum MacroRole: Sendable {
2424
case expression
2525
case declaration
2626
case accessor
@@ -50,6 +50,22 @@ extension MacroRole {
5050
case .body: return "BodyMacro"
5151
}
5252
}
53+
54+
var description: String {
55+
switch self {
56+
case .expression: return "expression"
57+
case .declaration: return "declaration"
58+
case .accessor: return "accessor"
59+
case .memberAttribute: return "memberAttribute"
60+
case .member: return "member"
61+
case .peer: return "peer"
62+
case .conformance: return "conformance"
63+
case .codeItem: return "codeItem"
64+
case .extension: return "extension"
65+
case .preamble: return "preamble"
66+
case .body: return "body"
67+
}
68+
}
5369
}
5470

5571
/// Simple diagnostic message

Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
722722
skipVisitAnyHandling.remove(Syntax(declSyntax))
723723

724724
let attributesToRemove = self.macroAttributes(attachedTo: visitedNode)
725-
attributesToRemove.forEach { (attribute, spec) in
725+
for (attribute, spec) in attributesToRemove {
726726
if let index = self.expandedAttributes.firstIndex(where: { expandedAttribute in
727727
expandedAttribute.position == attribute.position
728728
}) {
@@ -733,8 +733,8 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
733733
{
734734
contextGenerator(node).addDiagnostics(
735735
from: MacroApplicationError.macroAttachedToInvalidDecl(
736-
macroRole.rawValue,
737-
declSyntax.nodeTypeNameForDiagnostics(allowBlockNames: true) ?? ""
736+
macroRole.description,
737+
declSyntax.kind.nameForDiagnostics ?? ""
738738
),
739739
node: declSyntax,
740740
fixIts: [

0 commit comments

Comments
 (0)