From 734e68da4ceb1b15b3430302f233d4700d694728 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 7 Mar 2020 23:03:56 +0100 Subject: Handle visibility in method call completion --- crates/ra_hir_def/src/data.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 9fc43f3fb..8b343af9d 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -7,13 +7,16 @@ use hir_expand::{ AstId, InFile, }; use ra_prof::profile; -use ra_syntax::ast::{self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner}; +use ra_syntax::ast::{ + self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, VisibilityOwner, +}; use crate::{ db::DefDatabase, path::{path, GenericArgs, Path}, src::HasSource, type_ref::{Mutability, TypeBound, TypeRef}, + visibility::RawVisibility, AssocContainerId, AssocItemId, ConstId, ConstLoc, Expander, FunctionId, FunctionLoc, HasModule, ImplId, Intern, Lookup, ModuleId, StaticId, TraitId, TypeAliasId, TypeAliasLoc, }; @@ -26,6 +29,7 @@ pub struct FunctionData { /// True if the first param is `self`. This is relevant to decide whether this /// can be called as a method. pub has_self_param: bool, + pub visibility: RawVisibility, } impl FunctionData { @@ -72,7 +76,9 @@ impl FunctionData { ret_type }; - let sig = FunctionData { name, params, ret_type, has_self_param }; + let visibility = RawVisibility::from_ast(db, src.map(|s| s.visibility())); + + let sig = FunctionData { name, params, ret_type, has_self_param, visibility }; Arc::new(sig) } } @@ -230,7 +236,7 @@ impl ConstData { Arc::new(ConstData::new(&node)) } - fn new(node: &N) -> ConstData { + fn new(node: &N) -> ConstData { let name = node.name().map(|n| n.as_name()); let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); ConstData { name, type_ref } -- cgit v1.2.3 From 05e1c7b1972a87abe6d352b5d0cd8a58e2b7adc7 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 8 Mar 2020 15:11:57 +0100 Subject: Handle visibility for assoc item path completion as well --- crates/ra_hir_def/src/data.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 8b343af9d..a72eb5369 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -97,6 +97,7 @@ fn desugar_future_path(orig: TypeRef) -> Path { pub struct TypeAliasData { pub name: Name, pub type_ref: Option, + pub visibility: RawVisibility, } impl TypeAliasData { @@ -104,10 +105,11 @@ impl TypeAliasData { db: &impl DefDatabase, typ: TypeAliasId, ) -> Arc { - let node = typ.lookup(db).source(db).value; - let name = node.name().map_or_else(Name::missing, |n| n.as_name()); - let type_ref = node.type_ref().map(TypeRef::from_ast); - Arc::new(TypeAliasData { name, type_ref }) + let node = typ.lookup(db).source(db); + let name = node.value.name().map_or_else(Name::missing, |n| n.as_name()); + let type_ref = node.value.type_ref().map(TypeRef::from_ast); + let visibility = RawVisibility::from_ast(db, node.map(|n| n.visibility())); + Arc::new(TypeAliasData { name, type_ref, visibility }) } } @@ -223,23 +225,28 @@ pub struct ConstData { /// const _: () = (); pub name: Option, pub type_ref: TypeRef, + pub visibility: RawVisibility, } impl ConstData { pub(crate) fn const_data_query(db: &impl DefDatabase, konst: ConstId) -> Arc { - let node = konst.lookup(db).source(db).value; - Arc::new(ConstData::new(&node)) + let node = konst.lookup(db).source(db); + Arc::new(ConstData::new(db, node)) } pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc { - let node = konst.lookup(db).source(db).value; - Arc::new(ConstData::new(&node)) + let node = konst.lookup(db).source(db); + Arc::new(ConstData::new(db, node)) } - fn new(node: &N) -> ConstData { - let name = node.name().map(|n| n.as_name()); - let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); - ConstData { name, type_ref } + fn new( + db: &impl DefDatabase, + node: InFile, + ) -> ConstData { + let name = node.value.name().map(|n| n.as_name()); + let type_ref = TypeRef::from_ast_opt(node.value.ascribed_type()); + let visibility = RawVisibility::from_ast(db, node.map(|n| n.visibility())); + ConstData { name, type_ref, visibility } } } -- cgit v1.2.3