mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
feat: Deprioritize completions of private but editable definitions
This commit is contained in:
parent
d7a544e69a
commit
5c41f5d165
12 changed files with 120 additions and 58 deletions
|
@ -34,6 +34,11 @@ pub(crate) enum PatternRefutability {
|
|||
Refutable,
|
||||
Irrefutable,
|
||||
}
|
||||
pub enum Visible {
|
||||
Yes,
|
||||
Editable,
|
||||
No,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub(super) enum PathKind {
|
||||
|
@ -285,7 +290,7 @@ impl<'a> CompletionContext<'a> {
|
|||
}
|
||||
|
||||
/// Checks if an item is visible and not `doc(hidden)` at the completion site.
|
||||
pub(crate) fn is_visible<I>(&self, item: &I) -> bool
|
||||
pub(crate) fn is_visible<I>(&self, item: &I) -> Visible
|
||||
where
|
||||
I: hir::HasVisibility + hir::HasAttrs + hir::HasCrate + Copy,
|
||||
{
|
||||
|
@ -339,20 +344,24 @@ impl<'a> CompletionContext<'a> {
|
|||
vis: &hir::Visibility,
|
||||
attrs: &hir::Attrs,
|
||||
defining_crate: hir::Crate,
|
||||
) -> bool {
|
||||
) -> Visible {
|
||||
let module = match self.module {
|
||||
Some(it) => it,
|
||||
None => return false,
|
||||
None => return Visible::No,
|
||||
};
|
||||
if !vis.is_visible_from(self.db, module.into()) {
|
||||
// If the definition location is editable, also show private items
|
||||
let root_file = defining_crate.root_file(self.db);
|
||||
let source_root_id = self.db.file_source_root(root_file);
|
||||
let is_editable = !self.db.source_root(source_root_id).is_library;
|
||||
return is_editable;
|
||||
return if is_editable { Visible::Editable } else { Visible::No };
|
||||
}
|
||||
|
||||
!self.is_doc_hidden(attrs, defining_crate)
|
||||
if self.is_doc_hidden(attrs, defining_crate) {
|
||||
Visible::No
|
||||
} else {
|
||||
Visible::Yes
|
||||
}
|
||||
}
|
||||
|
||||
fn is_doc_hidden(&self, attrs: &hir::Attrs, defining_crate: hir::Crate) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue