fix: do not offer completions within macro strings

This commit is contained in:
Vishruth-Thimmaiah 2025-01-01 21:50:06 +05:30
parent 4a03036744
commit cb0221d774
No known key found for this signature in database
GPG key ID: B89775C5BE008866
3 changed files with 72 additions and 1 deletions

View file

@ -376,7 +376,7 @@ impl ChangeFixture {
}
}
fn default_test_proc_macros() -> [(String, ProcMacro); 7] {
fn default_test_proc_macros() -> [(String, ProcMacro); 8] {
[
(
r#"
@ -483,6 +483,21 @@ pub fn issue_18840(_attr: TokenStream, _item: TokenStream) -> TokenStream {
disabled: false,
},
),
(
r#"
#[proc_macro]
pub fn issue_17479(input: TokenStream) -> TokenStream {
input
}
"#
.into(),
ProcMacro {
name: Symbol::intern("issue_17479"),
kind: ProcMacroKind::Bang,
expander: sync::Arc::new(Issue17479ProcMacroExpander),
disabled: false,
},
),
]
}
@ -761,3 +776,28 @@ impl ProcMacroExpander for ShortenProcMacroExpander {
}
}
}
// Reads ident type within string quotes, for issue #17479.
#[derive(Debug)]
struct Issue17479ProcMacroExpander;
impl ProcMacroExpander for Issue17479ProcMacroExpander {
fn expand(
&self,
subtree: &TopSubtree,
_: Option<&TopSubtree>,
_: &Env,
_: Span,
_: Span,
_: Span,
_: Option<String>,
) -> Result<TopSubtree, ProcMacroExpansionError> {
let TokenTree::Leaf(Leaf::Literal(lit)) = &subtree.0[1] else {
return Err(ProcMacroExpansionError::Panic("incorrect Input".into()));
};
let symbol = &lit.symbol;
let span = lit.span;
Ok(quote! { span =>
#symbol()
})
}
}