File tree Expand file tree Collapse file tree 4 files changed +22
-6
lines changed
SwiftSyntaxMacroExpansion Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ extension Syntax {
85
85
extension SyntaxProtocol {
86
86
/// 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.
87
87
/// 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 ? {
89
89
let syntax = Syntax ( self )
90
90
if !allowBlockNames && ( syntax. is ( CodeBlockSyntax . self) || syntax. is ( MemberBlockSyntax . self) ) {
91
91
return nil
Original file line number Diff line number Diff line change 19
19
#endif
20
20
21
21
extension SyntaxKind {
22
- var nameForDiagnostics : String ? {
22
+ public var nameForDiagnostics : String ? {
23
23
switch self {
24
24
case . token:
25
25
return " token "
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import SwiftSyntax
20
20
@_spi ( MacroExpansion) @_spi ( ExperimentalLanguageFeature) import SwiftSyntaxMacros
21
21
#endif
22
22
23
- public enum MacroRole : String , Sendable {
23
+ public enum MacroRole : Sendable {
24
24
case expression
25
25
case declaration
26
26
case accessor
@@ -50,6 +50,22 @@ extension MacroRole {
50
50
case . body: return " BodyMacro "
51
51
}
52
52
}
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
+ }
53
69
}
54
70
55
71
/// Simple diagnostic message
Original file line number Diff line number Diff line change @@ -722,7 +722,7 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
722
722
skipVisitAnyHandling. remove ( Syntax ( declSyntax) )
723
723
724
724
let attributesToRemove = self . macroAttributes ( attachedTo: visitedNode)
725
- attributesToRemove . forEach { ( attribute, spec) in
725
+ for (attribute, spec) in attributesToRemove {
726
726
if let index = self . expandedAttributes. firstIndex ( where: { expandedAttribute in
727
727
expandedAttribute. position == attribute. position
728
728
} ) {
@@ -733,8 +733,8 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
733
733
{
734
734
contextGenerator ( node) . addDiagnostics (
735
735
from: MacroApplicationError . macroAttachedToInvalidDecl (
736
- macroRole. rawValue ,
737
- declSyntax. nodeTypeNameForDiagnostics ( allowBlockNames : true ) ?? " "
736
+ macroRole. description ,
737
+ declSyntax. kind . nameForDiagnostics ?? " "
738
738
) ,
739
739
node: declSyntax,
740
740
fixIts: [
You can’t perform that action at this time.
0 commit comments