Skip to content

Commit a9efd4c

Browse files
committed
fix
1 parent 3345082 commit a9efd4c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Sources/SwiftParserDiagnostics/MissingNodesError.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ func nodesDescription<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format:
111111
/// Same as `nodesDescription` but if a common ancestor was used to describe `missingNodes`, also return that `commonAncestor`
112112
func nodesDescriptionAndCommonParent<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format: Bool) -> (commonAncestor: Syntax?, description: String) {
113113
let missingSyntaxNodes = nodes.map(Syntax.init)
114+
115+
let isOnlyTokenWithNonMissingText: Bool
116+
if let token = nodes.only?.as(TokenSyntax.self) {
117+
isOnlyTokenWithNonMissingText = token.text != ""
118+
} else {
119+
isOnlyTokenWithNonMissingText = false
120+
}
114121

115122
// If all tokens in the parent are missing, return the parent type name unless
116123
// we are replacing by a single token that has explicit text, in which case we
@@ -120,7 +127,8 @@ func nodesDescriptionAndCommonParent<SyntaxType: SyntaxProtocol>(_ nodes: [Synta
120127
let firstToken = commonAncestor.firstToken(viewMode: .all),
121128
let lastToken = commonAncestor.lastToken(viewMode: .all),
122129
missingSyntaxNodes.contains(Syntax(firstToken)),
123-
missingSyntaxNodes.contains(Syntax(lastToken))
130+
missingSyntaxNodes.contains(Syntax(lastToken)),
131+
!isOnlyTokenWithNonMissingText
124132
{
125133
if let nodeTypeName = commonAncestor.nodeTypeNameForDiagnostics(allowBlockNames: true) {
126134
return (commonAncestor, nodeTypeName)

Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,5 @@ public struct ReplaceTokensFixIt: ParserFixIt {
614614
public let replacements: [TokenSyntax]
615615

616616
public var message: String {
617-
if replacements.count == 1 {
618-
return "replace \(nodesDescription(replaceTokens, format: false)) with '\(replacements[0].text)'"
619-
} else {
620-
return "replace \(nodesDescription(replaceTokens, format: false)) with \(nodesDescription(replacements, format: false))"
621-
}
622-
}
617+
"replace \(nodesDescription(replaceTokens, format: false)) with \(nodesDescription(replacements, format: false))" }
623618
}

0 commit comments

Comments
 (0)