Fix a case where completion was unable to expand a macro

Which caused the macros of the popular `tracing` crate to not offer completions.

The reason is rather complicated: it boils down to macro ignoring their input and completion always choosing the first expansion.
This commit is contained in:
Chayim Refael Friedman 2024-12-20 02:27:37 +02:00
parent e0c11f631e
commit 02d47f3a81
16 changed files with 604 additions and 368 deletions

View file

@ -72,8 +72,19 @@ pub(super) fn item_or_macro(p: &mut Parser<'_>, stop_on_r_curly: bool, is_in_ext
// macro_rules! ()
// macro_rules! []
if paths::is_use_path_start(p) {
macro_call(p, m);
return;
paths::use_path(p);
// Do not create a MACRO_CALL node here if this isn't a macro call, this causes problems with completion.
// test_err path_item_without_excl
// foo
if p.at(T![!]) {
macro_call(p, m);
return;
} else {
m.complete(p, ERROR);
p.error("expected an item");
return;
}
}
m.abandon(p);
@ -410,8 +421,7 @@ fn fn_(p: &mut Parser<'_>, m: Marker) {
}
fn macro_call(p: &mut Parser<'_>, m: Marker) {
assert!(paths::is_use_path_start(p));
paths::use_path(p);
assert!(p.at(T![!]));
match macro_call_after_excl(p) {
BlockLike::Block => (),
BlockLike::NotBlock => {

View file

@ -30,22 +30,20 @@ fn source_file() {
TopEntryPoint::SourceFile,
"@error@",
expect![[r#"
SOURCE_FILE
ERROR
AT "@"
MACRO_CALL
PATH
PATH_SEGMENT
NAME_REF
IDENT "error"
ERROR
AT "@"
error 0: expected an item
error 6: expected BANG
error 6: expected `{`, `[`, `(`
error 6: expected SEMICOLON
error 6: expected an item
"#]],
SOURCE_FILE
ERROR
AT "@"
ERROR
PATH
PATH_SEGMENT
NAME_REF
IDENT "error"
ERROR
AT "@"
error 0: expected an item
error 6: expected an item
error 6: expected an item
"#]],
);
}