From d49a4d1863c30e2dc6e744bf1f1dc92411912bb5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 3 Mar 2020 18:36:39 +0100 Subject: Rename NameDefinition -> Definition --- crates/ra_ide/src/display/navigation_target.rs | 16 ++++++------ crates/ra_ide/src/hover.rs | 14 +++++----- crates/ra_ide/src/references.rs | 20 ++++++-------- crates/ra_ide/src/references/classify.rs | 36 +++++++++++++------------- crates/ra_ide/src/references/search_scope.rs | 6 ++--- crates/ra_ide/src/syntax_highlighting.rs | 24 ++++++++--------- 6 files changed, 56 insertions(+), 60 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 4d3dd477e..c9c14561a 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -13,7 +13,7 @@ use ra_syntax::{ use crate::{ // expand::original_range, - references::NameDefinition, + references::Definition, FileSymbol, }; @@ -189,15 +189,15 @@ impl ToNav for FileSymbol { } } -impl TryToNav for NameDefinition { +impl TryToNav for Definition { fn try_to_nav(&self, db: &RootDatabase) -> Option { match self { - NameDefinition::Macro(it) => Some(it.to_nav(db)), - NameDefinition::StructField(it) => Some(it.to_nav(db)), - NameDefinition::ModuleDef(it) => it.try_to_nav(db), - NameDefinition::SelfType(it) => Some(it.to_nav(db)), - NameDefinition::Local(it) => Some(it.to_nav(db)), - NameDefinition::TypeParam(it) => Some(it.to_nav(db)), + Definition::Macro(it) => Some(it.to_nav(db)), + Definition::StructField(it) => Some(it.to_nav(db)), + Definition::ModuleDef(it) => it.try_to_nav(db), + Definition::SelfType(it) => Some(it.to_nav(db)), + Definition::Local(it) => Some(it.to_nav(db)), + Definition::TypeParam(it) => Some(it.to_nav(db)), } } } diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index b31956626..26c8996bc 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -2,7 +2,7 @@ use hir::{Adt, HasSource, HirDisplay, Semantics}; use ra_ide_db::{ - defs::{classify_name, NameDefinition}, + defs::{classify_name, Definition}, RootDatabase, }; use ra_syntax::{ @@ -92,20 +92,20 @@ fn hover_text(docs: Option, desc: Option) -> Option { } } -fn hover_text_from_name_kind(db: &RootDatabase, def: NameDefinition) -> Option { +fn hover_text_from_name_kind(db: &RootDatabase, def: Definition) -> Option { return match def { - NameDefinition::Macro(it) => { + Definition::Macro(it) => { let src = it.source(db); hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value))) } - NameDefinition::StructField(it) => { + Definition::StructField(it) => { let src = it.source(db); match src.value { hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), _ => None, } } - NameDefinition::ModuleDef(it) => match it { + Definition::ModuleDef(it) => match it { hir::ModuleDef::Module(it) => match it.definition_source(db).value { hir::ModuleSource::Module(it) => { hover_text(it.doc_comment_text(), it.short_label()) @@ -123,10 +123,10 @@ fn hover_text_from_name_kind(db: &RootDatabase, def: NameDefinition) -> Option from_def_source(db, it), hir::ModuleDef::BuiltinType(it) => Some(it.to_string()), }, - NameDefinition::Local(it) => { + Definition::Local(it) => { Some(rust_code_markup(it.ty(db).display_truncated(db, None).to_string())) } - NameDefinition::TypeParam(_) | NameDefinition::SelfType(_) => { + Definition::TypeParam(_) | Definition::SelfType(_) => { // FIXME: Hover for generic param None } diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index c9c9c6483..95a5c1914 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -31,7 +31,7 @@ pub(crate) use self::{ classify::{classify_name_ref, NameRefClass}, rename::rename, }; -pub(crate) use ra_ide_db::defs::{classify_name, NameDefinition}; +pub(crate) use ra_ide_db::defs::{classify_name, Definition}; pub use self::search_scope::SearchScope; @@ -145,7 +145,7 @@ pub(crate) fn find_all_refs( pub(crate) fn find_refs_to_def( db: &RootDatabase, - def: &NameDefinition, + def: &Definition, search_scope: Option, ) -> Vec { let search_scope = { @@ -169,7 +169,7 @@ fn find_name( syntax: &SyntaxNode, position: FilePosition, opt_name: Option, -) -> Option> { +) -> Option> { if let Some(name) = opt_name { let def = classify_name(sema, &name)?.definition(); let range = name.syntax().text_range(); @@ -183,7 +183,7 @@ fn find_name( fn process_definition( db: &RootDatabase, - def: &NameDefinition, + def: &Definition, name: String, scope: SearchScope, ) -> Vec { @@ -250,13 +250,9 @@ fn process_definition( refs } -fn decl_access( - def: &NameDefinition, - syntax: &SyntaxNode, - range: TextRange, -) -> Option { +fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Option { match def { - NameDefinition::Local(_) | NameDefinition::StructField(_) => {} + Definition::Local(_) | Definition::StructField(_) => {} _ => return None, }; @@ -273,10 +269,10 @@ fn decl_access( None } -fn reference_access(def: &NameDefinition, name_ref: &ast::NameRef) -> Option { +fn reference_access(def: &Definition, name_ref: &ast::NameRef) -> Option { // Only Locals and Fields have accesses for now. match def { - NameDefinition::Local(_) | NameDefinition::StructField(_) => {} + Definition::Local(_) | Definition::StructField(_) => {} _ => return None, }; diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 571236fdc..0bbf893f8 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs @@ -1,22 +1,22 @@ //! Functions that are used to classify an element from its definition or reference. use hir::{Local, PathResolution, Semantics}; -use ra_ide_db::defs::NameDefinition; +use ra_ide_db::defs::Definition; use ra_ide_db::RootDatabase; use ra_prof::profile; use ra_syntax::{ast, AstNode}; use test_utils::tested_by; pub enum NameRefClass { - NameDefinition(NameDefinition), - FieldShorthand { local: Local, field: NameDefinition }, + Definition(Definition), + FieldShorthand { local: Local, field: Definition }, } impl NameRefClass { - pub fn definition(self) -> NameDefinition { + pub fn definition(self) -> Definition { match self { - NameRefClass::NameDefinition(def) => def, - NameRefClass::FieldShorthand { local, field: _ } => NameDefinition::Local(local), + NameRefClass::Definition(def) => def, + NameRefClass::FieldShorthand { local, field: _ } => Definition::Local(local), } } } @@ -32,14 +32,14 @@ pub(crate) fn classify_name_ref( if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { tested_by!(goto_def_for_methods); if let Some(func) = sema.resolve_method_call(&method_call) { - return Some(NameRefClass::NameDefinition(NameDefinition::ModuleDef(func.into()))); + return Some(NameRefClass::Definition(Definition::ModuleDef(func.into()))); } } if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) { tested_by!(goto_def_for_fields); if let Some(field) = sema.resolve_field(&field_expr) { - return Some(NameRefClass::NameDefinition(NameDefinition::StructField(field))); + return Some(NameRefClass::Definition(Definition::StructField(field))); } } @@ -47,9 +47,9 @@ pub(crate) fn classify_name_ref( tested_by!(goto_def_for_record_fields); tested_by!(goto_def_for_field_init_shorthand); if let Some((field, local)) = sema.resolve_record_field(&record_field) { - let field = NameDefinition::StructField(field); + let field = Definition::StructField(field); let res = match local { - None => NameRefClass::NameDefinition(field), + None => NameRefClass::Definition(field), Some(local) => NameRefClass::FieldShorthand { field, local }, }; return Some(res); @@ -59,26 +59,26 @@ pub(crate) fn classify_name_ref( if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { tested_by!(goto_def_for_macros); if let Some(macro_def) = sema.resolve_macro_call(¯o_call) { - return Some(NameRefClass::NameDefinition(NameDefinition::Macro(macro_def))); + return Some(NameRefClass::Definition(Definition::Macro(macro_def))); } } let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; let resolved = sema.resolve_path(&path)?; let res = match resolved { - PathResolution::Def(def) => NameDefinition::ModuleDef(def), + PathResolution::Def(def) => Definition::ModuleDef(def), PathResolution::AssocItem(item) => { let def = match item { hir::AssocItem::Function(it) => it.into(), hir::AssocItem::Const(it) => it.into(), hir::AssocItem::TypeAlias(it) => it.into(), }; - NameDefinition::ModuleDef(def) + Definition::ModuleDef(def) } - PathResolution::Local(local) => NameDefinition::Local(local), - PathResolution::TypeParam(par) => NameDefinition::TypeParam(par), - PathResolution::Macro(def) => NameDefinition::Macro(def), - PathResolution::SelfType(impl_def) => NameDefinition::SelfType(impl_def), + PathResolution::Local(local) => Definition::Local(local), + PathResolution::TypeParam(par) => Definition::TypeParam(par), + PathResolution::Macro(def) => Definition::Macro(def), + PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def), }; - Some(NameRefClass::NameDefinition(res)) + Some(NameRefClass::Definition(res)) } diff --git a/crates/ra_ide/src/references/search_scope.rs b/crates/ra_ide/src/references/search_scope.rs index 27d483233..d98c84d91 100644 --- a/crates/ra_ide/src/references/search_scope.rs +++ b/crates/ra_ide/src/references/search_scope.rs @@ -12,7 +12,7 @@ use rustc_hash::FxHashMap; use ra_ide_db::RootDatabase; -use super::NameDefinition; +use super::Definition; pub struct SearchScope { entries: FxHashMap>, @@ -23,7 +23,7 @@ impl SearchScope { SearchScope { entries: FxHashMap::default() } } - pub(crate) fn for_def(def: &NameDefinition, db: &RootDatabase) -> SearchScope { + pub(crate) fn for_def(def: &Definition, db: &RootDatabase) -> SearchScope { let _p = profile("search_scope"); let module = match def.module(db) { Some(it) => it, @@ -32,7 +32,7 @@ impl SearchScope { let module_src = module.definition_source(db); let file_id = module_src.file_id.original_file(db); - if let NameDefinition::Local(var) = def { + if let Definition::Local(var) = def { let range = match var.parent(db) { DefWithBody::Function(f) => f.source(db).value.syntax().text_range(), DefWithBody::Const(c) => c.source(db).value.syntax().text_range(), diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 7e41db530..9e0ee2158 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -7,7 +7,7 @@ mod tests; use hir::{Name, Semantics}; use ra_ide_db::{ - defs::{classify_name, NameClass, NameDefinition}, + defs::{classify_name, Definition, NameClass}, RootDatabase, }; use ra_prof::profile; @@ -172,7 +172,7 @@ fn highlight_element( let name = element.into_node().and_then(ast::Name::cast).unwrap(); let name_kind = classify_name(sema, &name); - if let Some(NameClass::NameDefinition(NameDefinition::Local(local))) = &name_kind { + if let Some(NameClass::Definition(Definition::Local(local))) = &name_kind { if let Some(name) = local.name(db) { let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); *shadow_count += 1; @@ -181,7 +181,7 @@ fn highlight_element( }; match name_kind { - Some(NameClass::NameDefinition(def)) => { + Some(NameClass::Definition(def)) => { highlight_name(db, def) | HighlightModifier::Definition } Some(NameClass::ConstReference(def)) => highlight_name(db, def), @@ -196,8 +196,8 @@ fn highlight_element( let name_kind = classify_name_ref(sema, &name_ref)?; match name_kind { - NameRefClass::NameDefinition(def) => { - if let NameDefinition::Local(local) = &def { + NameRefClass::Definition(def) => { + if let Definition::Local(local) = &def { if let Some(name) = local.name(db) { let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); @@ -260,11 +260,11 @@ fn highlight_element( } } -fn highlight_name(db: &RootDatabase, def: NameDefinition) -> Highlight { +fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight { match def { - NameDefinition::Macro(_) => HighlightTag::Macro, - NameDefinition::StructField(_) => HighlightTag::Field, - NameDefinition::ModuleDef(def) => match def { + Definition::Macro(_) => HighlightTag::Macro, + Definition::StructField(_) => HighlightTag::Field, + Definition::ModuleDef(def) => match def { hir::ModuleDef::Module(_) => HighlightTag::Module, hir::ModuleDef::Function(_) => HighlightTag::Function, hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, @@ -277,10 +277,10 @@ fn highlight_name(db: &RootDatabase, def: NameDefinition) -> Highlight { hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, }, - NameDefinition::SelfType(_) => HighlightTag::SelfType, - NameDefinition::TypeParam(_) => HighlightTag::TypeParam, + Definition::SelfType(_) => HighlightTag::SelfType, + Definition::TypeParam(_) => HighlightTag::TypeParam, // FIXME: distinguish between locals and parameters - NameDefinition::Local(local) => { + Definition::Local(local) => { let mut h = Highlight::new(HighlightTag::Local); if local.is_mut(db) || local.ty(db).is_mutable_reference() { h |= HighlightModifier::Mutable; -- cgit v1.2.3