rust-lang / rust

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

rust-analyzer doesn't work on bootstrap anymore #101070

Closed tmandry closed 1 year ago

tmandry commented 2 years ago

97513 took bootstrap out of the cargo workspace, meaning that rust-analyzer can't see it anymore. I haven't yet found a config that makes rust-analyzer see it, short of opening bootstrap in a separate window.

This is annoying since I rust-analyzer particularly useful when working on bootstrap, but at least opening another window works for now.

cc @jyn514

RalfJung commented 2 years ago

Also see https://github.com/rust-lang/rust-analyzer/issues/10793 -- this is somewhat blocked on RA getting better support for projects that use custom build scripts such as ./x.py.

jyn514 commented 2 years ago

yeah, you can set linked-workspaces to have it use both, but then you get a bunch of spurious errors when you open the project

jyn514 commented 2 years ago

Blocked on https://github.com/rust-lang/rust-analyzer/pull/13128.

Veykril commented 1 year ago

Build scripts now work properly when rust-analyzer.linkedProjects is set if you follow the updated dev-guide instructions https://github.com/rust-lang/rustc-dev-guide/pull/1487 ~~... is what I would like to say but there is one small problem: x.py check --json-output does not emit build data for dependencies of bootstrap for example, so if you set linkedProjects to the bootstrap toml, r-a will currently fail to find the proc-macro dylibs for serde, because bootstrap uses a different serde version than the top level workspace has, and only the top level used one is reported (if I upgrade the serde version of bootstrap to the top-level one r-a finds the proc-macro dylibs for serde).~~ Looks like I either fixed it, or its a spurious problem

jyn514 commented 1 year ago

@Veykril I can't get this working. I have in .vscode/settings.json:

    "rust-analyzer.checkOnSave.enable": true,
    "rust-analyzer.checkOnSave.overrideCommand": [
        "python3",
        "x.py",
        "check",
        "--json-output"
    ],
    "rust-analyzer.rustfmt.overrideCommand": [
        "./build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt",
        "--edition=2021"
    ],
    "rust-analyzer.cargo.buildScripts.enable": true,
    "rust-analyzer.cargo.buildScripts.invocationLocation": "root",
    "rust-analyzer.cargo.buildScripts.invocationStrategy": "once",
    "rust-analyzer.cargo.buildScripts.overrideCommand": [
        "python3",
        "x.py",
        "check",
        "--json-output"
    ],
    "rust-analyzer.rustc.source": "./Cargo.toml",
    "rust-analyzer.cargo.sysroot": "./build/x86_64-unknown-linux-gnu/stage0-sysroot",
    "rust-analyzer.procMacro.enable": true,
    "rust-analyzer.linkedProjects": ["Cargo.toml", "src/bootstrap/Cargo.toml"],

which fails to find x.py:

[ERROR flycheck] Flycheck failed to run the following command: "python3" "x.py" "check" "--json-output"
[ERROR rust_analyzer::lsp_utils] cargo check failed

Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(512))):
python3: can't open file 'x.py': [Errno 2] No such file or directory

If I disable checkOnSave it does seem to work ok, though. Maybe the options you added need to be global instead of specific to build scripts?

Veykril commented 1 year ago

You'll need to set


    "rust-analyzer.cargo.checkOnSave.invocationLocation": "root",
    "rust-analyzer.cargo.checkOnSave.invocationStrategy": "once",

The reason I didn't add those to the dev guide is that you won't get diagnostics for linked projects anyways until x.py changes the paths in its output to be relative to the project root or https://github.com/rust-lang/cargo/issues/11007 is fixed (assuming x.py is using that flag). Otherwise r-a will not be able to deduce the correct files for the diagnostics as they are relative to the Cargo.toml of the linked projects without knowing which diagnostics come from what linked project.

jyn514 commented 1 year ago

You'll need to set

    "rust-analyzer.cargo.checkOnSave.invocationLocation": "root",
    "rust-analyzer.cargo.checkOnSave.invocationStrategy": "once",

The reason I didn't add those to the dev guide is that you won't get diagnostics for linked projects anyways until x.py changes the paths in its output to be relative to the project root or rust-lang/cargo#11007 is fixed (assuming x.py is using that flag). Otherwise r-a will not be able to deduce the correct files for the diagnostics as they are relative to the Cargo.toml of the linked projects without knowing which diagnostics come from what linked project.

I think we should add them anyway - even if the diagnostics are missing, having go-to-definition available is still extremely useful.

jyn514 commented 1 year ago

Mentoring instructions: add "rust-analyzer.linkedProjects": ["src/bootstrap/Cargo.toml", "Cargo.toml"], to this section of the dev-guide.

zephaniahong commented 1 year ago

Happy to help add this to the dev-guide but I noticed that the settings.json portion in the dev guide is no longer there. Is it due to #107547 ?

zephaniahong commented 1 year ago

@rustbot claim

jyn514 commented 1 year ago

Oh, sorry - this was fixed by https://github.com/rust-lang/rust/pull/107757