mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 12:24:29 +00:00
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:
parent
e0c11f631e
commit
02d47f3a81
16 changed files with 604 additions and 368 deletions
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -775,6 +775,10 @@ mod err {
|
|||
run_and_expect_errors("test_data/parser/inline/err/missing_fn_param_type.rs");
|
||||
}
|
||||
#[test]
|
||||
fn path_item_without_excl() {
|
||||
run_and_expect_errors("test_data/parser/inline/err/path_item_without_excl.rs");
|
||||
}
|
||||
#[test]
|
||||
fn pointer_type_no_mutability() {
|
||||
run_and_expect_errors("test_data/parser/inline/err/pointer_type_no_mutability.rs");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,20 +10,20 @@ SOURCE_FILE
|
|||
USE_KW "use"
|
||||
ERROR
|
||||
SLASH "/"
|
||||
MACRO_CALL
|
||||
ERROR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "bin"
|
||||
ERROR
|
||||
SLASH "/"
|
||||
MACRO_CALL
|
||||
ERROR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "env"
|
||||
WHITESPACE " "
|
||||
MACRO_CALL
|
||||
ERROR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
|
|
@ -33,13 +33,7 @@ error 23: expected `[`
|
|||
error 23: expected an item
|
||||
error 27: expected one of `*`, `::`, `{`, `self`, `super` or an identifier
|
||||
error 28: expected SEMICOLON
|
||||
error 31: expected BANG
|
||||
error 31: expected `{`, `[`, `(`
|
||||
error 31: expected SEMICOLON
|
||||
error 31: expected an item
|
||||
error 35: expected BANG
|
||||
error 35: expected `{`, `[`, `(`
|
||||
error 35: expected SEMICOLON
|
||||
error 41: expected BANG
|
||||
error 41: expected `{`, `[`, `(`
|
||||
error 41: expected SEMICOLON
|
||||
error 31: expected an item
|
||||
error 35: expected an item
|
||||
error 41: expected an item
|
||||
|
|
|
|||
|
|
@ -14,14 +14,15 @@ SOURCE_FILE
|
|||
WHITESPACE "\n"
|
||||
R_CURLY "}"
|
||||
WHITESPACE "\n\n"
|
||||
MACRO_CALL
|
||||
ERROR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "bar"
|
||||
TOKEN_TREE
|
||||
L_PAREN "("
|
||||
R_PAREN ")"
|
||||
ERROR
|
||||
L_PAREN "("
|
||||
ERROR
|
||||
R_PAREN ")"
|
||||
WHITESPACE " "
|
||||
ERROR
|
||||
L_CURLY "{"
|
||||
|
|
@ -75,6 +76,7 @@ SOURCE_FILE
|
|||
WHITESPACE "\n"
|
||||
R_CURLY "}"
|
||||
WHITESPACE "\n"
|
||||
error 17: expected BANG
|
||||
error 19: expected SEMICOLON
|
||||
error 17: expected an item
|
||||
error 17: expected an item
|
||||
error 18: expected an item
|
||||
error 20: expected an item
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ SOURCE_FILE
|
|||
ERROR
|
||||
AT "@"
|
||||
WHITESPACE " "
|
||||
MACRO_CALL
|
||||
ERROR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
|
|
@ -72,9 +72,7 @@ error 67: expected R_ANGLE
|
|||
error 67: expected R_PAREN
|
||||
error 67: expected SEMICOLON
|
||||
error 67: expected an item
|
||||
error 72: expected BANG
|
||||
error 72: expected `{`, `[`, `(`
|
||||
error 72: expected SEMICOLON
|
||||
error 72: expected an item
|
||||
error 72: expected an item
|
||||
error 73: expected an item
|
||||
error 79: expected an item
|
||||
|
|
|
|||
|
|
@ -26,14 +26,15 @@ SOURCE_FILE
|
|||
ERROR
|
||||
FN_KW "fn"
|
||||
WHITESPACE " "
|
||||
MACRO_CALL
|
||||
ERROR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "bar"
|
||||
TOKEN_TREE
|
||||
L_PAREN "("
|
||||
R_PAREN ")"
|
||||
ERROR
|
||||
L_PAREN "("
|
||||
ERROR
|
||||
R_PAREN ")"
|
||||
WHITESPACE " "
|
||||
ERROR
|
||||
L_CURLY "{"
|
||||
|
|
@ -43,6 +44,7 @@ error 6: expected fn, trait or impl
|
|||
error 38: expected a name
|
||||
error 40: missing type for `const` or `static`
|
||||
error 40: expected SEMICOLON
|
||||
error 44: expected BANG
|
||||
error 46: expected SEMICOLON
|
||||
error 44: expected an item
|
||||
error 44: expected an item
|
||||
error 45: expected an item
|
||||
error 47: expected an item
|
||||
|
|
|
|||
|
|
@ -12,15 +12,16 @@ SOURCE_FILE
|
|||
ERROR
|
||||
USE_KW "use"
|
||||
WHITESPACE " "
|
||||
MACRO_CALL
|
||||
ERROR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "std"
|
||||
ERROR
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n"
|
||||
error 8: expected R_ANGLE
|
||||
error 8: expected type
|
||||
error 11: expected `{`
|
||||
error 15: expected BANG
|
||||
error 15: expected `{`, `[`, `(`
|
||||
error 15: expected an item
|
||||
error 15: expected an item
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
SOURCE_FILE
|
||||
MACRO_CALL
|
||||
ERROR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
|
|
@ -22,7 +22,7 @@ SOURCE_FILE
|
|||
ERROR
|
||||
ASYNC_KW "async"
|
||||
WHITESPACE " "
|
||||
MACRO_CALL
|
||||
ERROR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
|
|
@ -42,10 +42,6 @@ SOURCE_FILE
|
|||
L_CURLY "{"
|
||||
R_CURLY "}"
|
||||
WHITESPACE "\n"
|
||||
error 3: expected BANG
|
||||
error 3: expected `{`, `[`, `(`
|
||||
error 3: expected SEMICOLON
|
||||
error 3: expected an item
|
||||
error 24: expected fn, trait or impl
|
||||
error 28: expected BANG
|
||||
error 28: expected `{`, `[`, `(`
|
||||
error 28: expected SEMICOLON
|
||||
error 28: expected an item
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
SOURCE_FILE
|
||||
ERROR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "foo"
|
||||
WHITESPACE "\n"
|
||||
error 3: expected an item
|
||||
|
|
@ -0,0 +1 @@
|
|||
foo
|
||||
Loading…
Add table
Add a link
Reference in a new issue