rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.06k stars 1.56k forks source link

rust-analyzer goes into "error state" in rustc repository #8667

Closed RalfJung closed 3 years ago

RalfJung commented 3 years ago

To reproduce this problem, open the rustc repository in vsocde with rust-analyzer installed. After some time the "rust-analyzer" text in the status bar at the bottom turns into a barely readable dark-gray-on-blue with a warning triangle in front of it. Hovering that item shows "cargo check failed" followed by some cargo output ending in "...". No error is visible in that text (I did not find a way to copy-paste all that text). Running ./x.py check on the same code works just fine.

I have no idea what this "error state" means, though...

My workspace settings JSON to make RA work on rustc looks as follows:

{
    "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"
    ],
    "editor.formatOnSave": false,
    "files.watcherExclude": {
        "*rustc*/src/llvm-project/**": true,
        "*rustc*/build/**": true,
    },
    "files.exclude": {
        "src/llvm-project/**": true,
        "build/**": true
    },
}

"Rust Analyzer Client" output says

INFO [4/26/2021, 2:26:35 PM]: Extension version: 0.2.574
INFO [4/26/2021, 2:26:35 PM]: Using configuration {
  cargoRunner: null,
  runnableEnv: null,
  inlayHints: {
    enable: false,
    chainingHints: true,
    maxLength: 25,
    parameterHints: true,
    typeHints: true
  },
  updates: { channel: 'stable', askBeforeDownload: true },
  server: { path: null, extraEnv: null },
  trace: { server: 'off', extension: false },
  debug: {
    engine: 'auto',
    sourceFileMap: {
      '/rustc/<id>': '${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust'
    },
    openDebugPane: false,
    engineSettings: {}
  },
  assist: {
    importMergeBehavior: 'full',
    importPrefix: 'plain',
    importGroup: true
  },
  callInfo: { full: true },
  cargo: {
    autoreload: true,
    allFeatures: false,
    features: [],
    runBuildScripts: true,
    useRustcWrapperForBuildScripts: true,
    noDefaultFeatures: false,
    target: null,
    noSysroot: false
  },
  checkOnSave: {
    enable: true,
    allFeatures: null,
    allTargets: true,
    command: 'check',
    noDefaultFeatures: null,
    target: null,
    extraArgs: [],
    features: null,
    overrideCommand: [ './x.py', 'check', '--json-output', 'library/std' ]
  },
  completion: {
    addCallArgumentSnippets: true,
    addCallParenthesis: true,
    postfix: { enable: true },
    autoimport: { enable: true }
  },
  diagnostics: {
    enable: true,
    enableExperimental: true,
    disabled: [ 'unlinked-file', 'missing-match-arm' ],
    remapPrefix: {},
    warningsAsHint: [],
    warningsAsInfo: []
  },
  files: { watcher: 'client', excludeDirs: [] },
  hoverActions: {
    debug: true,
    enable: true,
    gotoTypeDef: true,
    implementations: true,
    run: true,
    linksInHover: true
  },
  lens: {
    debug: true,
    enable: false,
    implementations: true,
    run: true,
    methodReferences: false,
    references: false
  },
  linkedProjects: [],
  lruCapacity: null,
  notifications: { cargoTomlNotFound: true },
  procMacro: { enable: true, server: null },
  runnables: { overrideCargo: null, cargoExtraArgs: [] },
  rustcSource: null,
  rustfmt: {
    extraArgs: [],
    overrideCommand: [ './build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt' ]
  }
}
INFO [4/26/2021, 2:26:35 PM]: PersistentState: {
  lastCheck: 1590603478202,
  releaseId: 26923638,
  serverVersion: '0.2.565'
}
INFO [4/26/2021, 2:27:02 PM]: Using server binary at /home/r/.config/Code/User/globalStorage/matklad.rust-analyzer/rust-analyzer-x86_64-unknown-linux-gnu
flodiebold commented 3 years ago

Can you try setting rust-analyzer.cargo.runBuildScripts to false?

RalfJung commented 3 years ago

I did that, then reloaded the window, but behavior is still as described above.

matklad commented 3 years ago

@RalfJung you want

{
    "rust-analyzer.cargo.runBuildScripts": false,
    "rust-analyzer.procMacro.enable": false,
}

If you don't disable proc macros, we'll still run build scripts. The error message will be marginally better with #8670.

The UX about settings is unfriendly ( Part of the problem is that VS Code doesn't allow us to distinguish unset settings...

RalfJung commented 3 years ago

Yes, that does get rid of the error, thanks. :)

Is it expected that these features break when used in the rustc compiler workspace?

matklad commented 3 years ago

Yes at the moment. This features require tight integration with the build system. At the moment this is hard-coded to cargo check --workspace, which fails for me in the rustc repo. There's a desire to make that configurable, so that one can plug ./x.py check there, but we haven't done that yet.

matklad commented 3 years ago

(also, to give some more context -- rust-analyzer was in this partially-error state since we enabled proc macros by deafult a while ago. What changed is that we now actually report this error as bad good as we can :)