From fa3c449d8f5a67865cab8d4717b3e32dca5b672a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 15 Oct 2020 16:15:01 +0200 Subject: Clarify NameClass names a bit --- crates/ide/src/doc_links.rs | 2 +- crates/ide/src/goto_definition.rs | 2 +- crates/ide/src/hover.rs | 2 +- crates/ide/src/references.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index db3f911c8..71382f13e 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -233,7 +233,7 @@ pub(crate) fn external_docs( let definition = match_ast! { match node { ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)), - ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition(sema.db)), + ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition_or_reference(sema.db)), _ => None, } }; diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 582bf4837..79fdb75ed 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -40,7 +40,7 @@ pub(crate) fn goto_definition( reference_definition(&sema, &name_ref).to_vec() }, ast::Name(name) => { - let def = classify_name(&sema, &name)?.definition(sema.db); + let def = classify_name(&sema, &name)?.definition_or_reference(sema.db); let nav = def.try_to_nav(sema.db)?; vec![nav] }, diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 632eaf0a0..51f03c718 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -108,7 +108,7 @@ pub(crate) fn hover( let definition = match_ast! { match node { ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)), - ast::Name(name) => classify_name(&sema, &name).and_then(|d| d.into_definition(sema.db)), + ast::Name(name) => classify_name(&sema, &name).and_then(|d| d.definition(sema.db)), _ => None, } }; diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 88e2f2db3..ec64207d2 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -132,7 +132,7 @@ fn find_name( opt_name: Option, ) -> Option> { if let Some(name) = opt_name { - let def = classify_name(sema, &name)?.definition(sema.db); + let def = classify_name(sema, &name)?.definition_or_reference(sema.db); let range = name.syntax().text_range(); return Some(RangeInfo::new(range, def)); } -- cgit v1.2.3 From bc287b8f9b7711a38d97be3b619758bb05d54c45 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 15 Oct 2020 16:23:55 +0200 Subject: Unconfuse expression and pattern field init shorthands --- crates/ide/src/syntax_highlighting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 527888306..4d8cd98c7 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -459,7 +459,7 @@ fn highlight_element( highlight_def(db, def) | HighlightModifier::Definition } Some(NameClass::ConstReference(def)) => highlight_def(db, def), - Some(NameClass::FieldShorthand { field, .. }) => { + Some(NameClass::PatFieldShorthand { field, .. }) => { let mut h = HighlightTag::Field.into(); if let Definition::Field(field) = field { if let VariantDef::Union(_) = field.parent_def(db) { -- cgit v1.2.3 From f9c1336873d65805ad34129939d800dbf59daf61 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 15 Oct 2020 17:18:07 +0200 Subject: More clarifications --- crates/ide/src/doc_links.rs | 2 +- crates/ide/src/goto_definition.rs | 2 +- crates/ide/src/references.rs | 2 +- crates/ide/src/syntax_highlighting.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 71382f13e..5e4147362 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -233,7 +233,7 @@ pub(crate) fn external_docs( let definition = match_ast! { match node { ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)), - ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition_or_reference(sema.db)), + ast::Name(name) => classify_name(&sema, &name).map(|d| d.reference_or_definition(sema.db)), _ => None, } }; diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 79fdb75ed..be2f81aab 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -40,7 +40,7 @@ pub(crate) fn goto_definition( reference_definition(&sema, &name_ref).to_vec() }, ast::Name(name) => { - let def = classify_name(&sema, &name)?.definition_or_reference(sema.db); + let def = classify_name(&sema, &name)?.reference_or_definition(sema.db); let nav = def.try_to_nav(sema.db)?; vec![nav] }, diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index ec64207d2..95d872b83 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -132,7 +132,7 @@ fn find_name( opt_name: Option, ) -> Option> { if let Some(name) = opt_name { - let def = classify_name(sema, &name)?.definition_or_reference(sema.db); + let def = classify_name(sema, &name)?.reference_or_definition(sema.db); let range = name.syntax().text_range(); return Some(RangeInfo::new(range, def)); } diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 4d8cd98c7..928f771a9 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -459,9 +459,9 @@ fn highlight_element( highlight_def(db, def) | HighlightModifier::Definition } Some(NameClass::ConstReference(def)) => highlight_def(db, def), - Some(NameClass::PatFieldShorthand { field, .. }) => { + Some(NameClass::PatFieldShorthand { field_ref, .. }) => { let mut h = HighlightTag::Field.into(); - if let Definition::Field(field) = field { + if let Definition::Field(field) = field_ref { if let VariantDef::Union(_) = field.parent_def(db) { h |= HighlightModifier::Unsafe; } -- cgit v1.2.3 From 56e67e3a392d7c7c7f30ca39d8e83446ea8bbec3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 15 Oct 2020 17:27:50 +0200 Subject: More idiomatic classification API --- crates/ide/src/doc_links.rs | 6 +++--- crates/ide/src/goto_definition.rs | 6 +++--- crates/ide/src/hover.rs | 6 +++--- crates/ide/src/references.rs | 6 +++--- crates/ide/src/references/rename.rs | 6 +++--- crates/ide/src/syntax_highlighting.rs | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 5e4147362..592a8e3ad 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -14,7 +14,7 @@ use hir::{ ModuleDef, }; use ide_db::{ - defs::{classify_name, classify_name_ref, Definition}, + defs::{Definition, NameClass, NameRefClass}, RootDatabase, }; use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T}; @@ -232,8 +232,8 @@ pub(crate) fn external_docs( let node = token.parent(); let definition = match_ast! { match node { - ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)), - ast::Name(name) => classify_name(&sema, &name).map(|d| d.reference_or_definition(sema.db)), + ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.definition(sema.db)), + ast::Name(name) => NameClass::classify(&sema, &name).map(|d| d.reference_or_definition(sema.db)), _ => None, } }; diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index be2f81aab..db6ad689e 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -1,6 +1,6 @@ use hir::Semantics; use ide_db::{ - defs::{classify_name, classify_name_ref}, + defs::{NameClass, NameRefClass}, symbol_index, RootDatabase, }; use syntax::{ @@ -40,7 +40,7 @@ pub(crate) fn goto_definition( reference_definition(&sema, &name_ref).to_vec() }, ast::Name(name) => { - let def = classify_name(&sema, &name)?.reference_or_definition(sema.db); + let def = NameClass::classify(&sema, &name)?.reference_or_definition(sema.db); let nav = def.try_to_nav(sema.db)?; vec![nav] }, @@ -81,7 +81,7 @@ pub(crate) fn reference_definition( sema: &Semantics, name_ref: &ast::NameRef, ) -> ReferenceResult { - let name_kind = classify_name_ref(sema, name_ref); + let name_kind = NameRefClass::classify(sema, name_ref); if let Some(def) = name_kind { let def = def.definition(sema.db); return match def.try_to_nav(sema.db) { diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 51f03c718..e915a753e 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -4,7 +4,7 @@ use hir::{ Module, ModuleDef, ModuleSource, Semantics, }; use ide_db::{ - defs::{classify_name, classify_name_ref, Definition}, + defs::{Definition, NameClass, NameRefClass}, RootDatabase, }; use itertools::Itertools; @@ -107,8 +107,8 @@ pub(crate) fn hover( let node = token.parent(); let definition = match_ast! { match node { - ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)), - ast::Name(name) => classify_name(&sema, &name).and_then(|d| d.definition(sema.db)), + ast::Name(name) => NameClass::classify(&sema, &name).and_then(|d| d.definition(sema.db)), + ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.definition(sema.db)), _ => None, } }; diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 95d872b83..fc537b9c0 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -13,7 +13,7 @@ pub(crate) mod rename; use hir::Semantics; use ide_db::{ - defs::{classify_name, classify_name_ref, Definition}, + defs::{Definition, NameClass, NameRefClass}, search::SearchScope, RootDatabase, }; @@ -132,13 +132,13 @@ fn find_name( opt_name: Option, ) -> Option> { if let Some(name) = opt_name { - let def = classify_name(sema, &name)?.reference_or_definition(sema.db); + let def = NameClass::classify(sema, &name)?.reference_or_definition(sema.db); let range = name.syntax().text_range(); return Some(RangeInfo::new(range, def)); } let name_ref = sema.find_node_at_offset_with_descend::(&syntax, position.offset)?; - let def = classify_name_ref(sema, &name_ref)?.definition(sema.db); + let def = NameRefClass::classify(sema, &name_ref)?.definition(sema.db); let range = name_ref.syntax().text_range(); Some(RangeInfo::new(range, def)) } diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index f9a11e43d..35aafc49d 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs @@ -3,7 +3,7 @@ use base_db::SourceDatabaseExt; use hir::{Module, ModuleDef, ModuleSource, Semantics}; use ide_db::{ - defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, + defs::{Definition, NameClass, NameRefClass}, RootDatabase, }; @@ -88,13 +88,13 @@ fn find_module_at_offset( let module = match_ast! { match (ident.parent()) { ast::NameRef(name_ref) => { - match classify_name_ref(sema, &name_ref)? { + match NameRefClass::classify(sema, &name_ref)? { NameRefClass::Definition(Definition::ModuleDef(ModuleDef::Module(module))) => module, _ => return None, } }, ast::Name(name) => { - match classify_name(&sema, &name)? { + match NameClass::classify(&sema, &name)? { NameClass::Definition(Definition::ModuleDef(ModuleDef::Module(module))) => module, _ => return None, } diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 928f771a9..b35c03162 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -8,7 +8,7 @@ mod tests; use hir::{Local, Name, Semantics, VariantDef}; use ide_db::{ - defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, + defs::{Definition, NameClass, NameRefClass}, RootDatabase, }; use rustc_hash::FxHashMap; @@ -443,7 +443,7 @@ fn highlight_element( // Highlight definitions depending on the "type" of the definition. NAME => { let name = element.into_node().and_then(ast::Name::cast).unwrap(); - let name_kind = classify_name(sema, &name); + let name_kind = NameClass::classify(sema, &name); if let Some(NameClass::Definition(Definition::Local(local))) = &name_kind { if let Some(name) = local.name(db) { @@ -480,7 +480,7 @@ fn highlight_element( NAME_REF => { let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| { - match classify_name_ref(sema, &name_ref) { + match NameRefClass::classify(sema, &name_ref) { Some(name_kind) => match name_kind { NameRefClass::ExternCrate(_) => HighlightTag::Module.into(), NameRefClass::Definition(def) => { -- cgit v1.2.3 From c5868a48795c899d43fde773091f0b133bee0a59 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 15 Oct 2020 17:33:32 +0200 Subject: Clarify the names one more time --- crates/ide/src/doc_links.rs | 4 ++-- crates/ide/src/goto_definition.rs | 4 ++-- crates/ide/src/hover.rs | 4 ++-- crates/ide/src/references.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 592a8e3ad..d9dc63b33 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -232,8 +232,8 @@ pub(crate) fn external_docs( let node = token.parent(); let definition = match_ast! { match node { - ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.definition(sema.db)), - ast::Name(name) => NameClass::classify(&sema, &name).map(|d| d.reference_or_definition(sema.db)), + ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(sema.db)), + ast::Name(name) => NameClass::classify(&sema, &name).map(|d| d.referenced_or_defined(sema.db)), _ => None, } }; diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index db6ad689e..a87e31019 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -40,7 +40,7 @@ pub(crate) fn goto_definition( reference_definition(&sema, &name_ref).to_vec() }, ast::Name(name) => { - let def = NameClass::classify(&sema, &name)?.reference_or_definition(sema.db); + let def = NameClass::classify(&sema, &name)?.referenced_or_defined(sema.db); let nav = def.try_to_nav(sema.db)?; vec![nav] }, @@ -83,7 +83,7 @@ pub(crate) fn reference_definition( ) -> ReferenceResult { let name_kind = NameRefClass::classify(sema, name_ref); if let Some(def) = name_kind { - let def = def.definition(sema.db); + let def = def.referenced(sema.db); return match def.try_to_nav(sema.db) { Some(nav) => ReferenceResult::Exact(nav), None => ReferenceResult::Approximate(Vec::new()), diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index e915a753e..845333e2a 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -107,8 +107,8 @@ pub(crate) fn hover( let node = token.parent(); let definition = match_ast! { match node { - ast::Name(name) => NameClass::classify(&sema, &name).and_then(|d| d.definition(sema.db)), - ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.definition(sema.db)), + ast::Name(name) => NameClass::classify(&sema, &name).and_then(|d| d.defined(sema.db)), + ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced(sema.db)), _ => None, } }; diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index fc537b9c0..67ec257a8 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -132,13 +132,13 @@ fn find_name( opt_name: Option, ) -> Option> { if let Some(name) = opt_name { - let def = NameClass::classify(sema, &name)?.reference_or_definition(sema.db); + let def = NameClass::classify(sema, &name)?.referenced_or_defined(sema.db); let range = name.syntax().text_range(); return Some(RangeInfo::new(range, def)); } let name_ref = sema.find_node_at_offset_with_descend::(&syntax, position.offset)?; - let def = NameRefClass::classify(sema, &name_ref)?.definition(sema.db); + let def = NameRefClass::classify(sema, &name_ref)?.referenced(sema.db); let range = name_ref.syntax().text_range(); Some(RangeInfo::new(range, def)) } -- cgit v1.2.3