aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_db/src/search.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_db/src/search.rs')
-rw-r--r--crates/ra_ide_db/src/search.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs
index 1bf014149..b464959fc 100644
--- a/crates/ra_ide_db/src/search.rs
+++ b/crates/ra_ide_db/src/search.rs
@@ -4,13 +4,13 @@
4//! get a super-set of matches. Then, we we confirm each match using precise 4//! get a super-set of matches. Then, we we confirm each match using precise
5//! name resolution. 5//! name resolution.
6 6
7use std::mem; 7use std::{convert::TryInto, mem};
8 8
9use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility}; 9use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility};
10use once_cell::unsync::Lazy; 10use once_cell::unsync::Lazy;
11use ra_db::{FileId, FileRange, SourceDatabaseExt}; 11use ra_db::{FileId, FileRange, SourceDatabaseExt};
12use ra_prof::profile; 12use ra_prof::profile;
13use ra_syntax::{ast, match_ast, AstNode, TextRange, TextUnit}; 13use ra_syntax::{ast, match_ast, AstNode, TextRange, TextSize};
14use rustc_hash::FxHashMap; 14use rustc_hash::FxHashMap;
15use test_utils::tested_by; 15use test_utils::tested_by;
16 16
@@ -28,8 +28,8 @@ pub struct Reference {
28 28
29#[derive(Debug, Clone, PartialEq)] 29#[derive(Debug, Clone, PartialEq)]
30pub enum ReferenceKind { 30pub enum ReferenceKind {
31 StructFieldShorthandForField, 31 FieldShorthandForField,
32 StructFieldShorthandForLocal, 32 FieldShorthandForLocal,
33 StructLiteral, 33 StructLiteral,
34 Other, 34 Other,
35} 35}
@@ -85,7 +85,7 @@ impl SearchScope {
85 match (r1, r2) { 85 match (r1, r2) {
86 (None, r) | (r, None) => Some(r), 86 (None, r) | (r, None) => Some(r),
87 (Some(r1), Some(r2)) => { 87 (Some(r1), Some(r2)) => {
88 let r = r1.intersection(&r2)?; 88 let r = r1.intersect(r2)?;
89 Some(Some(r)) 89 Some(Some(r))
90 } 90 }
91 } 91 }
@@ -201,13 +201,13 @@ impl Definition {
201 for (file_id, search_range) in search_scope { 201 for (file_id, search_range) in search_scope {
202 let text = db.file_text(file_id); 202 let text = db.file_text(file_id);
203 let search_range = 203 let search_range =
204 search_range.unwrap_or(TextRange::offset_len(0.into(), TextUnit::of_str(&text))); 204 search_range.unwrap_or(TextRange::up_to(TextSize::of(text.as_str())));
205 205
206 let sema = Semantics::new(db); 206 let sema = Semantics::new(db);
207 let tree = Lazy::new(|| sema.parse(file_id).syntax().clone()); 207 let tree = Lazy::new(|| sema.parse(file_id).syntax().clone());
208 208
209 for (idx, _) in text.match_indices(pat) { 209 for (idx, _) in text.match_indices(pat) {
210 let offset = TextUnit::from_usize(idx); 210 let offset: TextSize = idx.try_into().unwrap();
211 if !search_range.contains_inclusive(offset) { 211 if !search_range.contains_inclusive(offset) {
212 tested_by!(search_filters_by_range; force); 212 tested_by!(search_filters_by_range; force);
213 continue; 213 continue;
@@ -242,14 +242,14 @@ impl Definition {
242 } 242 }
243 Some(NameRefClass::FieldShorthand { local, field }) => { 243 Some(NameRefClass::FieldShorthand { local, field }) => {
244 match self { 244 match self {
245 Definition::StructField(_) if &field == self => refs.push(Reference { 245 Definition::Field(_) if &field == self => refs.push(Reference {
246 file_range: sema.original_range(name_ref.syntax()), 246 file_range: sema.original_range(name_ref.syntax()),
247 kind: ReferenceKind::StructFieldShorthandForField, 247 kind: ReferenceKind::FieldShorthandForField,
248 access: reference_access(&field, &name_ref), 248 access: reference_access(&field, &name_ref),
249 }), 249 }),
250 Definition::Local(l) if &local == l => refs.push(Reference { 250 Definition::Local(l) if &local == l => refs.push(Reference {
251 file_range: sema.original_range(name_ref.syntax()), 251 file_range: sema.original_range(name_ref.syntax()),
252 kind: ReferenceKind::StructFieldShorthandForLocal, 252 kind: ReferenceKind::FieldShorthandForLocal,
253 access: reference_access(&Definition::Local(local), &name_ref), 253 access: reference_access(&Definition::Local(local), &name_ref),
254 }), 254 }),
255 255
@@ -267,7 +267,7 @@ impl Definition {
267fn reference_access(def: &Definition, name_ref: &ast::NameRef) -> Option<ReferenceAccess> { 267fn reference_access(def: &Definition, name_ref: &ast::NameRef) -> Option<ReferenceAccess> {
268 // Only Locals and Fields have accesses for now. 268 // Only Locals and Fields have accesses for now.
269 match def { 269 match def {
270 Definition::Local(_) | Definition::StructField(_) => {} 270 Definition::Local(_) | Definition::Field(_) => {}
271 _ => return None, 271 _ => return None,
272 }; 272 };
273 273