mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-15 13:52:59 +00:00
Merge pull request #19942 from ChayimFriedman2/faux
fix: Fix completion with some attribute macros
This commit is contained in:
commit
2095af26ad
@ -13,7 +13,7 @@ use crate::{
|
|||||||
AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo,
|
AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo,
|
||||||
EagerExpander, EditionedFileId, ExpandError, ExpandResult, ExpandTo, HirFileId, MacroCallId,
|
EagerExpander, EditionedFileId, ExpandError, ExpandResult, ExpandTo, HirFileId, MacroCallId,
|
||||||
MacroCallKind, MacroCallLoc, MacroDefId, MacroDefKind,
|
MacroCallKind, MacroCallLoc, MacroDefId, MacroDefKind,
|
||||||
attrs::{AttrId, collect_attrs},
|
attrs::{AttrId, AttrInput, RawAttrs, collect_attrs},
|
||||||
builtin::pseudo_derive_attr_expansion,
|
builtin::pseudo_derive_attr_expansion,
|
||||||
cfg_process,
|
cfg_process,
|
||||||
declarative::DeclarativeMacroExpander,
|
declarative::DeclarativeMacroExpander,
|
||||||
@ -241,19 +241,10 @@ pub fn expand_speculative(
|
|||||||
|
|
||||||
let attr_arg = match loc.kind {
|
let attr_arg = match loc.kind {
|
||||||
MacroCallKind::Attr { invoc_attr_index, .. } => {
|
MacroCallKind::Attr { invoc_attr_index, .. } => {
|
||||||
let attr = if loc.def.is_attribute_derive() {
|
if loc.def.is_attribute_derive() {
|
||||||
// for pseudo-derive expansion we actually pass the attribute itself only
|
// for pseudo-derive expansion we actually pass the attribute itself only
|
||||||
ast::Attr::cast(speculative_args.clone())
|
ast::Attr::cast(speculative_args.clone()).and_then(|attr| attr.token_tree()).map(
|
||||||
} else {
|
|token_tree| {
|
||||||
// Attributes may have an input token tree, build the subtree and map for this as well
|
|
||||||
// then try finding a token id for our token if it is inside this input subtree.
|
|
||||||
let item = ast::Item::cast(speculative_args.clone())?;
|
|
||||||
collect_attrs(&item)
|
|
||||||
.nth(invoc_attr_index.ast_index())
|
|
||||||
.and_then(|x| Either::left(x.1))
|
|
||||||
}?;
|
|
||||||
match attr.token_tree() {
|
|
||||||
Some(token_tree) => {
|
|
||||||
let mut tree = syntax_node_to_token_tree(
|
let mut tree = syntax_node_to_token_tree(
|
||||||
token_tree.syntax(),
|
token_tree.syntax(),
|
||||||
span_map,
|
span_map,
|
||||||
@ -261,10 +252,25 @@ pub fn expand_speculative(
|
|||||||
DocCommentDesugarMode::ProcMacro,
|
DocCommentDesugarMode::ProcMacro,
|
||||||
);
|
);
|
||||||
*tree.top_subtree_delimiter_mut() = tt::Delimiter::invisible_spanned(span);
|
*tree.top_subtree_delimiter_mut() = tt::Delimiter::invisible_spanned(span);
|
||||||
|
tree
|
||||||
Some(tree)
|
},
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// Attributes may have an input token tree, build the subtree and map for this as well
|
||||||
|
// then try finding a token id for our token if it is inside this input subtree.
|
||||||
|
let item = ast::Item::cast(speculative_args.clone())?;
|
||||||
|
let attrs = RawAttrs::new_expanded(db, &item, span_map, loc.krate.cfg_options(db));
|
||||||
|
attrs.iter().find(|attr| attr.id == invoc_attr_index).and_then(|attr| {
|
||||||
|
match attr.input.as_deref()? {
|
||||||
|
AttrInput::TokenTree(tt) => {
|
||||||
|
let mut attr_arg = tt.clone();
|
||||||
|
attr_arg.top_subtree_delimiter_mut().kind =
|
||||||
|
tt::DelimiterKind::Invisible;
|
||||||
|
Some(attr_arg)
|
||||||
}
|
}
|
||||||
_ => None,
|
AttrInput::Literal(_) => None,
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|||||||
@ -25,7 +25,6 @@ use hir_expand::{
|
|||||||
builtin::{BuiltinFnLikeExpander, EagerExpander},
|
builtin::{BuiltinFnLikeExpander, EagerExpander},
|
||||||
db::ExpandDatabase,
|
db::ExpandDatabase,
|
||||||
files::{FileRangeWrapper, HirFileRange, InRealFile},
|
files::{FileRangeWrapper, HirFileRange, InRealFile},
|
||||||
inert_attr_macro::find_builtin_attr_idx,
|
|
||||||
mod_path::{ModPath, PathKind},
|
mod_path::{ModPath, PathKind},
|
||||||
name::AsName,
|
name::AsName,
|
||||||
};
|
};
|
||||||
@ -969,13 +968,6 @@ impl<'db> SemanticsImpl<'db> {
|
|||||||
let Some(item) = ast::Item::cast(ancestor) else {
|
let Some(item) = ast::Item::cast(ancestor) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
// Optimization to skip the semantic check.
|
|
||||||
if item.attrs().all(|attr| {
|
|
||||||
attr.simple_name()
|
|
||||||
.is_some_and(|attr| find_builtin_attr_idx(&Symbol::intern(&attr)).is_some())
|
|
||||||
}) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
self.with_ctx(|ctx| {
|
self.with_ctx(|ctx| {
|
||||||
if ctx.item_to_macro_call(token.with_value(&item)).is_some() {
|
if ctx.item_to_macro_call(token.with_value(&item)).is_some() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user