Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No completion inside of macro args #15016

Closed
hellow554 opened this issue Jun 9, 2023 · 3 comments · Fixed by #16061
Closed

No completion inside of macro args #15016

hellow554 opened this issue Jun 9, 2023 · 3 comments · Fixed by #16061
Labels
A-completion autocompletion A-macro macro expansion C-enhancement Category: enhancement

Comments

@hellow554
Copy link

rust-analyzer version: rust-analyzer version: 0.4.1545-standalone

rustc version: rustc 1.72.0-nightly (101fa903b 2023-06-05)

I have the following code:

fn main() {
    let x = String::new();
    // write the macros here
}

and where the comment is I write something along these lines with each and every macro:

assert!(x.ctrl+space
and observe whether RA gives a suggestion on the x parameter

Macro Name First Parameter Second Paramter additional
assert
assert_eq stops working after second parameter
assert_ne stops working after second parameter
compile_error
dbg
debug_assert
debug_assert_eq stops working after second parameter
debug_assert_ne stops working after second paremeter
env
eprint
eprintln
format
format_args
matches stops working after second parameter
panic
print
println
todo
unimplemened
unreachable
vec

It's funny that some macros work, while others dont... also somewhat inconsistent i.e. in dbg! where the first parameter has suggestion, but the second (and third...) hasn't.

Is this something that can be easily done? Some macros have suggestion, so there must be a codepath for that somewhere.

@hellow554 hellow554 added the C-bug Category: bug label Jun 9, 2023
@Veykril
Copy link
Member

Veykril commented Jun 9, 2023

This is kind of expected, our recovery for macro inputs is not that great yet. We don't pick an ideal matching arm for incorrect inputs yet, and we also do not consider the fragment type of captures to aid in recovery either.

To answer the question whether this can be easily fixed right now, I'd say not necessarily. Picking a better matching arm for incorrect/partial inputs for macros can be worked on though it's a tough problem. Considering fragment types we are missing the infra for currently.

@flodiebold
Copy link
Member

flodiebold commented Jun 10, 2023

For format strings, the format string parameter itself (e.g. first argument of print!, second argument of assert!, third argument of assert_eq!) is expected to not give completions because it needs to be a string literal. All further arguments work if you have the corresponding {} in the format string. It used to work without that, but I guess because we made the implementation of format_args more realistic now it doesn't anymore. It might be nice to fix that.
That covers most of the cases listed.

compile_error!, env!: The argument needs to be a string literal, so no completions are expected. (Actually we do give completions for env! once you start a string literal.)
vec!: Yeah, this one I couldn't get to work with my older RA either. It's indeed just a matter of failing recovery though, as vec![s.a<|>] does give completions.

@Veykril Veykril added A-macro macro expansion C-enhancement Category: enhancement and removed C-bug Category: bug labels Jun 10, 2023
@Veykril Veykril added the A-completion autocompletion label Dec 8, 2023
@Veykril
Copy link
Member

Veykril commented Dec 8, 2023

#16060 fixes the format_args family of macros, vec! is still broken though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion A-macro macro expansion C-enhancement Category: enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants