Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/context.rs')
| -rw-r--r-- | crates/ide-completion/src/context.rs | 88 |
1 files changed, 47 insertions, 41 deletions
diff --git a/crates/ide-completion/src/context.rs b/crates/ide-completion/src/context.rs index 31a9a74aa8..ffffc2635e 100644 --- a/crates/ide-completion/src/context.rs +++ b/crates/ide-completion/src/context.rs @@ -53,6 +53,7 @@ pub(crate) struct QualifierCtx { pub(crate) unsafe_tok: Option<SyntaxToken>, pub(crate) safe_tok: Option<SyntaxToken>, pub(crate) vis_node: Option<ast::Visibility>, + pub(crate) abi_node: Option<ast::Abi>, } impl QualifierCtx { @@ -61,6 +62,7 @@ impl QualifierCtx { && self.unsafe_tok.is_none() && self.safe_tok.is_none() && self.vis_node.is_none() + && self.abi_node.is_none() } } @@ -557,7 +559,7 @@ impl CompletionContext<'_> { I: hir::HasAttrs + Copy, { let attrs = item.attrs(self.db); - attrs.doc_aliases().map(|it| it.as_str().into()).collect() + attrs.doc_aliases(self.db).iter().map(|it| it.as_str().into()).collect() } /// Check if an item is `#[doc(hidden)]`. @@ -571,7 +573,7 @@ impl CompletionContext<'_> { } /// Checks whether this item should be listed in regards to stability. Returns `true` if we should. - pub(crate) fn check_stability(&self, attrs: Option<&hir::Attrs>) -> bool { + pub(crate) fn check_stability(&self, attrs: Option<&hir::AttrsWithOwner>) -> bool { let Some(attrs) = attrs else { return true; }; @@ -589,15 +591,15 @@ impl CompletionContext<'_> { /// Whether the given trait is an operator trait or not. pub(crate) fn is_ops_trait(&self, trait_: hir::Trait) -> bool { - match trait_.attrs(self.db).lang() { - Some(lang) => OP_TRAIT_LANG_NAMES.contains(&lang.as_str()), + match trait_.attrs(self.db).lang(self.db) { + Some(lang) => OP_TRAIT_LANG.contains(&lang), None => false, } } /// Whether the given trait has `#[doc(notable_trait)]` pub(crate) fn is_doc_notable_trait(&self, trait_: hir::Trait) -> bool { - trait_.attrs(self.db).has_doc_notable_trait() + trait_.attrs(self.db).is_doc_notable_trait() } /// Returns the traits in scope, with the [`Drop`] trait removed. @@ -654,7 +656,7 @@ impl CompletionContext<'_> { fn is_visible_impl( &self, vis: &hir::Visibility, - attrs: &hir::Attrs, + attrs: &hir::AttrsWithOwner, defining_crate: hir::Crate, ) -> Visible { if !self.check_stability(Some(attrs)) { @@ -676,14 +678,18 @@ impl CompletionContext<'_> { if self.is_doc_hidden(attrs, defining_crate) { Visible::No } else { Visible::Yes } } - pub(crate) fn is_doc_hidden(&self, attrs: &hir::Attrs, defining_crate: hir::Crate) -> bool { + pub(crate) fn is_doc_hidden( + &self, + attrs: &hir::AttrsWithOwner, + defining_crate: hir::Crate, + ) -> bool { // `doc(hidden)` items are only completed within the defining crate. - self.krate != defining_crate && attrs.has_doc_hidden() + self.krate != defining_crate && attrs.is_doc_hidden() } pub(crate) fn doc_aliases_in_scope(&self, scope_def: ScopeDef) -> Vec<SmolStr> { if let Some(attrs) = scope_def.attrs(self.db) { - attrs.doc_aliases().map(|it| it.as_str().into()).collect() + attrs.doc_aliases(self.db).iter().map(|it| it.as_str().into()).collect() } else { vec![] } @@ -701,7 +707,7 @@ impl<'db> CompletionContext<'db> { let _p = tracing::info_span!("CompletionContext::new").entered(); let sema = Semantics::new(db); - let editioned_file_id = sema.attach_first_edition(file_id)?; + let editioned_file_id = sema.attach_first_edition(file_id); let original_file = sema.parse(editioned_file_id); // Insert a fake ident to get a valid parse tree. We will use this file @@ -887,35 +893,35 @@ impl<'db> CompletionContext<'db> { } } -const OP_TRAIT_LANG_NAMES: &[&str] = &[ - "add_assign", - "add", - "bitand_assign", - "bitand", - "bitor_assign", - "bitor", - "bitxor_assign", - "bitxor", - "deref_mut", - "deref", - "div_assign", - "div", - "eq", - "fn_mut", - "fn_once", - "fn", - "index_mut", - "index", - "mul_assign", - "mul", - "neg", - "not", - "partial_ord", - "rem_assign", - "rem", - "shl_assign", - "shl", - "shr_assign", - "shr", - "sub", +const OP_TRAIT_LANG: &[hir::LangItem] = &[ + hir::LangItem::AddAssign, + hir::LangItem::Add, + hir::LangItem::BitAndAssign, + hir::LangItem::BitAnd, + hir::LangItem::BitOrAssign, + hir::LangItem::BitOr, + hir::LangItem::BitXorAssign, + hir::LangItem::BitXor, + hir::LangItem::DerefMut, + hir::LangItem::Deref, + hir::LangItem::DivAssign, + hir::LangItem::Div, + hir::LangItem::PartialEq, + hir::LangItem::FnMut, + hir::LangItem::FnOnce, + hir::LangItem::Fn, + hir::LangItem::IndexMut, + hir::LangItem::Index, + hir::LangItem::MulAssign, + hir::LangItem::Mul, + hir::LangItem::Neg, + hir::LangItem::Not, + hir::LangItem::PartialOrd, + hir::LangItem::RemAssign, + hir::LangItem::Rem, + hir::LangItem::ShlAssign, + hir::LangItem::Shl, + hir::LangItem::ShrAssign, + hir::LangItem::Shr, + hir::LangItem::Sub, ]; |