Default delimiters for macro invocation, vs-code rust-analyzer

Rust-analyzer autocompletes brackets for calling the vec macro as [ ], can I pass rust-analyzer some metadata so that it autocompletes my macro as custom![ ]?

rust-analyzer scans macros documentation for macro_name!(...), macro_name!{...} and macro_name![...] and picks whatever bracing style it finds there

3 Likes

@Veykril is correct. You just need to write a doc comment to tell Rust Analyzer the type of delimiter you wish to use.

/// My custom macro is used with square brackets, not round parentheses:
///
/// let c = custom![1, 2, 3];
#[macro_export]
macro_rules! custom {
    // ...
}

If examples in your doc comment use more than one kind of delimiter, Rust Analyzer will pick the first one it comes across.

As an aside, vec! is somewhat special because rustfmt re-formats vec!{} and vec!() to vec![]. This isn't related to Rust Analyzer's autosuggest predictions however.

4 Likes

@Veykril @hax10
thank you, It's really useful.

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.