Merge NameDefinition and NameKind

This commit is contained in:
Aleksey Kladov 2020-02-19 14:56:22 +01:00
parent 0d5ae89948
commit 372439dec8
8 changed files with 91 additions and 119 deletions

View file

@ -1,7 +1,7 @@
//! FIXME: write short doc here //! FIXME: write short doc here
use hir::{db::AstDatabase, InFile, SourceBinder}; use hir::{db::AstDatabase, InFile, SourceBinder};
use ra_ide_db::{symbol_index, RootDatabase}; use ra_ide_db::{defs::NameDefinition, symbol_index, RootDatabase};
use ra_syntax::{ use ra_syntax::{
ast::{self, DocCommentsOwner}, ast::{self, DocCommentsOwner},
match_ast, AstNode, match_ast, AstNode,
@ -12,7 +12,7 @@ use ra_syntax::{
use crate::{ use crate::{
display::{ShortLabel, ToNav}, display::{ShortLabel, ToNav},
expand::descend_into_macros, expand::descend_into_macros,
references::{classify_name_ref, NameKind::*}, references::classify_name_ref,
FilePosition, NavigationTarget, RangeInfo, FilePosition, NavigationTarget, RangeInfo,
}; };
@ -73,17 +73,17 @@ pub(crate) fn reference_definition(
) -> ReferenceResult { ) -> ReferenceResult {
use self::ReferenceResult::*; use self::ReferenceResult::*;
let name_kind = classify_name_ref(sb, name_ref).map(|d| d.kind); let name_kind = classify_name_ref(sb, name_ref);
match name_kind { match name_kind {
Some(Macro(it)) => return Exact(it.to_nav(sb.db)), Some(NameDefinition::Macro(it)) => return Exact(it.to_nav(sb.db)),
Some(StructField(it)) => return Exact(it.to_nav(sb.db)), Some(NameDefinition::StructField(it)) => return Exact(it.to_nav(sb.db)),
Some(TypeParam(it)) => return Exact(it.to_nav(sb.db)), Some(NameDefinition::TypeParam(it)) => return Exact(it.to_nav(sb.db)),
Some(Local(it)) => return Exact(it.to_nav(sb.db)), Some(NameDefinition::Local(it)) => return Exact(it.to_nav(sb.db)),
Some(ModuleDef(def)) => match NavigationTarget::from_def(sb.db, def) { Some(NameDefinition::ModuleDef(def)) => match NavigationTarget::from_def(sb.db, def) {
Some(nav) => return Exact(nav), Some(nav) => return Exact(nav),
None => return Approximate(vec![]), None => return Approximate(vec![]),
}, },
Some(SelfType(imp)) => { Some(NameDefinition::SelfType(imp)) => {
// FIXME: ideally, this should point to the type in the impl, and // FIXME: ideally, this should point to the type in the impl, and
// not at the whole impl. And goto **type** definition should bring // not at the whole impl. And goto **type** definition should bring
// us to the actual type // us to the actual type

View file

@ -2,7 +2,7 @@
use hir::{db::AstDatabase, Adt, HasSource, HirDisplay, SourceBinder}; use hir::{db::AstDatabase, Adt, HasSource, HirDisplay, SourceBinder};
use ra_db::SourceDatabase; use ra_db::SourceDatabase;
use ra_ide_db::RootDatabase; use ra_ide_db::{defs::NameDefinition, RootDatabase};
use ra_syntax::{ use ra_syntax::{
algo::find_covering_element, algo::find_covering_element,
ast::{self, DocCommentsOwner}, ast::{self, DocCommentsOwner},
@ -14,7 +14,7 @@ use ra_syntax::{
use crate::{ use crate::{
display::{macro_label, rust_code_markup, rust_code_markup_with_doc, ShortLabel}, display::{macro_label, rust_code_markup, rust_code_markup_with_doc, ShortLabel},
expand::{descend_into_macros, original_range}, expand::{descend_into_macros, original_range},
references::{classify_name, classify_name_ref, NameKind, NameKind::*}, references::{classify_name, classify_name_ref},
FilePosition, FileRange, RangeInfo, FilePosition, FileRange, RangeInfo,
}; };
@ -92,20 +92,20 @@ fn hover_text(docs: Option<String>, desc: Option<String>) -> Option<String> {
} }
} }
fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option<String> { fn hover_text_from_name_kind(db: &RootDatabase, def: NameDefinition) -> Option<String> {
return match name_kind { return match def {
Macro(it) => { NameDefinition::Macro(it) => {
let src = it.source(db); let src = it.source(db);
hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value))) hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value)))
} }
StructField(it) => { NameDefinition::StructField(it) => {
let src = it.source(db); let src = it.source(db);
match src.value { match src.value {
hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()),
_ => None, _ => None,
} }
} }
ModuleDef(it) => match it { NameDefinition::ModuleDef(it) => match it {
hir::ModuleDef::Module(it) => match it.definition_source(db).value { hir::ModuleDef::Module(it) => match it.definition_source(db).value {
hir::ModuleSource::Module(it) => { hir::ModuleSource::Module(it) => {
hover_text(it.doc_comment_text(), it.short_label()) hover_text(it.doc_comment_text(), it.short_label())
@ -123,8 +123,10 @@ fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option<S
hir::ModuleDef::TypeAlias(it) => from_def_source(db, it), hir::ModuleDef::TypeAlias(it) => from_def_source(db, it),
hir::ModuleDef::BuiltinType(it) => Some(it.to_string()), hir::ModuleDef::BuiltinType(it) => Some(it.to_string()),
}, },
Local(it) => Some(rust_code_markup(it.ty(db).display_truncated(db, None).to_string())), NameDefinition::Local(it) => {
TypeParam(_) | SelfType(_) => { Some(rust_code_markup(it.ty(db).display_truncated(db, None).to_string()))
}
NameDefinition::TypeParam(_) | NameDefinition::SelfType(_) => {
// FIXME: Hover for generic param // FIXME: Hover for generic param
None None
} }
@ -151,10 +153,10 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
if let Some((node, name_kind)) = match_ast! { if let Some((node, name_kind)) = match_ast! {
match (token.value.parent()) { match (token.value.parent()) {
ast::NameRef(name_ref) => { ast::NameRef(name_ref) => {
classify_name_ref(&mut sb, token.with_value(&name_ref)).map(|d| (name_ref.syntax().clone(), d.kind)) classify_name_ref(&mut sb, token.with_value(&name_ref)).map(|d| (name_ref.syntax().clone(), d))
}, },
ast::Name(name) => { ast::Name(name) => {
classify_name(&mut sb, token.with_value(&name)).map(|d| (name.syntax().clone(), d.kind)) classify_name(&mut sb, token.with_value(&name)).map(|d| (name.syntax().clone(), d))
}, },
_ => None, _ => None,
} }

View file

@ -31,7 +31,7 @@ pub(crate) use self::{
classify::{classify_name, classify_name_ref}, classify::{classify_name, classify_name_ref},
rename::rename, rename::rename,
}; };
pub(crate) use ra_ide_db::defs::{NameDefinition, NameKind}; pub(crate) use ra_ide_db::defs::NameDefinition;
pub use self::search_scope::SearchScope; pub use self::search_scope::SearchScope;
@ -126,13 +126,13 @@ pub(crate) fn find_all_refs(
let RangeInfo { range, info: (name, def) } = find_name(db, &syntax, position, opt_name)?; let RangeInfo { range, info: (name, def) } = find_name(db, &syntax, position, opt_name)?;
let declaration = match def.kind { let declaration = match def {
NameKind::Macro(mac) => mac.to_nav(db), NameDefinition::Macro(mac) => mac.to_nav(db),
NameKind::StructField(field) => field.to_nav(db), NameDefinition::StructField(field) => field.to_nav(db),
NameKind::ModuleDef(def) => NavigationTarget::from_def(db, def)?, NameDefinition::ModuleDef(def) => NavigationTarget::from_def(db, def)?,
NameKind::SelfType(imp) => imp.to_nav(db), NameDefinition::SelfType(imp) => imp.to_nav(db),
NameKind::Local(local) => local.to_nav(db), NameDefinition::Local(local) => local.to_nav(db),
NameKind::TypeParam(_) => return None, NameDefinition::TypeParam(_) => return None,
}; };
let search_scope = { let search_scope = {
@ -148,7 +148,7 @@ pub(crate) fn find_all_refs(
let declaration = Declaration { let declaration = Declaration {
nav: declaration, nav: declaration,
kind: ReferenceKind::Other, kind: ReferenceKind::Other,
access: decl_access(&def.kind, &name, &syntax, decl_range), access: decl_access(&def, &name, &syntax, decl_range),
}; };
let references = process_definition(db, def, name, search_scope) let references = process_definition(db, def, name, search_scope)
@ -247,7 +247,7 @@ fn process_definition(
refs.push(Reference { refs.push(Reference {
file_range: FileRange { file_id, range }, file_range: FileRange { file_id, range },
kind, kind,
access: reference_access(&d.kind, &name_ref.value), access: reference_access(&d, &name_ref.value),
}); });
} }
} }
@ -257,13 +257,13 @@ fn process_definition(
} }
fn decl_access( fn decl_access(
kind: &NameKind, def: &NameDefinition,
name: &str, name: &str,
syntax: &SyntaxNode, syntax: &SyntaxNode,
range: TextRange, range: TextRange,
) -> Option<ReferenceAccess> { ) -> Option<ReferenceAccess> {
match kind { match def {
NameKind::Local(_) | NameKind::StructField(_) => {} NameDefinition::Local(_) | NameDefinition::StructField(_) => {}
_ => return None, _ => return None,
}; };
@ -280,10 +280,10 @@ fn decl_access(
None None
} }
fn reference_access(kind: &NameKind, name_ref: &ast::NameRef) -> Option<ReferenceAccess> { fn reference_access(def: &NameDefinition, name_ref: &ast::NameRef) -> Option<ReferenceAccess> {
// Only Locals and Fields have accesses for now. // Only Locals and Fields have accesses for now.
match kind { match def {
NameKind::Local(_) | NameKind::StructField(_) => {} NameDefinition::Local(_) | NameDefinition::StructField(_) => {}
_ => return None, _ => return None,
}; };

View file

@ -5,7 +5,7 @@ use ra_prof::profile;
use ra_syntax::{ast, AstNode}; use ra_syntax::{ast, AstNode};
use test_utils::tested_by; use test_utils::tested_by;
use super::{NameDefinition, NameKind}; use super::NameDefinition;
use ra_ide_db::RootDatabase; use ra_ide_db::RootDatabase;
pub use ra_ide_db::defs::{classify_name, from_module_def, from_struct_field}; pub use ra_ide_db::defs::{classify_name, from_module_def, from_struct_field};
@ -46,8 +46,7 @@ pub(crate) fn classify_name_ref(
if let Some(macro_def) = if let Some(macro_def) =
analyzer.resolve_macro_call(sb.db, name_ref.with_value(&macro_call)) analyzer.resolve_macro_call(sb.db, name_ref.with_value(&macro_call))
{ {
let kind = NameKind::Macro(macro_def); return Some(NameDefinition::Macro(macro_def));
return Some(NameDefinition { kind });
} }
} }
@ -63,22 +62,10 @@ pub(crate) fn classify_name_ref(
}; };
from_module_def(def) from_module_def(def)
} }
PathResolution::Local(local) => { PathResolution::Local(local) => NameDefinition::Local(local),
let kind = NameKind::Local(local); PathResolution::TypeParam(par) => NameDefinition::TypeParam(par),
NameDefinition { kind } PathResolution::Macro(def) => NameDefinition::Macro(def),
} PathResolution::SelfType(impl_block) => NameDefinition::SelfType(impl_block),
PathResolution::TypeParam(par) => {
let kind = NameKind::TypeParam(par);
NameDefinition { kind }
}
PathResolution::Macro(def) => {
let kind = NameKind::Macro(def);
NameDefinition { kind }
}
PathResolution::SelfType(impl_block) => {
let kind = NameKind::SelfType(impl_block);
NameDefinition { kind }
}
}; };
Some(res) Some(res)
} }

View file

@ -12,7 +12,7 @@ use rustc_hash::FxHashMap;
use ra_ide_db::RootDatabase; use ra_ide_db::RootDatabase;
use super::{NameDefinition, NameKind}; use super::NameDefinition;
pub struct SearchScope { pub struct SearchScope {
entries: FxHashMap<FileId, Option<TextRange>>, entries: FxHashMap<FileId, Option<TextRange>>,
@ -32,7 +32,7 @@ impl SearchScope {
let module_src = module.definition_source(db); let module_src = module.definition_source(db);
let file_id = module_src.file_id.original_file(db); let file_id = module_src.file_id.original_file(db);
if let NameKind::Local(var) = def.kind { if let NameDefinition::Local(var) = def {
let range = match var.parent(db) { let range = match var.parent(db) {
DefWithBody::Function(f) => f.source(db).value.syntax().text_range(), DefWithBody::Function(f) => f.source(db).value.syntax().text_range(),
DefWithBody::Const(c) => c.source(db).value.syntax().text_range(), DefWithBody::Const(c) => c.source(db).value.syntax().text_range(),

View file

@ -2,7 +2,7 @@
use hir::{HirFileId, InFile, Name, SourceAnalyzer, SourceBinder}; use hir::{HirFileId, InFile, Name, SourceAnalyzer, SourceBinder};
use ra_db::SourceDatabase; use ra_db::SourceDatabase;
use ra_ide_db::RootDatabase; use ra_ide_db::{defs::NameDefinition, RootDatabase};
use ra_prof::profile; use ra_prof::profile;
use ra_syntax::{ use ra_syntax::{
ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxToken, TextRange, ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxToken, TextRange,
@ -12,7 +12,7 @@ use rustc_hash::FxHashMap;
use crate::{ use crate::{
expand::descend_into_macros_with_analyzer, expand::descend_into_macros_with_analyzer,
references::{classify_name, classify_name_ref, NameKind}, references::{classify_name, classify_name_ref},
FileId, FileId,
}; };
@ -186,10 +186,10 @@ fn highlight_node(
NAME_REF if node.value.ancestors().any(|it| it.kind() == ATTR) => return None, NAME_REF if node.value.ancestors().any(|it| it.kind() == ATTR) => return None,
NAME_REF => { NAME_REF => {
let name_ref = node.value.as_node().cloned().and_then(ast::NameRef::cast).unwrap(); let name_ref = node.value.as_node().cloned().and_then(ast::NameRef::cast).unwrap();
let name_kind = classify_name_ref(sb, node.with_value(&name_ref)).map(|d| d.kind); let name_kind = classify_name_ref(sb, node.with_value(&name_ref));
match name_kind { match name_kind {
Some(name_kind) => { Some(name_kind) => {
if let NameKind::Local(local) = &name_kind { if let NameDefinition::Local(local) = &name_kind {
if let Some(name) = local.name(db) { if let Some(name) = local.name(db) {
let shadow_count = let shadow_count =
bindings_shadow_count.entry(name.clone()).or_default(); bindings_shadow_count.entry(name.clone()).or_default();
@ -205,9 +205,9 @@ fn highlight_node(
} }
NAME => { NAME => {
let name = node.value.as_node().cloned().and_then(ast::Name::cast).unwrap(); let name = node.value.as_node().cloned().and_then(ast::Name::cast).unwrap();
let name_kind = classify_name(sb, node.with_value(&name)).map(|d| d.kind); let name_kind = classify_name(sb, node.with_value(&name));
if let Some(NameKind::Local(local)) = &name_kind { if let Some(NameDefinition::Local(local)) = &name_kind {
if let Some(name) = local.name(db) { if let Some(name) = local.name(db) {
let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); let shadow_count = bindings_shadow_count.entry(name.clone()).or_default();
*shadow_count += 1; *shadow_count += 1;
@ -310,22 +310,22 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
buf buf
} }
fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { fn highlight_name(db: &RootDatabase, def: NameDefinition) -> &'static str {
match name_kind { match def {
NameKind::Macro(_) => tags::MACRO, NameDefinition::Macro(_) => tags::MACRO,
NameKind::StructField(_) => tags::FIELD, NameDefinition::StructField(_) => tags::FIELD,
NameKind::ModuleDef(hir::ModuleDef::Module(_)) => tags::MODULE, NameDefinition::ModuleDef(hir::ModuleDef::Module(_)) => tags::MODULE,
NameKind::ModuleDef(hir::ModuleDef::Function(_)) => tags::FUNCTION, NameDefinition::ModuleDef(hir::ModuleDef::Function(_)) => tags::FUNCTION,
NameKind::ModuleDef(hir::ModuleDef::Adt(_)) => tags::TYPE, NameDefinition::ModuleDef(hir::ModuleDef::Adt(_)) => tags::TYPE,
NameKind::ModuleDef(hir::ModuleDef::EnumVariant(_)) => tags::CONSTANT, NameDefinition::ModuleDef(hir::ModuleDef::EnumVariant(_)) => tags::CONSTANT,
NameKind::ModuleDef(hir::ModuleDef::Const(_)) => tags::CONSTANT, NameDefinition::ModuleDef(hir::ModuleDef::Const(_)) => tags::CONSTANT,
NameKind::ModuleDef(hir::ModuleDef::Static(_)) => tags::CONSTANT, NameDefinition::ModuleDef(hir::ModuleDef::Static(_)) => tags::CONSTANT,
NameKind::ModuleDef(hir::ModuleDef::Trait(_)) => tags::TYPE, NameDefinition::ModuleDef(hir::ModuleDef::Trait(_)) => tags::TYPE,
NameKind::ModuleDef(hir::ModuleDef::TypeAlias(_)) => tags::TYPE, NameDefinition::ModuleDef(hir::ModuleDef::TypeAlias(_)) => tags::TYPE,
NameKind::ModuleDef(hir::ModuleDef::BuiltinType(_)) => tags::TYPE_BUILTIN, NameDefinition::ModuleDef(hir::ModuleDef::BuiltinType(_)) => tags::TYPE_BUILTIN,
NameKind::SelfType(_) => tags::TYPE_SELF, NameDefinition::SelfType(_) => tags::TYPE_SELF,
NameKind::TypeParam(_) => tags::TYPE_PARAM, NameDefinition::TypeParam(_) => tags::TYPE_PARAM,
NameKind::Local(local) => { NameDefinition::Local(local) => {
if local.is_mut(db) || local.ty(db).is_mutable_reference() { if local.is_mut(db) || local.ty(db).is_mutable_reference() {
tags::VARIABLE_MUT tags::VARIABLE_MUT
} else { } else {

View file

@ -18,7 +18,7 @@ use ra_syntax::{
use crate::RootDatabase; use crate::RootDatabase;
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum NameKind { pub enum NameDefinition {
Macro(MacroDef), Macro(MacroDef),
StructField(StructField), StructField(StructField),
ModuleDef(ModuleDef), ModuleDef(ModuleDef),
@ -27,33 +27,26 @@ pub enum NameKind {
TypeParam(TypeParam), TypeParam(TypeParam),
} }
#[derive(PartialEq, Eq)]
pub struct NameDefinition {
/// FIXME: this doesn't really make sense. For example, builtin types don't
/// really have a module.
pub kind: NameKind,
}
impl NameDefinition { impl NameDefinition {
pub fn module(&self, db: &RootDatabase) -> Option<Module> { pub fn module(&self, db: &RootDatabase) -> Option<Module> {
match self.kind { match self {
NameKind::Macro(it) => it.module(db), NameDefinition::Macro(it) => it.module(db),
NameKind::StructField(it) => Some(it.parent_def(db).module(db)), NameDefinition::StructField(it) => Some(it.parent_def(db).module(db)),
NameKind::ModuleDef(it) => it.module(db), NameDefinition::ModuleDef(it) => it.module(db),
NameKind::SelfType(it) => Some(it.module(db)), NameDefinition::SelfType(it) => Some(it.module(db)),
NameKind::Local(it) => Some(it.module(db)), NameDefinition::Local(it) => Some(it.module(db)),
NameKind::TypeParam(it) => Some(it.module(db)), NameDefinition::TypeParam(it) => Some(it.module(db)),
} }
} }
pub fn visibility(&self, db: &RootDatabase) -> Option<ast::Visibility> { pub fn visibility(&self, db: &RootDatabase) -> Option<ast::Visibility> {
match self.kind { match self {
NameKind::Macro(_) => None, NameDefinition::Macro(_) => None,
NameKind::StructField(sf) => match sf.source(db).value { NameDefinition::StructField(sf) => match sf.source(db).value {
FieldSource::Named(it) => it.visibility(), FieldSource::Named(it) => it.visibility(),
FieldSource::Pos(it) => it.visibility(), FieldSource::Pos(it) => it.visibility(),
}, },
NameKind::ModuleDef(def) => match def { NameDefinition::ModuleDef(def) => match def {
ModuleDef::Module(it) => it.declaration_source(db)?.value.visibility(), ModuleDef::Module(it) => it.declaration_source(db)?.value.visibility(),
ModuleDef::Function(it) => it.source(db).value.visibility(), ModuleDef::Function(it) => it.source(db).value.visibility(),
ModuleDef::Adt(adt) => match adt { ModuleDef::Adt(adt) => match adt {
@ -68,9 +61,9 @@ impl NameDefinition {
ModuleDef::EnumVariant(_) => None, ModuleDef::EnumVariant(_) => None,
ModuleDef::BuiltinType(_) => None, ModuleDef::BuiltinType(_) => None,
}, },
NameKind::SelfType(_) => None, NameDefinition::SelfType(_) => None,
NameKind::Local(_) => None, NameDefinition::Local(_) => None,
NameKind::TypeParam(_) => None, NameDefinition::TypeParam(_) => None,
} }
} }
} }
@ -87,9 +80,7 @@ pub fn classify_name(
ast::BindPat(it) => { ast::BindPat(it) => {
let src = name.with_value(it); let src = name.with_value(it);
let local = sb.to_def(src)?; let local = sb.to_def(src)?;
Some(NameDefinition { Some(NameDefinition::Local(local))
kind: NameKind::Local(local),
})
}, },
ast::RecordFieldDef(it) => { ast::RecordFieldDef(it) => {
let src = name.with_value(it); let src = name.with_value(it);
@ -144,16 +135,12 @@ pub fn classify_name(
let src = name.with_value(it); let src = name.with_value(it);
let def = sb.to_def(src.clone())?; let def = sb.to_def(src.clone())?;
Some(NameDefinition { Some(NameDefinition::Macro(def))
kind: NameKind::Macro(def),
})
}, },
ast::TypeParam(it) => { ast::TypeParam(it) => {
let src = name.with_value(it); let src = name.with_value(it);
let def = sb.to_def(src)?; let def = sb.to_def(src)?;
Some(NameDefinition { Some(NameDefinition::TypeParam(def))
kind: NameKind::TypeParam(def),
})
}, },
_ => None, _ => None,
} }
@ -161,11 +148,9 @@ pub fn classify_name(
} }
pub fn from_struct_field(field: StructField) -> NameDefinition { pub fn from_struct_field(field: StructField) -> NameDefinition {
let kind = NameKind::StructField(field); NameDefinition::StructField(field)
NameDefinition { kind }
} }
pub fn from_module_def(def: ModuleDef) -> NameDefinition { pub fn from_module_def(def: ModuleDef) -> NameDefinition {
let kind = NameKind::ModuleDef(def); NameDefinition::ModuleDef(def)
NameDefinition { kind }
} }

View file

@ -6,8 +6,7 @@ use ra_prof::profile;
use ra_syntax::{ast, AstNode, SyntaxKind::NAME}; use ra_syntax::{ast, AstNode, SyntaxKind::NAME};
use crate::{ use crate::{
defs::classify_name, defs::{classify_name, NameDefinition},
defs::NameKind,
symbol_index::{self, FileSymbol, Query}, symbol_index::{self, FileSymbol, Query},
RootDatabase, RootDatabase,
}; };
@ -44,7 +43,7 @@ impl<'a> ImportsLocator<'a> {
.chain(lib_results.into_iter()) .chain(lib_results.into_iter())
.filter_map(|import_candidate| self.get_name_definition(db, &import_candidate)) .filter_map(|import_candidate| self.get_name_definition(db, &import_candidate))
.filter_map(|name_definition_to_import| match name_definition_to_import { .filter_map(|name_definition_to_import| match name_definition_to_import {
NameKind::ModuleDef(module_def) => Some(module_def), NameDefinition::ModuleDef(module_def) => Some(module_def),
_ => None, _ => None,
}) })
.collect() .collect()
@ -54,7 +53,7 @@ impl<'a> ImportsLocator<'a> {
&mut self, &mut self,
db: &impl HirDatabase, db: &impl HirDatabase,
import_candidate: &FileSymbol, import_candidate: &FileSymbol,
) -> Option<NameKind> { ) -> Option<NameDefinition> {
let _p = profile("get_name_definition"); let _p = profile("get_name_definition");
let file_id = import_candidate.file_id.into(); let file_id = import_candidate.file_id.into();
let candidate_node = import_candidate.ptr.to_node(&db.parse_or_expand(file_id)?); let candidate_node = import_candidate.ptr.to_node(&db.parse_or_expand(file_id)?);
@ -67,6 +66,5 @@ impl<'a> ImportsLocator<'a> {
&mut self.source_binder, &mut self.source_binder,
hir::InFile { file_id, value: &ast::Name::cast(candidate_name_node)? }, hir::InFile { file_id, value: &ast::Name::cast(candidate_name_node)? },
) )
.map(|it| it.kind)
} }
} }