Skip to content

Commit

Permalink
fix: cr
Browse files Browse the repository at this point in the history
  • Loading branch information
RayZhao1998 committed May 2, 2024
1 parent d6b9cd2 commit ad9e5ae
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sources/SwiftParserDiagnostics/SyntaxExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension Syntax {
extension SyntaxProtocol {
/// 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.
/// If `allowBlockNames` is `false`, ``CodeBlockSyntax`` and ``MemberDeclBlockSyntax`` are not considered to have a good name and will return `nil`.
public func nodeTypeNameForDiagnostics(allowBlockNames: Bool) -> String? {
func nodeTypeNameForDiagnostics(allowBlockNames: Bool) -> String? {
let syntax = Syntax(self)
if !allowBlockNames && (syntax.is(CodeBlockSyntax.self) || syntax.is(MemberBlockSyntax.self)) {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#endif

extension SyntaxKind {
var nameForDiagnostics: String? {
public var nameForDiagnostics: String? {
switch self {
case .token:
return "token"
Expand Down
18 changes: 17 additions & 1 deletion Sources/SwiftSyntaxMacroExpansion/MacroExpansion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import SwiftSyntax
@_spi(MacroExpansion) @_spi(ExperimentalLanguageFeature) import SwiftSyntaxMacros
#endif

public enum MacroRole: String, Sendable {
public enum MacroRole: Sendable {
case expression
case declaration
case accessor
Expand Down Expand Up @@ -50,6 +50,22 @@ extension MacroRole {
case .body: return "BodyMacro"
}
}

var description: String {
switch self {
case .expression: return "expression"
case .declaration: return "declaration"
case .accessor: return "accessor"
case .memberAttribute: return "memberAttribute"
case .member: return "member"
case .peer: return "peer"
case .conformance: return "conformance"
case .codeItem: return "codeItem"
case .extension: return "extension"
case .preamble: return "preamble"
case .body: return "body"
}
}
}

/// Simple diagnostic message
Expand Down
7 changes: 3 additions & 4 deletions Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
skipVisitAnyHandling.remove(Syntax(declSyntax))

let attributesToRemove = self.macroAttributes(attachedTo: visitedNode)
attributesToRemove.forEach { (attribute, spec) in
for (attribute, spec) in attributesToRemove {
if let index = self.expandedAttributes.firstIndex(where: { expandedAttribute in
expandedAttribute.position == attribute.position
}) {
Expand All @@ -733,8 +733,8 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
{
contextGenerator(node).addDiagnostics(
from: MacroApplicationError.macroAttachedToInvalidDecl(
macroRole.rawValue,
declSyntax.nodeTypeNameForDiagnostics(allowBlockNames: true) ?? ""
macroRole.description,
declSyntax.kind.nameForDiagnostics ?? ""
),
node: declSyntax,
fixIts: [
Expand Down Expand Up @@ -1248,7 +1248,6 @@ extension MacroApplication {
contextGenerator(Syntax(storage)).addDiagnostics(from: error, node: macro.attributeNode)
}
}

return (newAccessorsBlock, expandsGetSet)
}
}
Expand Down

0 comments on commit ad9e5ae

Please sign in to comment.