From 9710ad8c488e63fc46ab911e2d0787dafacb87e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 1 Jul 2020 15:11:34 +0300 Subject: Reuse Semantics instances --- crates/ra_ide_db/src/search.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide_db/src') diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs index 44d5c35e6..81553150b 100644 --- a/crates/ra_ide_db/src/search.rs +++ b/crates/ra_ide_db/src/search.rs @@ -180,20 +180,20 @@ impl Definition { pub fn find_usages( &self, - db: &RootDatabase, + sema: &Semantics, search_scope: Option, ) -> Vec { let _p = profile("Definition::find_usages"); let search_scope = { - let base = self.search_scope(db); + let base = self.search_scope(sema.db); match search_scope { None => base, Some(scope) => base.intersection(&scope), } }; - let name = match self.name(db) { + let name = match self.name(sema.db) { None => return Vec::new(), Some(it) => it.to_string(), }; @@ -202,11 +202,10 @@ impl Definition { let mut refs = vec![]; for (file_id, search_range) in search_scope { - let text = db.file_text(file_id); + let text = sema.db.file_text(file_id); let search_range = search_range.unwrap_or(TextRange::up_to(TextSize::of(text.as_str()))); - let sema = Semantics::new(db); let tree = Lazy::new(|| sema.parse(file_id).syntax().clone()); for (idx, _) in text.match_indices(pat) { @@ -222,9 +221,6 @@ impl Definition { continue; }; - // FIXME: reuse sb - // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098 - match classify_name_ref(&sema, &name_ref) { Some(NameRefClass::Definition(def)) if &def == self => { let kind = if is_record_lit_name_ref(&name_ref) -- cgit v1.2.3