From e31420fbe2986884783c2baba02b34003cc3b28a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 18 Jan 2021 21:10:01 +0100 Subject: Remove obsolete RangeInfo usage in references --- crates/ide/src/call_hierarchy.rs | 2 +- crates/ide/src/lib.rs | 4 +--- crates/ide/src/references.rs | 52 ++++++++++++++-------------------------- 3 files changed, 20 insertions(+), 38 deletions(-) (limited to 'crates') diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index e8999a7f3..b10a0a78b 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs @@ -47,7 +47,7 @@ pub(crate) fn incoming_calls(db: &RootDatabase, position: FilePosition) -> Optio let mut calls = CallLocations::default(); - for (&file_id, references) in refs.info.references().iter() { + for (&file_id, references) in refs.references().iter() { let file = sema.parse(file_id); let file = file.syntax(); for reference in references { diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 3abbb14c6..567b8117e 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -369,9 +369,7 @@ impl Analysis { position: FilePosition, search_scope: Option, ) -> Cancelable> { - self.with_db(|db| { - references::find_all_refs(&Semantics::new(db), position, search_scope).map(|it| it.info) - }) + self.with_db(|db| references::find_all_refs(&Semantics::new(db), position, search_scope)) } /// Finds all methods and free functions for the file. Does not return tests! diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index df9c31aef..3a4f4d80b 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -25,7 +25,7 @@ use syntax::{ AstNode, SyntaxNode, TextRange, TokenAtOffset, T, }; -use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo}; +use crate::{display::TryToNav, FilePosition, NavigationTarget}; #[derive(Debug, Clone)] pub struct ReferenceSearchResult { @@ -41,14 +41,6 @@ pub struct Declaration { } impl ReferenceSearchResult { - pub fn declaration(&self) -> &Declaration { - &self.declaration - } - - pub fn decl_target(&self) -> &NavigationTarget { - &self.declaration.nav - } - pub fn references(&self) -> &UsageSearchResult { &self.references } @@ -87,7 +79,7 @@ pub(crate) fn find_all_refs( sema: &Semantics, position: FilePosition, search_scope: Option, -) -> Option> { +) -> Option { let _p = profile::span("find_all_refs"); let syntax = sema.parse(position.file_id).syntax().clone(); @@ -105,7 +97,7 @@ pub(crate) fn find_all_refs( ) }; - let RangeInfo { range, info: def } = find_name(&sema, &syntax, position, opt_name)?; + let def = find_name(&sema, &syntax, position, opt_name)?; let mut usages = def.usages(sema).set_scope(search_scope).all(); usages @@ -139,7 +131,7 @@ pub(crate) fn find_all_refs( let declaration = Declaration { nav, kind, access: decl_access(&def, &syntax, decl_range) }; - Some(RangeInfo::new(range, ReferenceSearchResult { declaration, references: usages })) + Some(ReferenceSearchResult { declaration, references: usages }) } fn find_name( @@ -147,35 +139,27 @@ fn find_name( syntax: &SyntaxNode, position: FilePosition, opt_name: Option, -) -> Option> { - if let Some(name) = opt_name { - let def = NameClass::classify(sema, &name)?.referenced_or_defined(sema.db); - let FileRange { range, .. } = sema.original_range(name.syntax()); - return Some(RangeInfo::new(range, def)); - } - - let (FileRange { range, .. }, def) = if let Some(lifetime) = +) -> Option { + let def = if let Some(name) = opt_name { + NameClass::classify(sema, &name)?.referenced_or_defined(sema.db) + } else if let Some(lifetime) = sema.find_node_at_offset_with_descend::(&syntax, position.offset) { - if let Some(def) = NameRefClass::classify_lifetime(sema, &lifetime) - .map(|class| NameRefClass::referenced(class, sema.db)) + if let Some(def) = + NameRefClass::classify_lifetime(sema, &lifetime).map(|class| class.referenced(sema.db)) { - (sema.original_range(lifetime.syntax()), def) + def } else { - ( - sema.original_range(lifetime.syntax()), - NameClass::classify_lifetime(sema, &lifetime)?.referenced_or_defined(sema.db), - ) + NameClass::classify_lifetime(sema, &lifetime)?.referenced_or_defined(sema.db) } + } else if let Some(name_ref) = + sema.find_node_at_offset_with_descend::(&syntax, position.offset) + { + NameRefClass::classify(sema, &name_ref)?.referenced(sema.db) } else { - let name_ref = - sema.find_node_at_offset_with_descend::(&syntax, position.offset)?; - ( - sema.original_range(name_ref.syntax()), - NameRefClass::classify(sema, &name_ref)?.referenced(sema.db), - ) + return None; }; - Some(RangeInfo::new(range, def)) + Some(def) } fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Option { -- cgit v1.2.3