rustemacsrust-analyzer

How to inline a variable in Emacs?


I'm writing Rust using rust-analyzer and lsp-mode

Suppose I have code:

let x = 10;
let y = 20 + x;

I want to put my cursor over x and hit some shortcut (or whatever) and the code becomes:

let y = 20 + 10;

From searching the internet it seems I'm the first person in the world who ever wanted to inline a variable in Emacs⁈


Solution

  • Since rust-analyzer supports that code action, you should be able to use it using lsp-mode's support of rust-analyzer. I did a quick testing using my Emacs instance and can confirm that the code action works fine via lsp-mode.