rust-analyzer
rust-analyzer copied to clipboard
rust-analyzer won't work on this rustlings repo
I'm doing Rustlings excersises. If I clone this Rustlings repo rust-analyzer works fine. https://github.com/rust-lang/rustlings
I created my own repo for Rustlings so I can save my work. This repo won't work with rust-analyzer reguarless of commit number. I tried cloning a new copy then checking out a bunch of old commits in the repo (before any of my changes) and oddly no version works at all. https://github.com/7--/rustlings
See if you can get rust-analyzer to work on this repo even using an old version. This repo was working fine at one point. rust-analyzer is the only extension I have installed in VS code.
rust-analyzer version: 5d5bbec9b 2022-05-09 stable
Status: Workspaces: Loaded 75 packages across 1 workspace.
Analysis: 32mb of files 0b of index symbols (0) 1037 trees, 128 preserved 11163 trees, 128 preserved (Macros) 253mb in total
Rust Analyzer Client:
INFO [5/12/2022, 4:32:18 PM]: Extension version: 0.2.1048
INFO [5/12/2022, 4:32:18 PM]: Using configuration {
cargoRunner: null,
runnableEnv: null,
server: { path: null, extraEnv: null },
trace: { server: 'off', extension: false },
debug: {
engine: 'auto',
sourceFileMap: {
'/rustc/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'
}
},
postfix: { enable: true },
autoimport: { enable: true },
autoself: { enable: true },
privateEditable: { enable: false }
},
diagnostics: {
enable: true,
enableExperimental: false,
disabled: [],
remapPrefix: {},
warningsAsHint: [],
warningsAsInfo: []
},
experimental: { procAttrMacros: true },
files: { watcher: 'client', excludeDirs: [] },
highlightRelated: {
references: true,
exitPoints: true,
breakPoints: true,
yieldPoints: true
},
highlighting: { strings: true },
hover: { documentation: true, linksInHover: true },
hoverActions: {
debug: true,
enable: true,
gotoTypeDef: true,
implementations: true,
references: false,
run: true
},
inlayHints: {
renderColons: true,
maxLength: 25,
parameterHints: true,
typeHints: true,
chainingHints: true,
closureReturnTypeHints: false,
reborrowHints: false,
lifetimeElisionHints: { enable: 'never', useParameterNames: false },
hideNamedConstructorHints: false
},
joinLines: {
joinElseIf: true,
removeTrailingComma: true,
unwrapTrivialBlock: true,
joinAssignments: true
},
lens: {
debug: true,
enable: true,
implementations: true,
run: true,
methodReferences: false,
references: false,
enumVariantReferences: false,
forceCustomCommands: true
},
linkedProjects: [],
lruCapacity: null,
notifications: { cargoTomlNotFound: true },
primeCaches: { numThreads: 0 },
procMacro: { enable: true, server: null, ignored: {} },
runnables: { overrideCargo: null, cargoExtraArgs: [] },
rustcSource: null,
rustfmt: {
extraArgs: [],
overrideCommand: null,
enableRangeFormatting: false
},
workspace: {
symbol: { search: { scope: 'workspace', kind: 'only_types', limit: 128 } }
}
}
INFO [5/12/2022, 4:32:18 PM]: PersistentState: { serverVersion: '0.2.1048' }
INFO [5/12/2022, 4:32:19 PM]: Using server binary at /home/phil/.vscode/extensions/matklad.rust-analyzer-0.2.1048-linux-x64/server/rust-analyzer
INFO [5/12/2022, 4:32:22 PM]: Extension version: 0.2.1048
INFO [5/12/2022, 4:32:22 PM]: Using configuration {
cargoRunner: null,
runnableEnv: null,
server: { path: null, extraEnv: null },
trace: { server: 'off', extension: false },
debug: {
engine: 'auto',
sourceFileMap: {
'/rustc/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'
}
},
postfix: { enable: true },
autoimport: { enable: true },
autoself: { enable: true },
privateEditable: { enable: false }
},
diagnostics: {
enable: true,
enableExperimental: false,
disabled: [],
remapPrefix: {},
warningsAsHint: [],
warningsAsInfo: []
},
experimental: { procAttrMacros: true },
files: { watcher: 'client', excludeDirs: [] },
highlightRelated: {
references: true,
exitPoints: true,
breakPoints: true,
yieldPoints: true
},
highlighting: { strings: true },
hover: { documentation: true, linksInHover: true },
hoverActions: {
debug: true,
enable: true,
gotoTypeDef: true,
implementations: true,
references: false,
run: true
},
inlayHints: {
renderColons: true,
maxLength: 25,
parameterHints: true,
typeHints: true,
chainingHints: true,
closureReturnTypeHints: false,
reborrowHints: false,
lifetimeElisionHints: { enable: 'never', useParameterNames: false },
hideNamedConstructorHints: false
},
joinLines: {
joinElseIf: true,
removeTrailingComma: true,
unwrapTrivialBlock: true,
joinAssignments: true
},
lens: {
debug: true,
enable: true,
implementations: true,
run: true,
methodReferences: false,
references: false,
enumVariantReferences: false,
forceCustomCommands: true
},
linkedProjects: [],
lruCapacity: null,
notifications: { cargoTomlNotFound: true },
primeCaches: { numThreads: 0 },
procMacro: { enable: true, server: null, ignored: {} },
runnables: { overrideCargo: null, cargoExtraArgs: [] },
rustcSource: null,
rustfmt: {
extraArgs: [],
overrideCommand: null,
enableRangeFormatting: false
},
workspace: {
symbol: { search: { scope: 'workspace', kind: 'only_types', limit: 128 } }
}
}
You need to set "rust-analyzer.cargo.features": ["exercises"]
in your editor configuration for the rustling workspace. Rustlings has an unusual project structure. This config causes rustlings to generate extra files necessary for rust-analyzer to understand the project structure if I understand https://github.com/rust-lang/rustlings/pull/917 correctly.
"rust-analyzer.cargo.features": ["exercises"]
I get this error when I put that line in my settings.json
[ERROR rust_analyzer::lsp_utils] rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/phil/sol-workspace/rustlings/Cargo.toml, cargo 1.61.0-nightly (109bfbd 2022-03-17): Failed to run `"cargo" "metadata" "--format-version" "1" "--features" "exercises" "--manifest-path" "/home/phil/sol-workspace/rustlings/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: Package `rustlings v4.6.0 (/home/phil/sol-workspace/rustlings)` does not have the feature `exercises`
[ERROR rust_analyzer::lsp_utils] rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/phil/sol-workspace/rustlings/Cargo.toml, cargo 1.61.0-nightly (109bfbd 2022-03-17): Failed to run `"cargo" "metadata" "--format-version" "1" "--features" "exercises" "--manifest-path" "/home/phil/sol-workspace/rustlings/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: Package `rustlings v4.6.0 (/home/phil/sol-workspace/rustlings)` does not have the feature `exercises`
[Error - 5:32:37 PM] Registering progress handler for token rustAnalyzer/Roots Scanned failed.
Error: Progress handler for token rustAnalyzer/Roots Scanned already registered
at Object.onProgress (/home/phil/.vscode/extensions/matklad.rust-analyzer-0.2.1048-linux-x64/out/main.js:29:2259)
at Pg.onProgress (/home/phil/.vscode/extensions/matklad.rust-analyzer-0.2.1048-linux-x64/out/main.js:34:53976)
at new hh (/home/phil/.vscode/extensions/matklad.rust-analyzer-0.2.1048-linux-x64/out/main.js:34:6850)
at r (/home/phil/.vscode/extensions/matklad.rust-analyzer-0.2.1048-linux-x64/out/main.js:36:27492)
at qn (/home/phil/.vscode/extensions/matklad.rust-analyzer-0.2.1048-linux-x64/out/main.js:3:8774)
at Bn (/home/phil/.vscode/extensions/matklad.rust-analyzer-0.2.1048-linux-x64/out/main.js:3:6618)
at Immediate._onImmediate (/home/phil/.vscode/extensions/matklad.rust-analyzer-0.2.1048-linux-x64/out/main.js:3:6531)
at processImmediate (node:internal/timers:464:21)
"editor.minimap.enabled": false,
"workbench.colorTheme": "Default Light+",
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"java.configuration.checkProjectSettingsExclusions": false,
"python.jediEnabled": false,
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"workbench.startupEditor": "newUntitledFile",
"update.mode": "manual",
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"workbench.editor.enablePreview": false,
"python.languageServer": "Default",
"jshint.options": {
"esversion":8
},
"jshint.excludePath": "",
// Controls whether text selected in the terminal will be copied to the clipboard.
"terminal.integrated.copyOnSelection": true,
"solidity.compileUsingLocalVersion": "/home/phil/Programs/soljson-v0.6.12+commit.27d51765.js",
"solidity.compileUsingRemoteVersion": "soljson-v0.6.12+commit.27d51765.js",
"workbench.editor.titleScrollbarSizing": "large",
"jshint.config": "",
"editor.emptySelectionClipboard": false,
"remote.SSH.defaultExtensions": [
"gitpod.gitpod-remote-ssh"
],
"remote.SSH.configFile": "/tmp/gitpod_ssh_config-598909-vGlT9kgxLClk",
"rust-analyzer.cargo.features": ["exercises"]
}```
~~What does git status
show in your clone of the rustlings
repo?~~
Never mind. You've started from an older version of rustlings
, which doesn't contain the exercises
feature/fix. You can probably copy over your source code changes.
~What does
git status
show in your clone of therustlings
repo?~Never mind. You've started from an older version of
rustlings
, which doesn't contain theexercises
feature/fix. You can probably copy over your source code changes.
I pulled from the Rustlings repo and fixed the conflicts and errors, but still rust-analyzer doesnt work. Not seeing any rust-analyszer errors. I'm already like 80% done with Rustlings so if it's just this repo I'll live without it.
$ git pull rustlings main
Enter passphrase for key '/home/phil/.ssh/id_rsa':
From github.com:rust-lang/rustlings
* branch main -> FETCH_HEAD
Already up to date.
$ git status
On branch phil
Your branch is up to date with 'origin/phil'.
nothing to commit, working tree clean
@7-- Hi, maybe it's too late for it, but I had the same problem, rustlings lsp
worked for me, I am using LunarVim though.
I ran into this as well.
I can confirm that running rustlings lsp
once solves the problem in VSCode as well.
I got neovim and running rustlings lsp
solves the problem as well.
For me rustlings lsp
didn't quite work. It generated the rust-project.json file but autocomplete and type hints weren't working. Upon investigating I noticed that the 'sysroot_src' value in the json truncated my Windows user name - presumably because of the space in it. So I changed it to C:\Users\$MY_USER_NAME\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library. Now it works, although it's not showing some errors in the editor like a normal cargo project. I'm not sure if that's by design
You mean the truncation happened on the r-a side or the path in the json file was truncated? If the latter it would be nice to report that to the rustlings repo.
Regarding the errors I am unsure, it might not work that well given the structure (I'm hoping to make rustlings work better with some design changes)
You mean the truncation happened on the r-a side or the path in the json file was truncated? If the latter it would be nice to report that to the rustlings repo.
Basically this is what rustlings lsp
generates
And this is what I changed it to
I just noticed that a bit more than my user name were truncated. Thanks I'll report this bug to the Rustlings team
Regarding the errors I am unsure, it might not work that well given the structure (I'm hoping to make rustlings work better with some design changes)
Thanks for all the work you've been putting Rust Analyzer. The errors still show in the terminal so I'll manage.
@7-- Hi, maybe it's too late for it, but I had the same problem,
rustlings lsp
worked for me, I am using LunarVim though.
I can confirm that the command still works if you have any problems regarding intellisense.