Rust analyzer generates function names with $0

Heya, when I use "generate getter" on the value field using Rust analyzer:

#[derive(Clone, Debug)]
pub struct MyStruct {
    value: u32,
}

The following code gets generated (notice the $0 before the function name):

impl MyStruct {
    pub fn $0value(&self) -> u32 {
        self.value
    }
}

I need help figuring out:

  • if it is a bug (should this line check if ctx.config.snippet_cap is a certain value?)
  • where the would-be bug is (rust-analyzer, LSP, LSP-rust-analyzer, or some config setting)

I'm not sure how to avoid the $0 being inserted as part of the code (it looks like where the caret is intended to be placed). The $0 looks intentional, similar to rust-analyzer#7793. #11006 might also be related.

I've been playing with LSP-rust-analyzer settings but can't seem to resolve it.

My tools and versions are:

Rust Analyzer: rust-analyzer 0.0.0 (89b994049 2023-02-14)
Sublime text: Build 4147
LSP-rust-analyzer: v1.3.1

I think so. While it would be nice for SublimeText to support snippets, rust-analyzer shouldn't use them if the client indicates it doesn't support them.

2 Likes

Cool thank you, I've opened rust-analyzer#14161 to confirm and send a fix.

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.