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 won't work on this rustlings repo #12235

Closed
7-- opened this issue May 12, 2022 · 12 comments
Closed

rust-analyzer won't work on this rustlings repo #12235

7-- opened this issue May 12, 2022 · 12 comments
Labels
C-support Category: support questions

Comments

@7--
Copy link

7-- commented May 12, 2022

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: 5d5bbec 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/': '${env:USERPROFILE}/.rustup/toolchains//lib/rustlib/src/rust'
},
openDebugPane: false,
engineSettings: {}
},
assist: {
exprFillDefault: 'todo',
importGranularity: 'crate',
importEnforceGranularity: false,
importPrefix: 'plain',
importGroup: true,
allowMergingIntoGlobImports: true
},
cache: { warmup: true },
callInfo: { full: true },
cargo: {
autoreload: true,
allFeatures: true,
unsetTest: [ 'core' ],
features: [],
runBuildScripts: true,
runBuildScriptsCommand: null,
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: null
},
completion: {
addCallArgumentSnippets: true,
addCallParenthesis: true,
snippets: {
'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'
}
},
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/': '${env:USERPROFILE}/.rustup/toolchains//lib/rustlib/src/rust'
},
openDebugPane: false,
engineSettings: {}
},
assist: {
exprFillDefault: 'todo',
importGranularity: 'crate',
importEnforceGranularity: false,
importPrefix: 'plain',
importGroup: true,
allowMergingIntoGlobImports: true
},
cache: { warmup: true },
callInfo: { full: true },
cargo: {
autoreload: true,
allFeatures: true,
unsetTest: [ 'core' ],
features: [],
runBuildScripts: true,
runBuildScriptsCommand: null,
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: null
},
completion: {
addCallArgumentSnippets: true,
addCallParenthesis: true,
snippets: {
'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'
}
},
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 } }
}
}

@bjorn3
Copy link
Member

bjorn3 commented May 12, 2022

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 rust-lang/rustlings#917 correctly.

@7--
Copy link
Author

7-- commented May 12, 2022

"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"]

}```

@lnicola
Copy link
Member

lnicola commented May 13, 2022

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.

@lnicola lnicola added the C-support Category: support questions label May 13, 2022
@7--
Copy link
Author

7-- commented May 13, 2022

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.

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

@rbruno95
Copy link

@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.

@JeppeKlitgaard
Copy link

I ran into this as well.

I can confirm that running rustlings lsp once solves the problem in VSCode as well.

@gachikuku
Copy link

I got neovim and running rustlings lsp solves the problem as well.

@Veykril Veykril closed this as completed Jan 19, 2023
@cossieB
Copy link

cossieB commented Mar 25, 2023

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

@Veykril
Copy link
Member

Veykril commented Mar 25, 2023

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)

@cossieB
Copy link

cossieB commented Mar 25, 2023

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
broken
And this is what I changed it to
fixed
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.

@BigChunguz69
Copy link

@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.

@bbkr
Copy link

bbkr commented May 13, 2024

Running rustlings lsp and restarting LSP server fixed the issue in Kate editor. Now I have code analysis and completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

10 participants