2

Goal

I'm trying to setup Visual Studio Code(vscode) on macOS for rust development. I had my setup working, using the official rust extension, but it wasn't always consistent. I saw that the rust-analyzer extension could provide a better experience.

Problem

Now that I have installed the extension, It keep throwing the following error:

rust-analyzer failed to load workspace: "/Users/michaelbailey/.cargo" "--version" failed: Permission denied (os error 13)

From my understanding, the plugin is trying to execute the .cargo folder rather than cargo itself.

running

$ /Users/michaelbailey/.cargo --version  
zsh: permission denied: /Users/michaelbailey/.cargo

instead of

$ /Users/michaelbailey/.cargo/bin/cargo --version 
cargo 1.61.0 (a028ae42f 2022-04-29)

This is causing rust analyser to fail loading any project.

What i have tried

  • Reinstalling the Rust-analyzer extension.
  • Disabling other rust based plugins.
  • Switching to the pre-release version.
  • reinstalling rust from the rust website.
  • clearing all rust settings.
  • creating a new project to test if my project was misconfigured somehow.

what i need help with

  • finding out a way to config rust-analyzer to point to the right file.
  • another way to resolve rust-analyzer.

Any help or pointers on the matter would be greatly appreciated.

Logs

output of rust-analyzer, in the vscode output tab.

INFO [6/9/2022, 6:10:00 PM]: Extension version: 0.3.1083
INFO [6/9/2022, 6:10:00 PM]: Using configuration {
  cargoRunner: null,
  runnableEnv: null,
  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: { expressionFillDefault: 'todo' },
  cachePriming: { enable: true, numThreads: 0 },
  cargo: {
    autoreload: true,
    buildScripts: { enable: true, overrideCommand: null, useRustcWrapper: true },
    features: [],
    noDefaultFeatures: false,
    noSysroot: false,
    target: null,
    unsetTest: [ 'core' ]
  },
  checkOnSave: {
    allTargets: true,
    command: 'check',
    enable: true,
    extraArgs: [],
    features: null,
    noDefaultFeatures: null,
    overrideCommand: null,
    target: null
  },
  completion: {
    autoimport: { enable: true },
    autoself: { enable: true },
    callable: { snippets: 'fill_arguments' },
    postfix: { enable: true },
    privateEditable: { enable: false },
    snippets: {
      custom: {
        'Arc::new': {
          postfix: 'arc',
          body: 'Arc::new(${receiver})',
          requires: 'std::sync::Arc',
          description: 'Put the expression into an `Arc`',
          scope: 'expr'
        },
        'Rc::new': {
          postfix: 'rc',
          body: 'Rc::new(${receiver})',
          requires: 'std::rc::Rc',
          description: 'Put the expression into an `Rc`',
          scope: 'expr'
        },
        'Box::pin': {
          postfix: 'pinbox',
          body: 'Box::pin(${receiver})',
          requires: 'std::boxed::Box',
          description: 'Put the expression into a pinned `Box`',
          scope: 'expr'
        },
        Ok: {
          postfix: 'ok',
          body: 'Ok(${receiver})',
          description: 'Wrap the expression in a `Result::Ok`',
          scope: 'expr'
        },
        Err: {
          postfix: 'err',
          body: 'Err(${receiver})',
          description: 'Wrap the expression in a `Result::Err`',
          scope: 'expr'
        },
        Some: {
          postfix: 'some',
          body: 'Some(${receiver})',
          description: 'Wrap the expression in an `Option::Some`',
          scope: 'expr'
        }
      }
    }
  },
  diagnostics: {
    disabled: [],
    enable: true,
    experimental: { enable: false },
    remapPrefix: {},
    warningsAsHint: [],
    warningsAsInfo: []
  },
  files: { excludeDirs: [], watcher: 'client' },
  highlightRelated: {
    breakPoints: { enable: true },
    exitPoints: { enable: true },
    references: { enable: true },
    yieldPoints: { enable: true }
  },
  hover: {
    actions: {
      debug: { enable: true },
      enable: true,
      gotoTypeDef: { enable: true },
      implementations: { enable: true },
      references: { enable: false },
      run: { enable: true }
    },
    documentation: { enable: true },
    links: { enable: true }
  },
  imports: {
    granularity: { enforce: false, group: 'crate' },
    group: { enable: true },
    merge: { glob: true },
    prefix: 'plain'
  },
  inlayHints: {
    bindingModeHints: { enable: false },
    chainingHints: { enable: true },
    closingBraceHints: { enable: true, minLines: 25 },
    closureReturnTypeHints: { enable: 'never' },
    lifetimeElisionHints: { enable: 'never', useParameterNames: false },
    maxLength: 25,
    parameterHints: { enable: true },
    reborrowHints: { enable: 'never' },
    renderColons: true,
    typeHints: {
      enable: true,
      hideClosureInitialization: false,
      hideNamedConstructor: false
    }
  },
  joinLines: {
    joinAssignments: true,
    joinElseIf: true,
    removeTrailingComma: true,
    unwrapTrivialBlock: true
  },
  lens: {
    debug: { enable: true },
    enable: true,
    forceCustomCommands: true,
    implementations: { enable: true },
    references: {
      adt: { enable: false },
      enumVariant: { enable: false },
      method: { enable: false },
      trait: { enable: false }
    },
    run: { enable: true }
  },
  linkedProjects: [],
  lru: { capacity: null },
  notifications: { cargoTomlNotFound: true },
  procMacro: {
    attributes: { enable: true },
    enable: true,
    ignored: {},
    server: null
  },
  runnables: { command: null, extraArgs: [] },
  rustc: { source: null },
  rustfmt: {
    extraArgs: [],
    overrideCommand: null,
    rangeFormatting: { enable: false }
  },
  semanticHighlighting: { strings: { enable: true } },
  signatureInfo: { detail: 'full', documentation: { enable: true } },
  typing: { autoClosingAngleBrackets: { enable: false } },
  workspace: {
    symbol: { search: { kind: 'only_types', limit: 128, scope: 'workspace' } }
  }
}
INFO [6/9/2022, 6:10:00 PM]: PersistentState: { serverVersion: '0.3.1083' }
INFO [6/9/2022, 6:10:00 PM]: Using server binary at /Users/michaelbailey/.vscode/extensions/rust-lang.rust-analyzer-0.3.1083-darwin-x64/server/rust-analyzer
INFO [6/9/2022, 6:10:01 PM]: Extension version: 0.3.1083
INFO [6/9/2022, 6:10:01 PM]: Using configuration {
  cargoRunner: null,
  runnableEnv: null,
  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: { expressionFillDefault: 'todo' },
  cachePriming: { enable: true, numThreads: 0 },
  cargo: {
    autoreload: true,
    buildScripts: { enable: true, overrideCommand: null, useRustcWrapper: true },
    features: [],
    noDefaultFeatures: false,
    noSysroot: false,
    target: null,
    unsetTest: [ 'core' ]
  },
  checkOnSave: {
    allTargets: true,
    command: 'check',
    enable: true,
    extraArgs: [],
    features: null,
    noDefaultFeatures: null,
    overrideCommand: null,
    target: null
  },
  completion: {
    autoimport: { enable: true },
    autoself: { enable: true },
    callable: { snippets: 'fill_arguments' },
    postfix: { enable: true },
    privateEditable: { enable: false },
    snippets: {
      custom: {
        'Arc::new': {
          postfix: 'arc',
          body: 'Arc::new(${receiver})',
          requires: 'std::sync::Arc',
          description: 'Put the expression into an `Arc`',
          scope: 'expr'
        },
        'Rc::new': {
          postfix: 'rc',
          body: 'Rc::new(${receiver})',
          requires: 'std::rc::Rc',
          description: 'Put the expression into an `Rc`',
          scope: 'expr'
        },
        'Box::pin': {
          postfix: 'pinbox',
          body: 'Box::pin(${receiver})',
          requires: 'std::boxed::Box',
          description: 'Put the expression into a pinned `Box`',
          scope: 'expr'
        },
        Ok: {
          postfix: 'ok',
          body: 'Ok(${receiver})',
          description: 'Wrap the expression in a `Result::Ok`',
          scope: 'expr'
        },
        Err: {
          postfix: 'err',
          body: 'Err(${receiver})',
          description: 'Wrap the expression in a `Result::Err`',
          scope: 'expr'
        },
        Some: {
          postfix: 'some',
          body: 'Some(${receiver})',
          description: 'Wrap the expression in an `Option::Some`',
          scope: 'expr'
        }
      }
    }
  },
  diagnostics: {
    disabled: [],
    enable: true,
    experimental: { enable: false },
    remapPrefix: {},
    warningsAsHint: [],
    warningsAsInfo: []
  },
  files: { excludeDirs: [], watcher: 'client' },
  highlightRelated: {
    breakPoints: { enable: true },
    exitPoints: { enable: true },
    references: { enable: true },
    yieldPoints: { enable: true }
  },
  hover: {
    actions: {
      debug: { enable: true },
      enable: true,
      gotoTypeDef: { enable: true },
      implementations: { enable: true },
      references: { enable: false },
      run: { enable: true }
    },
    documentation: { enable: true },
    links: { enable: true }
  },
  imports: {
    granularity: { enforce: false, group: 'crate' },
    group: { enable: true },
    merge: { glob: true },
    prefix: 'plain'
  },
  inlayHints: {
    bindingModeHints: { enable: false },
    chainingHints: { enable: true },
    closingBraceHints: { enable: true, minLines: 25 },
    closureReturnTypeHints: { enable: 'never' },
    lifetimeElisionHints: { enable: 'never', useParameterNames: false },
    maxLength: 25,
    parameterHints: { enable: true },
    reborrowHints: { enable: 'never' },
    renderColons: true,
    typeHints: {
      enable: true,
      hideClosureInitialization: false,
      hideNamedConstructor: false
    }
  },
  joinLines: {
    joinAssignments: true,
    joinElseIf: true,
    removeTrailingComma: true,
    unwrapTrivialBlock: true
  },
  lens: {
    debug: { enable: true },
    enable: true,
    forceCustomCommands: true,
    implementations: { enable: true },
    references: {
      adt: { enable: false },
      enumVariant: { enable: false },
      method: { enable: false },
      trait: { enable: false }
    },
    run: { enable: true }
  },
  linkedProjects: [],
  lru: { capacity: null },
  notifications: { cargoTomlNotFound: true },
  procMacro: {
    attributes: { enable: true },
    enable: true,
    ignored: {},
    server: null
  },
  runnables: { command: null, extraArgs: [] },
  rustc: { source: null },
  rustfmt: {
    extraArgs: [],
    overrideCommand: null,
    rangeFormatting: { enable: false }
  },
  semanticHighlighting: { strings: { enable: true } },
  signatureInfo: { detail: 'full', documentation: { enable: true } },
  typing: { autoClosingAngleBrackets: { enable: false } },
  workspace: {
    symbol: { search: { kind: 'only_types', limit: 128, scope: 'workspace' } }
  }
}
rioV8
  • 24,506
  • 3
  • 32
  • 49
  • If you run the command `which cargo`, does it return the correct path (`/Users/michaelbailey/.cargo/bin/cargo`)? – Mark G Jun 09 '22 at 18:01
  • yes it does. the paths are all setup properly, as i am still able to use cargo with the official extension without extra config. – Michael Bailey Jun 09 '22 at 20:48
  • Looks like this may be a bug specifically for macOS. Might go straight to making a github issue, but i'm not sure how reproducable this is, as i only have one machine. – Michael Bailey Jun 10 '22 at 17:14

1 Answers1

3

I've had the same problem. The reason was that the environment variable CARGO was set to ~/.cargo in my shell resources file. Removing it solved the problem.

You can check your environment by running echo $CARGO.

  • Thanks for mentioning this, I had forgotten this post and asked on their GitHub. Here's a link to it for reference: https://github.com/rust-lang/rust-analyzer/issues/13152 – Michael Bailey Oct 20 '22 at 14:12