Autocomplete in macro parameters?


is there a way to have autocompletion on macros parameters (derive,proc_macro_derive,etc..)?

take the example of the Serde crate :

#[derive(Serialize, Deserialize)]
struct S {
    field: i32

in VSCode/Codium , if I type : #[serde( then I press Ctrl+Space , i don't have suggestions such as ( tag , rename , default, etc.. ).

I know it's complicated, the IDE has to interpret the macros to be able to determine the parameters,
but isn't there a way of predefining the expected parameters in the DOC comments, with a standard that all IDEs can understand?

derive is a special case since it's a compiler built-in. Maybe it's possible for a future version of rust-analyzer to look up the set of derive macros exported by imported crates?

1 Like

Completion for derive already exists. For special macro syntax like serde annotations, nothing exists yet. It would be possible to give macros the ability to provide completions in auch places (actually there are some hacky ways for macros to do this already), but no one has done this yet.

1 Like

Wouldn't it be simpler to reach a consensus (RFC) and define all this at the level of comments dedicated to documentation?

/// ....
/// params : [ tag, name, default ]

even if it won't handle linked or conditional parameters, but it's a good start.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.