rust-analyzer: RA does not work at all when offline
I tried to do a bit of coding on rustc while on a plane without internet, and noticed that RA handles this situation quite badly. cargo metadata fails because it cannot refresh the index, and then basically nothing works, even though everything needed should be available offline. In particular, not even “check on save” does anything – I had to run ./x.py check by hand. That worked perfectly fine, demonstrating that RA could also have run x.py as usual and show the diagnostics in the editor.
rust-analyzer version: ad6810e90 2022-06-06 stable
rustc version: rustc 1.63.0-nightly (e09449220 2022-05-31)
relevant settings:
{
"rust-analyzer.checkOnSave.enable": true,
"rust-analyzer.checkOnSave.overrideCommand": [
"./x.py",
"check",
"--json-output",
"library/std",
"compiler/rustc",
],
"rust-analyzer.rustfmt.overrideCommand": [
"./build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt",
"--edition=2021"
],
"rust-analyzer.procMacro.enable": false,
"editor.formatOnSave": false,
"files.watcherExclude": {
"*rustc*/src/llvm-project/**": true,
"*rustc*/build/**": true,
},
"files.exclude": {
"src/llvm-project/**": true,
"build/**": true
},
"rust-analyzer.cargo.buildScripts.enable": false,
"rust-analyzer.rustc.source": "./Cargo.toml",
"rust-analyzer.hover.actions.references.enable": true,
}
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 10
- Comments: 21 (11 by maintainers)
Links to this issue
Commits related to this issue
- Auto merge of #17915 - Veykril:offline-no-deps, r=Veykril feat: Make rust-analyzer work partially when offline Helps out with https://github.com/rust-lang/rust-analyzer/issues/12499 a bit — committed to rust-lang/rust-analyzer by bors 2 years ago
- Auto merge of #17915 - Veykril:offline-no-deps, r=Veykril feat: Make rust-analyzer work partially when offline Helps out with https://github.com/rust-lang/rust-analyzer/issues/12499 a bit — committed to lnicola/rust by bors 2 years ago
Realized there is a
--no-depsflag which prevents metadata from accessing the registry entirely, so with https://github.com/rust-lang/rust-analyzer/pull/17915 the workspace itself will at least load, while no crates-io dependencies will resolve. Not ideal, but better than not working at allFWIW, I ran into this yesterday on an airplane as well. I managed to work around this in the following way:
cargo check --all-targets --offlinein a terminal to update theCargo.lockfile(Separately, editing dependencies required some manual dexterity, but that’s more of a Cargo issue.)
In my mind the ideal solution here would be that RA uses some connectivity canary (like a trivial DNS request to Google or Cloudflare DNS servers) to assess whether it should try applying
--offline/CARGO_NET_OFFLINE.That’s not only “I’m on an airplane” case, but also “I work in airgapped environment and would like to use Rust”. We do build docker image with all cargo dependencies on a networked host and then move it inside environment without network access.
I believe analyzer worked ok about 9 months ago, but we could have used older RA back then too.
Should there be an
x.py metadata? 😄This might be related to https://github.com/rust-lang/cargo/issues/10096, where
cargo metadatainsists to do some work that is IMO entirely unnecessary.I see two orthogonal issues here:
cargo metadatafailed when it possibly should not havecargo metadatafails, even though I would think it can still run./x.py checkand render the resulting diagnostics in the editorThat only changes the error message to