macOS下VSCode rust-analyzer权限拒绝无法加载工作区问题求助
macOS下VSCode配置rust-analyzer报错:误执行.cargo目录导致权限不足无法加载工作区
目标
在macOS系统上配置Visual Studio Code(VSCode)用于Rust开发。此前使用官方Rust扩展可完成基础开发,但运行表现不稳定,了解到rust-analyzer扩展可提供更优质的开发体验,因此选择安装该扩展。
问题现象
安装rust-analyzer扩展后,持续抛出如下错误,无法正常工作:
rust-analyzer failed to load workspace: "/Users/michaelbailey/.cargo" "--version" failed: Permission denied (os error 13)
经排查判断,插件错误地尝试执行.cargo目录本身,而非目录下的cargo可执行文件:
- 执行错误路径命令时返回权限不足:
$ /Users/michaelbailey/.cargo --version zsh: permission denied: /Users/michaelbailey/.cargo
- 执行正确路径命令可正常返回cargo版本信息:
$ /Users/michaelbailey/.cargo/bin/cargo --version cargo 1.61.0 (a028ae42f 2022-04-29)
该路径识别错误导致rust-analyzer无法加载任何Rust项目。
已尝试的排查操作
- 重新安装Rust-analyzer扩展
- 禁用其他所有Rust相关插件排除冲突
- 切换至rust-analyzer扩展预发布版本
- 从Rust官方网站重新安装Rust工具链
- 清除所有Rust相关配置项
- 新建空白测试项目,排除单项目配置错误的可能
求助需求
- 获取配置rust-analyzer使其指向正确cargo可执行文件路径的方法
- 获取其他可修复该rust-analyzer加载失败问题的可行方案
运行日志
VSCode输出面板中rust-analyzer的运行日志如下:
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' } } } }
内容的提问来源于stack exchange,提问作者Michael Bailey
相关产品推荐
相关产品推荐

