@@ -62,13 +62,13 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
6262 // MARK: - Private helper functions
6363
6464 /// 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) )
6767 }
6868
6969 /// 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)
7272 }
7373
7474 /// 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 {
119119 // This is mostly a proof-of-concept implementation to produce more complex diagnostics.
120120 if let unexpectedCondition = node. body. unexpectedBeforeLeftBrace,
121121 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 } ) )
123136 markNodesAsHandled ( node. inKeyword. id, unexpectedCondition. id)
124137 }
125138 return . visitChildren
0 commit comments