diff --git a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift index 45577150253..fb257767d85 100644 --- a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift +++ b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift @@ -664,23 +664,14 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { if let unexpectedCondition = node.body.unexpectedBeforeLeftBrace, unexpectedCondition.tokens(withKind: .semicolon).count == 2 { - // FIXME: This is aweful. We should have a way to either get all children between two cursors in a syntax node or highlight a range from one node to another. + var highlights = Array(node.children(viewMode: .sourceAccurate).compactMap({ $0.as(Syntax.self) }).dropFirst().dropLast()) + highlights.append(Syntax(unexpectedCondition)) addDiagnostic( node, .cStyleForLoop, - highlights: ([ - Syntax(node.pattern), - Syntax(node.unexpectedBetweenPatternAndTypeAnnotation), - Syntax(node.typeAnnotation), - Syntax(node.unexpectedBetweenTypeAnnotationAndInKeyword), - Syntax(node.inKeyword), - Syntax(node.unexpectedBetweenInKeywordAndSequenceExpr), - Syntax(node.sequenceExpr), - Syntax(node.unexpectedBetweenSequenceExprAndWhereClause), - Syntax(node.whereClause), - Syntax(node.unexpectedBetweenWhereClauseAndBody), - Syntax(unexpectedCondition), - ] as [Syntax?]).compactMap({ $0 }), + highlights: ( + highlights + ), handledNodes: [node.inKeyword.id, node.sequenceExpr.id, unexpectedCondition.id] ) } else { // If it's not a C-style for loop @@ -688,7 +679,6 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { addDiagnostic(node.sequenceExpr, .expectedSequenceExpressionInForEachLoop, handledNodes: [node.sequenceExpr.id]) } } - return .visitChildren }