33use std:: any:: Any ;
44
55use hir_expand:: { db:: AstDatabase , name:: Name , HirFileId , InFile } ;
6- use ra_syntax:: { ast, AstNode , AstPtr , SyntaxNodePtr } ;
6+ use ra_syntax:: { ast, AstNode , AstPtr , SyntaxNodePtr , TextRange } ;
77use stdx:: format_to;
88
99pub use hir_def:: { diagnostics:: UnresolvedModule , expr:: MatchArm } ;
@@ -13,13 +13,18 @@ pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
1313pub struct NoSuchField {
1414 pub file : HirFileId ,
1515 pub field : AstPtr < ast:: RecordField > ,
16+ pub highlight_range : TextRange ,
1617}
1718
1819impl Diagnostic for NoSuchField {
1920 fn message ( & self ) -> String {
2021 "no such field" . to_string ( )
2122 }
2223
24+ fn highlight_range ( & self ) -> TextRange {
25+ self . highlight_range
26+ }
27+
2328 fn source ( & self ) -> InFile < SyntaxNodePtr > {
2429 InFile { file_id : self . file , value : self . field . clone ( ) . into ( ) }
2530 }
@@ -33,6 +38,7 @@ impl Diagnostic for NoSuchField {
3338pub struct MissingFields {
3439 pub file : HirFileId ,
3540 pub field_list : AstPtr < ast:: RecordFieldList > ,
41+ pub highlight_range : TextRange ,
3642 pub missed_fields : Vec < Name > ,
3743}
3844
@@ -44,6 +50,10 @@ impl Diagnostic for MissingFields {
4450 }
4551 buf
4652 }
53+ fn highlight_range ( & self ) -> TextRange {
54+ self . highlight_range
55+ }
56+
4757 fn source ( & self ) -> InFile < SyntaxNodePtr > {
4858 InFile { file_id : self . file , value : self . field_list . clone ( ) . into ( ) }
4959 }
@@ -66,6 +76,7 @@ impl AstDiagnostic for MissingFields {
6676pub struct MissingPatFields {
6777 pub file : HirFileId ,
6878 pub field_list : AstPtr < ast:: RecordFieldPatList > ,
79+ pub highlight_range : TextRange ,
6980 pub missed_fields : Vec < Name > ,
7081}
7182
@@ -77,6 +88,9 @@ impl Diagnostic for MissingPatFields {
7788 }
7889 buf
7990 }
91+ fn highlight_range ( & self ) -> TextRange {
92+ self . highlight_range
93+ }
8094 fn source ( & self ) -> InFile < SyntaxNodePtr > {
8195 InFile { file_id : self . file , value : self . field_list . clone ( ) . into ( ) }
8296 }
@@ -90,12 +104,16 @@ pub struct MissingMatchArms {
90104 pub file : HirFileId ,
91105 pub match_expr : AstPtr < ast:: Expr > ,
92106 pub arms : AstPtr < ast:: MatchArmList > ,
107+ pub highlight_range : TextRange ,
93108}
94109
95110impl Diagnostic for MissingMatchArms {
96111 fn message ( & self ) -> String {
97112 String :: from ( "Missing match arm" )
98113 }
114+ fn highlight_range ( & self ) -> TextRange {
115+ self . highlight_range
116+ }
99117 fn source ( & self ) -> InFile < SyntaxNodePtr > {
100118 InFile { file_id : self . file , value : self . match_expr . clone ( ) . into ( ) }
101119 }
@@ -108,12 +126,16 @@ impl Diagnostic for MissingMatchArms {
108126pub struct MissingOkInTailExpr {
109127 pub file : HirFileId ,
110128 pub expr : AstPtr < ast:: Expr > ,
129+ pub highlight_range : TextRange ,
111130}
112131
113132impl Diagnostic for MissingOkInTailExpr {
114133 fn message ( & self ) -> String {
115134 "wrap return expression in Ok" . to_string ( )
116135 }
136+ fn highlight_range ( & self ) -> TextRange {
137+ self . highlight_range
138+ }
117139 fn source ( & self ) -> InFile < SyntaxNodePtr > {
118140 InFile { file_id : self . file , value : self . expr . clone ( ) . into ( ) }
119141 }
0 commit comments