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 on WSL cannot find sysroot, VSCode 1.49.2 #6106

Closed
ChronosWS opened this issue Sep 30, 2020 · 10 comments
Closed

rust-analyzer on WSL cannot find sysroot, VSCode 1.49.2 #6106

ChronosWS opened this issue Sep 30, 2020 · 10 comments
Labels
E-unknown It's unclear if the issue is E-hard or E-easy without digging in S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@ChronosWS
Copy link

VSCode: 1.49.2
Rust-Analyzer plugin: 0.2.328

Expected: Language server loads and operates correctly (as it did yesterday before today's VSCode update)

Actual: Language server fails to load, all language features unavailable in VSCode

Error (from extension toast):

rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /home/cliff/<redacted>/Cargo.toml. Is rust-src installed?: can't load standard library from sysroot /usr/local (discovered via `rustc --print sysroot`) try running `rustup component add rust-src` or set `RUST_SRC_PATH`

Diagnostics:
From the VSCode Bash shell:

$ rustc --print sysroot
/home/cliff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu
$ rustup component add rust-src
info: component 'rust-src' is up to date

From Rust Analyzer Language Server diagnostics window:

[ERROR rust_analyzer::reload] failed to load workspace: Failed to find sysroot for Cargo.toml file /home/cliff/<redacted>/Cargo.toml. Is rust-src installed?: can't load standard library from sysroot
/usr/local
(discovered via `rustc --print sysroot`)
try running `rustup component add rust-src` or set `RUST_SRC_PATH`

From Rust Analyzer Client diagnostics window:

INFO [9/30/2020, 12:21:44 PM]: Extension version: 0.2.328
INFO [9/30/2020, 12:21:44 PM]: Using configuration {
  lruCapacity: null,
  files: { watcher: 'client', exclude: [] },
  notifications: { cargoTomlNotFound: true },
  cargo: {
    autoreload: true,
    noDefaultFeatures: false,
    allFeatures: false,
    features: [],
    loadOutDirsFromCheck: false,
    target: null
  },
  rustfmt: { extraArgs: [], overrideCommand: null },
  checkOnSave: {
    enable: true,
    extraArgs: [],
    command: 'check',
    overrideCommand: null,
    allTargets: true,
    noDefaultFeatures: null,
    allFeatures: null,
    features: null,
    target: null
  },
  cargoRunner: null,
  runnableEnv: null,
  inlayHints: {
    enable: true,
    typeHints: true,
    chainingHints: true,
    parameterHints: true,
    maxLength: 20
  },
  completion: {
    addCallParenthesis: true,
    addCallArgumentSnippets: true,
    postfix: { enable: true }
  },
  callInfo: { full: true },
  updates: { channel: 'stable', askBeforeDownload: true },
  serverPath: null,
  trace: { server: 'off', extension: false },
  procMacro: { enable: false },
  debug: {
    engine: 'auto',
    sourceFileMap: {
      '/rustc/<id>': '${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust'
    },
    openDebugPane: false,
    engineSettings: {}
  },
  lens: { enable: true, run: true, debug: true, implementations: true },
  hoverActions: {
    enable: true,
    implementations: true,
    run: true,
    debug: true,
    gotoTypeDef: true
  },
  linkedProjects: null,
  withSysroot: true,
  diagnostics: {
    enable: true,
    enableExperimental: true,
    disabled: [],
    warningsAsInfo: [],
    warningsAsHint: []
  },
  assist: { importMergeBehaviour: 'full' }
}
INFO [9/30/2020, 12:21:44 PM]: PersistentState: {
  lastCheck: undefined,
  releaseId: undefined,
  serverVersion: '0.2.328'
}
INFO [9/30/2020, 12:21:44 PM]: Using server binary at /home/cliff/.vscode-server/data/User/globalStorage/matklad.rust-analyzer/rust-analyzer-linux
WARN [9/30/2020, 12:22:39 PM]: LSP request timed out {
  method: 'rust-analyzer/inlayHints',
  param: {
    textDocument: {
      uri: 'file:///home/cliff/<redacted>/src/main.rs'
    }
  },
  error: [ResponseError: Rust Analyzer is still loading...
  	at handleResponse (/home/cliff/.vscode-server/extensions/matklad.rust-analyzer-0.2.328/out/src/main.js:3779:48)
  	at processMessageQueue (/home/cliff/.vscode-server/extensions/matklad.rust-analyzer-0.2.328/out/src/main.js:3594:17)
  	at Immediate.<anonymous> (/home/cliff/.vscode-server/extensions/matklad.rust-analyzer-0.2.328/out/src/main.js:3578:13)
  	at processImmediate (internal/timers.js:439:21)] {
    code: -32801,
    data: undefined
  }
}
@bjorn3
Copy link
Member

bjorn3 commented Sep 30, 2020

can't load standard library from sysroot /usr/local (discovered via rustc --print sysroot)

Is it possible that ~/.cargo/bin is not in your PATH for vscode? Did you set the PATH in ~/.profile or ~/.bashrc/~/.zshrc?

@ChronosWS
Copy link
Author

can't load standard library from sysroot /usr/local (discovered via rustc --print sysroot)

Is it possible that ~/.cargo/bin is not in your PATH for vscode? Did you set the PATH in ~/.profile or ~/.bashrc/~/.zshrc?

$ echo $PATH
/home/cliff/.cargo/bin;...
$ which cargo
/home/cliff/.cargo/bin/cargo

Is there some way besides that which VSCode might require for the path to be recognized?

@bjorn3
Copy link
Member

bjorn3 commented Sep 30, 2020

You are printing the PATH for your shell. This is not necessarily identical to the PATH for graphical applications. For example ~/.profile is runned when logging in, meaning that it applies for all programs. ~/.bashrc only runs when you open a shell, meaning that it only applies to that shell session and not for example vscode, unless you ran vscode from the terminal.

@ChronosWS
Copy link
Author

You are printing the PATH for your shell. This is not necessarily identical to the PATH for graphical applications. For example ~/.profile is runned when logging in, meaning that it applies for all programs. ~/.bashrc only runs when you open a shell, meaning that it only applies to that shell session and not for example vscode, unless you ran vscode from the terminal.

Yes, I always run code from the WSL terminal - I don't do a post-hoc connection to Remote WSL

@ChronosWS
Copy link
Author

Though in any case, I see in .profile the following:

export PATH="$HOME/.cargo/bin:$PATH"

@ChronosWS
Copy link
Author

If there are any additional diagnostics I can enable to help debug this please let me know :)

@matklad matklad added E-unknown It's unclear if the issue is E-hard or E-easy without digging in S-unactionable Issue requires feedback, design decisions or is blocked on other work labels Oct 14, 2020
@matklad
Copy link
Member

matklad commented Oct 14, 2020

Have no idea what's going on here. Added some more logging in #6230.

@lnicola
Copy link
Member

lnicola commented Jan 20, 2021

@ChronosWS are you still seeing this?

@patbecich
Copy link

I experienced a similar issue. If I open an individual Rust file in VSCode (i.e. cd src; code main.rs), rust-analyzer shows an unresolved import error. Cargo.toml exists in the project root, but it seems rust-analyzer does not find it.
If I open the project directory in VSCode, and then open the Rust file, rust-analyzer works as expected.
I'm not sure if my issue is this: #6038

@Veykril
Copy link
Member

Veykril commented Dec 14, 2021

@patbecich r-a requires the cargo workspace to be fully opened for it to work, single files do not work properly(we have some stuff now that allows them to work in some fashion but very very limited).

Closing as OP hasn't replied and doesn't seem to be active currently anymore.

@Veykril Veykril closed this as completed Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-unknown It's unclear if the issue is E-hard or E-easy without digging in S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

6 participants