Skip to content

Commit

Permalink
Work around fixit trivia bug in Xcode by replacing entire declaration…
Browse files Browse the repository at this point in the history
… instead of members (#128)
  • Loading branch information
dfed authored Dec 29, 2024
1 parent 21c13af commit 2416015
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Sources/SafeDIMacros/Macros/InstantiableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ public struct InstantiableMacro: MemberMacro {
.contains(where: { $0.isValid(forFulfilling: visitor.dependencies) })
guard hasMemberwiseInitializerForInjectableProperties else {
if visitor.uninitializedNonOptionalPropertyNames.isEmpty {
var membersWithInitializer = declaration.memberBlock.members
membersWithInitializer.insert(
var declarationWithInitializer = declaration
declarationWithInitializer.memberBlock.members.insert(
MemberBlockItemSyntax(
leadingTrivia: .newline,
decl: Initializer.generateRequiredInitializer(
Expand All @@ -143,22 +143,22 @@ public struct InstantiableMacro: MemberMacro {
),
trailingTrivia: .newline
),
at: membersWithInitializer.startIndex
at: declarationWithInitializer.memberBlock.members.startIndex
)
context.diagnose(Diagnostic(
node: Syntax(declaration.memberBlock),
error: FixableInstantiableError.missingRequiredInitializer(.hasOnlyInjectableProperties),
changes: [
.replace(
oldNode: Syntax(declaration.memberBlock.members),
newNode: Syntax(membersWithInitializer)
oldNode: Syntax(declaration),
newNode: Syntax(declarationWithInitializer)
),
]
))
return []
} else {
var membersWithInitializer = declaration.memberBlock.members
membersWithInitializer.insert(
var declarationWithInitializer = declaration
declarationWithInitializer.memberBlock.members.insert(
MemberBlockItemSyntax(
leadingTrivia: .newline,
decl: Initializer.generateRequiredInitializer(
Expand All @@ -168,7 +168,7 @@ public struct InstantiableMacro: MemberMacro {
),
trailingTrivia: .newline
),
at: membersWithInitializer.startIndex
at: declarationWithInitializer.memberBlock.members.startIndex
)
// TODO: Create separate fixit if just `public` or `open` are missing.
context.diagnose(Diagnostic(
Expand All @@ -178,8 +178,8 @@ public struct InstantiableMacro: MemberMacro {
),
changes: [
.replace(
oldNode: Syntax(declaration.memberBlock.members),
newNode: Syntax(membersWithInitializer)
oldNode: Syntax(declaration),
newNode: Syntax(declarationWithInitializer)
),
]
))
Expand Down

0 comments on commit 2416015

Please sign in to comment.