visible_from -> is_visible_from

This commit is contained in:
Florian Diebold 2019-12-27 11:24:31 +01:00
parent dfe95d735b
commit 9fd2c813ca
4 changed files with 10 additions and 10 deletions

View file

@ -1053,8 +1053,8 @@ impl<T: Into<AttrDef> + Copy> Docs for T {
pub trait HasVisibility { pub trait HasVisibility {
fn visibility(&self, db: &impl HirDatabase) -> Visibility; fn visibility(&self, db: &impl HirDatabase) -> Visibility;
fn visible_from(&self, db: &impl HirDatabase, module: Module) -> bool { fn is_visible_from(&self, db: &impl HirDatabase, module: Module) -> bool {
let vis = self.visibility(db); let vis = self.visibility(db);
vis.visible_from(db, module.id) vis.is_visible_from(db, module.id)
} }
} }

View file

@ -378,7 +378,7 @@ where
.resolutions() .resolutions()
// only keep visible names... // only keep visible names...
.map(|(n, res)| { .map(|(n, res)| {
(n, res.filter_visibility(|v| v.visible_from_other_crate())) (n, res.filter_visibility(|v| v.is_visible_from_other_crate()))
}) })
.filter(|(_, res)| !res.is_none()) .filter(|(_, res)| !res.is_none())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -398,7 +398,7 @@ where
( (
n, n,
res.filter_visibility(|v| { res.filter_visibility(|v| {
v.visible_from_def_map(&self.def_map, module_id) v.is_visible_from_def_map(&self.def_map, module_id)
}), }),
) )
}) })
@ -492,7 +492,7 @@ where
for (glob_importing_module, glob_import_vis) in glob_imports { for (glob_importing_module, glob_import_vis) in glob_imports {
// we know all resolutions have the same visibility (`vis`), so we // we know all resolutions have the same visibility (`vis`), so we
// just need to check that once // just need to check that once
if !vis.visible_from_def_map(&self.def_map, glob_importing_module) { if !vis.is_visible_from_def_map(&self.def_map, glob_importing_module) {
continue; continue;
} }
self.update_recursive(glob_importing_module, resolutions, glob_import_vis, depth + 1); self.update_recursive(glob_importing_module, resolutions, glob_import_vis, depth + 1);

View file

@ -81,7 +81,7 @@ pub enum Visibility {
} }
impl Visibility { impl Visibility {
pub fn visible_from(self, db: &impl DefDatabase, from_module: ModuleId) -> bool { pub fn is_visible_from(self, db: &impl DefDatabase, from_module: ModuleId) -> bool {
let to_module = match self { let to_module = match self {
Visibility::Module(m) => m, Visibility::Module(m) => m,
Visibility::Public => return true, Visibility::Public => return true,
@ -91,17 +91,17 @@ impl Visibility {
return false; return false;
} }
let def_map = db.crate_def_map(from_module.krate); let def_map = db.crate_def_map(from_module.krate);
self.visible_from_def_map(&def_map, from_module.local_id) self.is_visible_from_def_map(&def_map, from_module.local_id)
} }
pub(crate) fn visible_from_other_crate(self) -> bool { pub(crate) fn is_visible_from_other_crate(self) -> bool {
match self { match self {
Visibility::Module(_) => false, Visibility::Module(_) => false,
Visibility::Public => true, Visibility::Public => true,
} }
} }
pub(crate) fn visible_from_def_map( pub(crate) fn is_visible_from_def_map(
self, self,
def_map: &crate::nameres::CrateDefMap, def_map: &crate::nameres::CrateDefMap,
from_module: crate::LocalModuleId, from_module: crate::LocalModuleId,

View file

@ -38,7 +38,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) { fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) {
for receiver in receiver.autoderef(ctx.db) { for receiver in receiver.autoderef(ctx.db) {
for (field, ty) in receiver.fields(ctx.db) { for (field, ty) in receiver.fields(ctx.db) {
if ctx.module.map_or(false, |m| !field.visible_from(ctx.db, m)) { if ctx.module.map_or(false, |m| !field.is_visible_from(ctx.db, m)) {
// Skip private field. FIXME: If the definition location of the // Skip private field. FIXME: If the definition location of the
// field is editable, we should show the completion // field is editable, we should show the completion
continue; continue;