rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.08k stars 1.57k forks source link

Rust-analyzer does not recover from proc-macro errors. Message: "proc-macro server did not respond with data" #17944

Open buildwithzephyr opened 3 weeks ago

buildwithzephyr commented 3 weeks ago

If there are any errors when executing a proc-macro, rust-analyzer will fail on all proc macros until I restart VSCode, even when the macro should work. It gives the error "proc-macro server did not respond with data." It seems that maybe any panic while expanding a proc-macro causes the server to crash and not restart?

rust-analyzer version: Version 0.3.2078, Server Version 0.3.2078-standalone (fa0032624 2024-08-17)

rustc version: rustc 1.78.0 (9b00956e5 2024-04-29)

editor or extension: VSCode, extension version v0.3.2078. I primarily use MacOS, but have seen the same problem on Ubuntu.

relevant settings: I have rust-analyzer set to run on every save, here is my .vscode/settings.json:

{
  "rust-analyzer.showUnlinkedFileNotification": false,
  "[rust]": {
    "editor.defaultFormatter": "rust-lang.rust-analyzer",
    "editor.formatOnSave": true
  }
}

steps to reproduce:

Here is a minimal example using the proc macro subenum:

use subenum::subenum;

#[subenum(A)]
pub enum SomeEnum {
    #[subenum(A, B)]
    A,
    B,
}

The code will fail because the subenum B is specified in the variant attribute, but not in the enum attribute. Rust-analyzer displays the correct error message from the proc macro.

Screenshot 2024-08-22 at 11 26 39 AM

Fix the code by removing B from the variant attribute:

use subenum::subenum;

#[subenum(A)]
pub enum SomeEnum {
    #[subenum(A)]
    A,
    B,
}

This code should now compile. You can confirm this from the terminal with a cargo check.

However, rust-analyzer now fails on the proc-macro again, this time with the message "proc-macro server did not respond with data."

Screenshot 2024-08-22 at 11 32 16 AM

The only way to get rid of this error is to restart VSCode, after which rust-analyzer will handle the macro just fine.

Veykril commented 3 weeks ago

Hmm I can't reproduce this on windows