@@ -111,6 +111,13 @@ func nodesDescription<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format:
111
111
/// Same as `nodesDescription` but if a common ancestor was used to describe `missingNodes`, also return that `commonAncestor`
112
112
func nodesDescriptionAndCommonParent< SyntaxType: SyntaxProtocol > ( _ nodes: [ SyntaxType ] , format: Bool ) -> ( commonAncestor: Syntax ? , description: String ) {
113
113
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
+ }
114
121
115
122
// If all tokens in the parent are missing, return the parent type name unless
116
123
// 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
120
127
let firstToken = commonAncestor. firstToken ( viewMode: . all) ,
121
128
let lastToken = commonAncestor. lastToken ( viewMode: . all) ,
122
129
missingSyntaxNodes. contains ( Syntax ( firstToken) ) ,
123
- missingSyntaxNodes. contains ( Syntax ( lastToken) )
130
+ missingSyntaxNodes. contains ( Syntax ( lastToken) ) ,
131
+ !isOnlyTokenWithNonMissingText
124
132
{
125
133
if let nodeTypeName = commonAncestor. nodeTypeNameForDiagnostics ( allowBlockNames: true ) {
126
134
return ( commonAncestor, nodeTypeName)
0 commit comments