rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.82k stars 12.77k forks source link

Add rustc compiler development support for the Zed Editor #126931

Open KittyBorgX opened 5 months ago

KittyBorgX commented 5 months ago

Currently running x setup prompts an editor setup for VSCode for rustc compiler development in the following way :

x.py can automatically install the recommended `.vscode/settings.json` file for rustc development
Would you like to create/update settings.json? (Press 'p' to preview values): [y/N]

Seeing the rising popularity of the Zed Editor, why not add support for it too? I spent some time configuring and tweaking .zed/settings.json and it's working for me on Zed 0.140.5. I've opened this issue with regard to the workflow of the x setup part, whether:

x.py can automatically install the recommended .zed/settings.json file for rustc development Would you like to create/update settings.json? (Press 'p' to preview values): [y/N]


- Displaying it in a "menu" - which is seen in the "Welcome to the Rust project! What do you want to do with x.py?" section as follows (just sample text, not the final one): 

x.py can automatically install the recommended settings for rustc development. Would you like to create/update settings.json for a) vscode (.vscode/settings.json) b) zed (.zed/settings.json) c) none


- Any other way which it can be displayed to make it user friendly

btw, here's the `.zed/settings.json` that works (taken almost 1:1 from https://github.com/rust-lang/rust/blob/master/src/etc/rust_analyzer_settings.json): 
```json
{
  "lsp": {
    "rust-analyzer": {
      "initialization_options": {
        "check": {
          "invocationLocation": "root",
          "invocationStrategy": "once",
          "overrideCommand": ["python3", "x.py", "check", "--json-output"]
        },
        "linkedProjects": [
          "Cargo.toml",
          "src/tools/x/Cargo.toml",
          "src/bootstrap/Cargo.toml",
          "src/tools/rust-analyzer/Cargo.toml",
          "compiler/rustc_codegen_cranelift/Cargo.toml",
          "compiler/rustc_codegen_gcc/Cargo.toml"
        ],
        "rustfmt": {
          "overrideCommand": [
            "./build/host/rustfmt/bin/rustfmt",
            "--edition=2021"
          ]
        },
        "procMacro": {
          "enable": true,
          "server": "./build/host/stage0/libexec/rust-analyzer-proc-macro-srv"
        },
        "cargo": {
          "buildScripts": {
            "enable": true,
            "invocationLocation": "root",
            "invocationStrategy": "once",
            "overrideCommand": ["python3", "x.py", "check", "--json-output"]
          },
          "sysrootSrc": "./library",
          "extraEnv": {
            "RUSTC_BOOTSTRAP": "1"
          }
        }
      }
    }
  }
}

note : i've removed the ${workspaceFolder} and replaced it with ./ since afaik there's no way of using vars in settings.json in zed. variables like ZED_WORKTREE_ROOT can be used in tasks.json hovewer.

KittyBorgX commented 5 months ago

@rustbot claim

Noratrieb commented 3 months ago

I'd be opposed to the first one, asking more questions is not good. the menu sounds good to me, with a default to none if no letter is entered. but i don't work on bootstrap so it will be up to the reviewer to decide if they like it. when in doubt ask on zulip but I'd just go ahead and implement it

lucarlig commented 1 month ago

the menu is already implemented, just the config for zed needs to be added. @KittyBorgX are you still working on this?

KittyBorgX commented 1 month ago

the menu is already implemented, just the config for zed needs to be added. @KittyBorgX are you still working on this?

oh I see - I'm not actively working on this issue atm and I think it'll be hard to find the time for it so anyone who wants to take this on - feel free to do so 😅

the working config is part of the original issue description

lucarlig commented 1 month ago

@rustbot label E-easy

shrirambalaji commented 1 month ago

I can pick this up, I've been using Zed and also worked on a change in this repo, so I'm aware of the details.

@rustbot claim