mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
fix: Don't show qualified path completions for private items
This commit is contained in:
parent
6b823b0234
commit
7ff6c36716
11 changed files with 122 additions and 64 deletions
|
@ -33,6 +33,7 @@ pub(crate) enum PatternRefutability {
|
|||
Irrefutable,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum Visible {
|
||||
Yes,
|
||||
Editable,
|
||||
|
@ -355,10 +356,11 @@ pub(crate) struct CompletionContext<'a> {
|
|||
|
||||
pub(super) locals: FxHashMap<Name, Local>,
|
||||
|
||||
/// The module depth of the current module of the cursor position.
|
||||
/// - crate-root
|
||||
/// - mod foo
|
||||
/// - mod bar
|
||||
/// Here depth will be 2: {[bar<->foo], [foo<->crate-root]}
|
||||
/// Here depth will be 2
|
||||
pub(super) depth_from_crate_root: usize,
|
||||
}
|
||||
|
||||
|
@ -383,6 +385,30 @@ impl<'a> CompletionContext<'a> {
|
|||
FamousDefs(&self.sema, self.krate)
|
||||
}
|
||||
|
||||
/// Checks if an item is visible and not `doc(hidden)` at the completion site.
|
||||
pub(crate) fn def_is_visible(&self, item: &ScopeDef) -> Visible {
|
||||
match item {
|
||||
ScopeDef::ModuleDef(def) => match def {
|
||||
hir::ModuleDef::Module(it) => self.is_visible(it),
|
||||
hir::ModuleDef::Function(it) => self.is_visible(it),
|
||||
hir::ModuleDef::Adt(it) => self.is_visible(it),
|
||||
hir::ModuleDef::Variant(it) => self.is_visible(it),
|
||||
hir::ModuleDef::Const(it) => self.is_visible(it),
|
||||
hir::ModuleDef::Static(it) => self.is_visible(it),
|
||||
hir::ModuleDef::Trait(it) => self.is_visible(it),
|
||||
hir::ModuleDef::TypeAlias(it) => self.is_visible(it),
|
||||
hir::ModuleDef::Macro(it) => self.is_visible(it),
|
||||
hir::ModuleDef::BuiltinType(_) => Visible::Yes,
|
||||
},
|
||||
ScopeDef::GenericParam(_)
|
||||
| ScopeDef::ImplSelfType(_)
|
||||
| ScopeDef::AdtSelfType(_)
|
||||
| ScopeDef::Local(_)
|
||||
| ScopeDef::Label(_)
|
||||
| ScopeDef::Unknown => Visible::Yes,
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if an item is visible and not `doc(hidden)` at the completion site.
|
||||
pub(crate) fn is_visible<I>(&self, item: &I) -> Visible
|
||||
where
|
||||
|
@ -393,14 +419,6 @@ impl<'a> CompletionContext<'a> {
|
|||
self.is_visible_impl(&vis, &attrs, item.krate(self.db))
|
||||
}
|
||||
|
||||
pub(crate) fn is_scope_def_hidden(&self, scope_def: ScopeDef) -> bool {
|
||||
if let (Some(attrs), Some(krate)) = (scope_def.attrs(self.db), scope_def.krate(self.db)) {
|
||||
return self.is_doc_hidden(&attrs, krate);
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
/// Check if an item is `#[doc(hidden)]`.
|
||||
pub(crate) fn is_item_hidden(&self, item: &hir::ItemInNs) -> bool {
|
||||
let attrs = item.attrs(self.db);
|
||||
|
@ -468,6 +486,14 @@ impl<'a> CompletionContext<'a> {
|
|||
self.scope.process_all_names(&mut |name, def| f(name, def));
|
||||
}
|
||||
|
||||
fn is_scope_def_hidden(&self, scope_def: ScopeDef) -> bool {
|
||||
if let (Some(attrs), Some(krate)) = (scope_def.attrs(self.db), scope_def.krate(self.db)) {
|
||||
return self.is_doc_hidden(&attrs, krate);
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn is_visible_impl(
|
||||
&self,
|
||||
vis: &hir::Visibility,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue