@@ -62,13 +62,13 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
62
62
// MARK: - Private helper functions
63
63
64
64
/// Produce a diagnostic.
65
- private func addDiagnostic< T: SyntaxProtocol > ( _ node: T , _ message: DiagnosticMessage , fixIts: [ FixIt ] = [ ] ) {
66
- diagnostics. append ( Diagnostic ( node: Syntax ( node) , message: message, fixIts: fixIts) )
65
+ private func addDiagnostic< T: SyntaxProtocol > ( _ node: T , _ message: DiagnosticMessage , highlights : [ Syntax ] = [ ] , fixIts: [ FixIt ] = [ ] ) {
66
+ diagnostics. append ( Diagnostic ( node: Syntax ( node) , message: message, highlights : highlights , fixIts: fixIts) )
67
67
}
68
68
69
69
/// Produce a diagnostic.
70
- private func addDiagnostic< T: SyntaxProtocol > ( _ node: T , _ message: StaticParserError , fixIts: [ FixIt ] = [ ] ) {
71
- addDiagnostic ( node, message as DiagnosticMessage , fixIts: fixIts)
70
+ private func addDiagnostic< T: SyntaxProtocol > ( _ node: T , _ message: StaticParserError , highlights : [ Syntax ] = [ ] , fixIts: [ FixIt ] = [ ] ) {
71
+ addDiagnostic ( node, message as DiagnosticMessage , highlights : highlights , fixIts: fixIts)
72
72
}
73
73
74
74
/// If a diagnostic is generated that covers multiple syntax nodes, mark them as handles so they don't produce the generic diagnostics anymore.
@@ -119,7 +119,20 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
119
119
// This is mostly a proof-of-concept implementation to produce more complex diagnostics.
120
120
if let unexpectedCondition = node. body. unexpectedBeforeLeftBrace,
121
121
unexpectedCondition. tokens ( withKind: . semicolon) . count == 2 {
122
- addDiagnostic ( node, . cStyleForLoop)
122
+ // 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.
123
+ addDiagnostic ( node, . cStyleForLoop, highlights: ( [
124
+ Syntax ( node. pattern) ,
125
+ Syntax ( node. unexpectedBetweenPatternAndTypeAnnotation) ,
126
+ Syntax ( node. typeAnnotation) ,
127
+ Syntax ( node. unexpectedBetweenTypeAnnotationAndInKeyword) ,
128
+ Syntax ( node. inKeyword) ,
129
+ Syntax ( node. unexpectedBetweenInKeywordAndSequenceExpr) ,
130
+ Syntax ( node. sequenceExpr) ,
131
+ Syntax ( node. unexpectedBetweenSequenceExprAndWhereClause) ,
132
+ Syntax ( node. whereClause) ,
133
+ Syntax ( node. unexpectedBetweenWhereClauseAndBody) ,
134
+ Syntax ( unexpectedCondition)
135
+ ] as [ Syntax ? ] ) . compactMap ( { $0 } ) )
123
136
markNodesAsHandled ( node. inKeyword. id, unexpectedCondition. id)
124
137
}
125
138
return . visitChildren
0 commit comments