Skip to content

Commit ba7db24

Browse files
committed
bug fix
1 parent f602144 commit ba7db24

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Sources/SwiftParserDiagnostics/MissingNodesError.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,16 @@ func nodesDescription<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format:
112112
func nodesDescriptionAndCommonParent<SyntaxType: SyntaxProtocol>(_ nodes: [SyntaxType], format: Bool) -> (commonAncestor: Syntax?, description: String) {
113113
let missingSyntaxNodes = nodes.map(Syntax.init)
114114

115-
// If all tokens in the parent are missing, return the parent type name.
115+
// If all tokens in the parent are missing, return the parent type name unless
116+
// we are replacing by a single token that has explicit text, in which case we
117+
// return that explicit text.
116118
if let commonAncestor = findCommonAncestor(missingSyntaxNodes),
117119
commonAncestor.isMissingAllTokens,
118120
let firstToken = commonAncestor.firstToken(viewMode: .all),
119121
let lastToken = commonAncestor.lastToken(viewMode: .all),
120122
missingSyntaxNodes.contains(Syntax(firstToken)),
121-
missingSyntaxNodes.contains(Syntax(lastToken))
123+
missingSyntaxNodes.contains(Syntax(lastToken)),
124+
nodes.only?.as(TokenSyntax.self)?.text != nil
122125
{
123126
if let nodeTypeName = commonAncestor.nodeTypeNameForDiagnostics(allowBlockNames: true) {
124127
return (commonAncestor, nodeTypeName)

0 commit comments

Comments
 (0)