Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tmandry opened this issue Aug 27, 2022 · 11 comments
Closed

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

tmandry opened this issue Aug 27, 2022 · 11 comments
Assignees
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@tmandry
Copy link
Member

tmandry commented Aug 27, 2022

#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

@tmandry tmandry added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) C-bug Category: This is a bug. labels Aug 27, 2022
@tmandry tmandry changed the title rust-analyzer doesn't work on bootstrap rust-analyzer doesn't work on bootstrap anymore Aug 27, 2022
@RalfJung
Copy link
Member

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

@jyn514
Copy link
Member

jyn514 commented Aug 28, 2022

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
Copy link
Member

jyn514 commented Sep 15, 2022

Blocked on rust-lang/rust-analyzer#13128.

@Veykril
Copy link
Member

Veykril commented Oct 23, 2022

Build scripts now work properly when rust-analyzer.linkedProjects is set if you follow the updated dev-guide instructions rust-lang/rustc-dev-guide#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
Copy link
Member

jyn514 commented Nov 5, 2022

@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
Copy link
Member

Veykril commented Nov 5, 2022

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.

@jyn514
Copy link
Member

jyn514 commented Feb 3, 2023

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
Copy link
Member

jyn514 commented Feb 3, 2023

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

@jyn514 jyn514 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels Feb 3, 2023
@zephaniahong
Copy link
Contributor

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
Copy link
Contributor

@rustbot claim

@jyn514
Copy link
Member

jyn514 commented Feb 9, 2023

Oh, sorry - this was fixed by #107757

@jyn514 jyn514 closed this as completed Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

No branches or pull requests

5 participants