I'm trying to configure rust analyzer to expand proc macros. According to it's documentation I have to configure my editor (i.e. emacs) to send this JSON as a LSP message:

  "cargo": {
    "loadOutDirsFromCheck": true,
  "procMacro": {
    "enable": true,

I couldn't find anything in Emacs's documentation on how to do it.

  • Does calling the lsp-rust-analyzer-expand-macro function not work? It’s documented here: emacs-lsp.github.io/lsp-mode/page/lsp-rust-analyzer/…
    – db48x
    Commented Nov 20, 2021 at 20:55
  • @db48x No, this function refers to declarative macros not procedural ones. If I try it nonetheless, I get this error message: "No macro found at point, or it could not be expanded."
    – zvavybir
    Commented Nov 20, 2021 at 22:15
  • I see. Well, let me see if I have gathered enough information to answer this.
    – db48x
    Commented Nov 20, 2021 at 22:24

1 Answer 1


Ok, so you are asking about the configuration options listed in the rust-analyzer documentation.

I wasn’t able to find out much about the subject in the lsp-mode documentation, so instead I took a quick peek in the lsp-rust source code. I soon found that there is a function called lsp-rust-analyzer--make-init-options that returns the data structure that will be encoded as JSON and sent to the server. You can view the source inside Emacs (type C-h f and enter the function name; it opens a help buffer for the function which includes a link to its source code), but it is also viewable on GitHub.

If you look through this giant thing, you’ll eventually see :cargo and :procMacro sections. Specifically, you’ll see this:

:procMacro (:enable ,(lsp-json-bool lsp-rust-analyzer-proc-macro-enable))

which uses the variable lsp-rust-analyzer-proc-macro-enable to enable or disable support for procedural macros. Similarly:

:cargo (…
        :loadOutDirsFromCheck ,(lsp-json-bool lsp-rust-analyzer-cargo-run-build-scripts)

does the same thing with the lsp-rust-analyzer-cargo-run-build-scripts variable.

Both of these variables refer to customizable settings. To edit them, you can just run M-x customize-group, and then type lsp-rust-analyzer at the prompt. This lists all of the settings for the lsp-rust-analyzer module, and gives you a nice interface for editing them.

It also turns out that these variables are both documented in the lsp-mode documentation; I had simply failed to notice them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.