@@ -19,13 +19,12 @@ use crate::Name;
1919#[ derive( Debug , Clone ) ]
2020pub enum Identifier < ' db > {
2121 /// Cursor on a binding use or definition site tracked by the semantic
22- /// index. The range is the use or def site's text range. Its start is
23- /// the offset to pass to `resolve_at`.
22+ /// index. The range is the use or def site's text range.
2423 Variable { name : Name < ' db > , range : TextRange } ,
2524 /// Cursor on the RHS name of a `$` or `@` extract expression. Member
2625 /// names are not tracked by the semantic index.
2726 Member {
28- name : String ,
27+ name : Name < ' db > ,
2928 kind : MemberKind ,
3029 operator_range : TextRange ,
3130 name_range : TextRange ,
@@ -71,7 +70,7 @@ impl<'db> Identifier<'db> {
7170
7271 if let Some ( ( name, kind, operator_range, name_range) ) = classify_member ( & root, snapped) {
7372 return Some ( Identifier :: Member {
74- name,
73+ name : Name :: new ( db , name . as_str ( ) ) ,
7574 kind,
7675 operator_range,
7776 name_range,
@@ -84,28 +83,8 @@ impl<'db> Identifier<'db> {
8483
8584impl < ' db > File {
8685 /// All use-site ranges for `name` in this file, across every scope.
87- ///
88- /// Used as the candidate pool for find-references: each returned range is
89- /// confirmed by calling `resolve_at(range.start())` and checking whether
90- /// its definition set intersects the target.
9186 pub fn uses_of ( self , db : & ' db dyn Db , name : Name < ' db > ) -> Vec < TextRange > {
92- let index = self . semantic_index ( db) ;
93- let name_str = name. text ( db) ;
94- let mut ranges = Vec :: new ( ) ;
95-
96- for scope_id in index. scope_ids ( ) {
97- let symbols = index. symbols ( scope_id) ;
98- let Some ( symbol_id) = symbols. id ( name_str) else {
99- continue ;
100- } ;
101- for ( _use_id, use_site) in index. uses ( scope_id) . iter ( ) {
102- if use_site. symbol ( ) == symbol_id {
103- ranges. push ( use_site. range ( ) ) ;
104- }
105- }
106- }
107-
108- ranges
87+ self . semantic_index ( db) . uses_of ( name. text ( db) . as_str ( ) )
10988 }
11089
11190 /// All ranges where `name` appears as the RHS of a `$` or `@` with the
@@ -141,6 +120,9 @@ fn classify_member(
141120 root : & RSyntaxNode ,
142121 offset : TextSize ,
143122) -> Option < ( String , MemberKind , TextRange , TextRange ) > {
123+ // Snapping put `offset` at the name's start, which is the operator's end,
124+ // so `token_at_offset()` reports `Between(op, name)`. Take the name on the
125+ // right side.
144126 let token = root. token_at_offset ( offset) . right_biased ( ) ?;
145127 if !is_name_token ( & token) {
146128 return None ;
@@ -150,8 +132,7 @@ fn classify_member(
150132 let selector_node = token. parent ( ) ?;
151133 let extract = RExtractExpression :: cast ( selector_node. parent ( ) ?) ?;
152134
153- // Token is after the operator -> it's on the RHS, not LHS.
154- // RHS start == op end (adjacent bytes), so use strict <.
135+ // Token is after the operator -> it's on the RHS, not LHS
155136 let op = extract. operator ( ) . ok ( ) ?;
156137 if token. text_trimmed_range ( ) . start ( ) < op. text_trimmed_range ( ) . end ( ) {
157138 return None ;
@@ -201,6 +182,9 @@ fn snap_to_name_at_boundary(root: &RSyntaxNode, offset: TextSize) -> TextSize {
201182}
202183
203184fn is_name_token ( token : & RSyntaxToken ) -> bool {
185+ // FIXME: Right now we're too liberal with strings. We should only match
186+ // them when they stand for an identifier, e.g. in the LHS of `<-` or in
187+ // function call position.
204188 matches ! (
205189 token. kind( ) ,
206190 RSyntaxKind :: IDENT | RSyntaxKind :: R_STRING_LITERAL
0 commit comments