@@ -3,7 +3,7 @@ use ide_db::{
33 base_db:: FilePosition ,
44 defs:: { Definition , NameClass , NameRefClass } ,
55 helpers:: { for_each_break_expr, for_each_tail_expr, node_ext:: walk_expr, pick_best_token} ,
6- search:: { FileReference , ReferenceAccess , SearchScope } ,
6+ search:: { FileReference , ReferenceCategory , SearchScope } ,
77 RootDatabase ,
88} ;
99use rustc_hash:: FxHashSet ;
@@ -19,7 +19,10 @@ use crate::{display::TryToNav, references, NavigationTarget};
1919#[ derive( PartialEq , Eq , Hash ) ]
2020pub struct HighlightedRange {
2121 pub range : TextRange ,
22- pub access : Option < ReferenceAccess > ,
22+ // FIXME: This needs to be more precise. Reference category makes sense only
23+ // for references, but we also have defs. And things like exit points are
24+ // neither.
25+ pub category : Option < ReferenceCategory > ,
2326}
2427
2528#[ derive( Default , Clone ) ]
@@ -87,7 +90,10 @@ fn highlight_references(
8790 . remove ( & file_id)
8891 } )
8992 . flatten ( )
90- . map ( |FileReference { access, range, .. } | HighlightedRange { range, access } ) ;
93+ . map ( |FileReference { category : access, range, .. } | HighlightedRange {
94+ range,
95+ category : access,
96+ } ) ;
9197
9298 let declarations = defs. iter ( ) . flat_map ( |def| {
9399 match def {
@@ -99,8 +105,12 @@ fn highlight_references(
99105 . filter ( |decl| decl. file_id == file_id)
100106 . and_then ( |decl| {
101107 let range = decl. focus_range ?;
102- let access = references:: decl_access ( & def, syntax, range) ;
103- Some ( HighlightedRange { range, access } )
108+ let category = if references:: decl_mutability ( & def, syntax, range) {
109+ Some ( ReferenceCategory :: Write )
110+ } else {
111+ None
112+ } ;
113+ Some ( HighlightedRange { range, category } )
104114 } )
105115 } ) ;
106116
@@ -125,18 +135,20 @@ fn highlight_exit_points(
125135 walk_expr ( & body, & mut |expr| match expr {
126136 ast:: Expr :: ReturnExpr ( expr) => {
127137 if let Some ( token) = expr. return_token ( ) {
128- highlights. push ( HighlightedRange { access : None , range : token. text_range ( ) } ) ;
138+ highlights. push ( HighlightedRange { category : None , range : token. text_range ( ) } ) ;
129139 }
130140 }
131141 ast:: Expr :: TryExpr ( try_) => {
132142 if let Some ( token) = try_. question_mark_token ( ) {
133- highlights. push ( HighlightedRange { access : None , range : token. text_range ( ) } ) ;
143+ highlights. push ( HighlightedRange { category : None , range : token. text_range ( ) } ) ;
134144 }
135145 }
136146 ast:: Expr :: MethodCallExpr ( _) | ast:: Expr :: CallExpr ( _) | ast:: Expr :: MacroCall ( _) => {
137147 if sema. type_of_expr ( & expr) . map_or ( false , |ty| ty. original . is_never ( ) ) {
138- highlights
139- . push ( HighlightedRange { access : None , range : expr. syntax ( ) . text_range ( ) } ) ;
148+ highlights. push ( HighlightedRange {
149+ category : None ,
150+ range : expr. syntax ( ) . text_range ( ) ,
151+ } ) ;
140152 }
141153 }
142154 _ => ( ) ,
@@ -154,7 +166,7 @@ fn highlight_exit_points(
154166 . map_or_else ( || tail. syntax ( ) . text_range ( ) , |tok| tok. text_range ( ) ) ,
155167 _ => tail. syntax ( ) . text_range ( ) ,
156168 } ;
157- highlights. push ( HighlightedRange { access : None , range } )
169+ highlights. push ( HighlightedRange { category : None , range } )
158170 } ) ;
159171 }
160172 Some ( highlights)
@@ -187,13 +199,13 @@ fn highlight_break_points(token: SyntaxToken) -> Option<Vec<HighlightedRange>> {
187199 token. map ( |tok| tok. text_range ( ) ) ,
188200 label. as_ref ( ) . map ( |it| it. syntax ( ) . text_range ( ) ) ,
189201 ) ;
190- highlights. extend ( range. map ( |range| HighlightedRange { access : None , range } ) ) ;
202+ highlights. extend ( range. map ( |range| HighlightedRange { category : None , range } ) ) ;
191203 for_each_break_expr ( label, body, & mut |break_| {
192204 let range = cover_range (
193205 break_. break_token ( ) . map ( |it| it. text_range ( ) ) ,
194206 break_. lifetime ( ) . map ( |it| it. syntax ( ) . text_range ( ) ) ,
195207 ) ;
196- highlights. extend ( range. map ( |range| HighlightedRange { access : None , range } ) ) ;
208+ highlights. extend ( range. map ( |range| HighlightedRange { category : None , range } ) ) ;
197209 } ) ;
198210 Some ( highlights)
199211 }
@@ -241,13 +253,13 @@ fn highlight_yield_points(token: SyntaxToken) -> Option<Vec<HighlightedRange>> {
241253 body : Option < ast:: Expr > ,
242254 ) -> Option < Vec < HighlightedRange > > {
243255 let mut highlights =
244- vec ! [ HighlightedRange { access : None , range: async_token?. text_range( ) } ] ;
256+ vec ! [ HighlightedRange { category : None , range: async_token?. text_range( ) } ] ;
245257 if let Some ( body) = body {
246258 walk_expr ( & body, & mut |expr| {
247259 if let ast:: Expr :: AwaitExpr ( expr) = expr {
248260 if let Some ( token) = expr. await_token ( ) {
249261 highlights
250- . push ( HighlightedRange { access : None , range : token. text_range ( ) } ) ;
262+ . push ( HighlightedRange { category : None , range : token. text_range ( ) } ) ;
251263 }
252264 }
253265 } ) ;
@@ -353,10 +365,10 @@ mod tests {
353365 . map ( |hl| {
354366 (
355367 hl. range ,
356- hl. access . map ( |it| {
368+ hl. category . map ( |it| {
357369 match it {
358- ReferenceAccess :: Read => "read" ,
359- ReferenceAccess :: Write => "write" ,
370+ ReferenceCategory :: Read => "read" ,
371+ ReferenceCategory :: Write => "write" ,
360372 }
361373 . to_string ( )
362374 } ) ,
0 commit comments