rust-lang / rust-analyzer

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

Installing rust-analyzer on vscode does nothing #12547

Closed jsoneaday closed 2 years ago

jsoneaday commented 2 years ago

I installed rust-analyzer after first uninstalling the original rust extension. The original extension was working. After installing rust-analyzer no intellisense, code completion or hover over info is working. Going to output terminal under rust analyzer language server or trace shows nothing either. Also I cannot right click on any code and go to definitions or find references. The language service seems not to be running at all. There are no error notifications that show up.

rust-analyzer version: 0.3.1091

rustc version: 1.6.0

relevant settings: no custom settings, even tried disabling auto sync

flodiebold commented 2 years ago

I assume the rustc version is a typo and actually 1.60.0? Is this in a specific project? Can you try creating a new project with Cargo, opening that project folder, and opening src/main.rs from there? What's your VSCode version?

jsoneaday commented 2 years ago

I assume the rustc version is a typo and actually 1.60.0? Is this in a specific project? Can you try creating a new project with Cargo, opening that project folder, and opening src/main.rs from there? What's your VSCode version?

I'm sorry yes 1.60.0. But this is happening across multiple projects, some of them I cloned from git and others I created using cargo new.

Currently vscode is 1.68.1, but this has been happening for months across many versions.

Is there a value in settings for rust-analyzer that disables intellisense (code completion, highlighting etc)?

flodiebold commented 2 years ago

Is there a value in settings for rust-analyzer that disables intellisense (code completion, highlighting etc)?

No, since that's the whole point of the extension.

Can you run the Rust Analyzer: Status command with a Rust file open?

jsoneaday commented 2 years ago

Super interesting. So it does run but code completion and hover over do not work still. I've also included a screenshot of some test code. Interestingly the only hover over that worked was on the dead_code attribute.

Workspaces: Loaded 1 packages across 1 workspace.

Analysis: 1032b of files 0b of index symbols (0) 1 trees, 1 preserved 0 trees, 0 preserved (Macros) 0b in total

File info: Does not belong to any crate

Screen Shot 2022-06-18 at 9 59 50 AM
Veykril commented 2 years ago

File info: Does not belong to any crate

This is why, r-a isn't seen your file as being part of any crate in your workspace, so your workspace probably has an odd layout, what does your Cargo.toml look like?

jsoneaday commented 2 years ago

So this issue occurs on all my rust projects. This means projects like serum-dex that I cloned off of github. Here's this project's toml and status result. Since settings can be at the app level how can I get you my entire app level settings for rust-analyzer?

Screen Shot 2022-06-18 at 10 14 31 AM
flodiebold commented 2 years ago

Mh, Loaded 1 packages across 1 workspace does mean that some Cargo package was detected, but not even the sysroot was found. Can you take a simple project created by cargo new, and 1. run cargo metadata in it, and 2. run ~/.vscode/extensions/rust-lang.rust-analyzer-*/server/rust-analyzer analysis-stats . in it?

jsoneaday commented 2 years ago

Here's the entire project. I saved the metadata as metadata.rtf and the stats created a target folder

test-ra.zip

flodiebold commented 2 years ago

What did analysis-stats print?

jsoneaday commented 2 years ago

Sorry

davidchoi@Davids-MacBook-Pro test-ra % ~/.vscode/extensions/rust-lang.rust-analyzer-*/server/rust-analyzer analysis-stats . Database loaded: 2.03s (metadata 1.14s; build 670.87ms) crates: 1, mods: 1, decls: 1, fns: 1 Item Collection: 1.67s exprs: 12, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0 Inference: 825.63ms Total: 2.49s

flodiebold commented 2 years ago

Well, that looks like everything should be working. Just to make sure, what does it show when you 1. open the folder containing the Cargo.toml in VSCode, 2. open src/main.rs, and 3. run "Rust Analyzer: Status"?

jsoneaday commented 2 years ago

Hey thanks for your help. This is what I get

Workspaces: Loaded 1 packages across 1 workspace.

Analysis: 322b of files 0b of index symbols (0) 1 trees, 1 preserved 0 trees, 0 preserved (Macros) 0b in total

File info: Does not belong to any crate

flodiebold commented 2 years ago

Can you set RA_LOG to project_model=debug in rust-analyzer.server.extraEnv, restart rust-analyzer or VSCode, and paste the content of the "Rust Analyzer Language Server" output tab?

jsoneaday commented 2 years ago

It seems to be stuck reloading. Did I set the values correctly?

Screen Shot 2022-06-18 at 6 32 26 PM
jsoneaday commented 2 years ago

Not sure a restart completed but here's the output log.

[DEBUG project_model::rustc_cfg] rustc cfgs found: [Ok("panic=unwind"), Ok("target_arch=aarch64"), Ok("target_endian=little"), Ok("target_env="), Ok("target_family=unix"), Ok("target_has_atomic=128"), Ok("target_has_atomic=16"), Ok("target_has_atomic=32"), Ok("target_has_atomic=64"), Ok("target_has_atomic=8"), Ok("target_has_atomic=ptr"), Ok("target_os=macos"), Ok("target_pointer_width=64"), Ok("target_vendor=apple"), Ok("unix")] [DEBUG project_model::workspace] Did not patch std to depend on cfg-if [DEBUG project_model::rustc_cfg] rustc cfgs found: [Ok("panic=unwind"), Ok("target_arch=aarch64"), Ok("target_endian=little"), Ok("target_env="), Ok("target_family=unix"), Ok("target_has_atomic=128"), Ok("target_has_atomic=16"), Ok("target_has_atomic=32"), Ok("target_has_atomic=64"), Ok("target_has_atomic=8"), Ok("target_has_atomic=ptr"), Ok("target_os=macos"), Ok("target_pointer_width=64"), Ok("target_vendor=apple"), Ok("unix")] [DEBUG project_model::workspace] Did not patch std to depend on cfg-if

flodiebold commented 2 years ago

You originally wrote "no custom settings", but you seem to have quite a few settings in the above screenshot. Could you provide them? Also, could you run the Show RA version command in VSCode and show the output?

jsoneaday commented 2 years ago

I was messing with the settings when it wasn't working. Even with whatever settings were there it was not working. One thing, the rust-analyzer.linkedProjects item was isolated so I moved it closer to the other rust-analyzer tags. This gave the error below. Also you might have found the problem, when I ran Show RA version it shows 0.0.0. Error: Progress handler for token rustAnalyzer/Roots Scanned already registered at Object.onProgress (/Users/davidchoi/.vscode/extensions/rust-lang.rust-analyzer-0.3.1091-darwin-arm64/out/main.js:29:2259) at Og.onProgress (/Users/davidchoi/.vscode/extensions/rust-lang.rust-analyzer-0.3.1091-darwin-arm64/out/main.js:34:53972) at new yp (/Users/davidchoi/.vscode/extensions/rust-lang.rust-analyzer-0.3.1091-darwin-arm64/out/main.js:34:6846) at r (/Users/davidchoi/.vscode/extensions/rust-lang.rust-analyzer-0.3.1091-darwin-arm64/out/main.js:36:27492) at qn (/Users/davidchoi/.vscode/extensions/rust-lang.rust-analyzer-0.3.1091-darwin-arm64/out/main.js:3:8777) at Bn (/Users/davidchoi/.vscode/extensions/rust-lang.rust-analyzer-0.3.1091-darwin-arm64/out/main.js:3:6621) at Immediate._onImmediate (/Users/davidchoi/.vscode/extensions/rust-lang.rust-analyzer-0.3.1091-darwin-arm64/out/main.js:3:6534) at processImmediate (node:internal/timers:464:21)

{ "workbench.startupEditor": "newUntitledFile", "explorer.confirmDelete": false, "typescript.updateImportsOnFileMove.enabled": "always", "javascript.updateImportsOnFileMove.enabled": "always", "explorer.confirmDragAndDrop": false, "editor.fontSize": 14, "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "terminal.integrated.tabs.location": "left", "workbench.iconTheme": "material-icon-theme", "security.workspace.trust.untrustedFiles": "open", "tabnine.experimentalAutoImports": true, "react-native-tools.showUserTips": false, "editor.minimap.enabled": false, "editor.maxTokenizationLineLength": 2000000, "terminal.integrated.enableMultiLinePasteWarning": false, "emmet.includeLanguages": { "javascript": "javascriptreact" }, "rust-analyzer.linkedProjects": [ { "crates": [ { "root_module": "src/program/lib.rs", "edition": "2018", "deps": [] } ] } ], "rust-analyzer.assist.expressionFillDefault": "default", "rust-analyzer.lens.references.adt.enable": true, "rust-analyzer.cargo.features": ["all"], "rust-analyzer.cargo.buildScripts.overrideCommand": null, "rust-analyzer.cachePriming.numThreads": 1, "rust-analyzer.checkOnSave.features": "all", "rust-analyzer.inlayHints.closureReturnTypeHints.enable": "always", "rust-analyzer.inlayHints.lifetimeElisionHints.enable": "always", "rust-analyzer.inlayHints.reborrowHints.enable": "always", "rust-analyzer.hover.actions.references.enable": true, "window.zoomLevel": 2, "rust-analyzer.restartServerOnConfigChange": true, "settingsSync.ignoredExtensions": ["rust-lang.rust-analyzer"], "rust-analyzer.server.extraEnv": { "RA_LOG": "project_model=debug" } }

Screen Shot 2022-06-19 at 8 26 17 AM

jsoneaday commented 2 years ago

What I think happened is when I had the earlier rust plugin somehow it's settings got "merged" with rust-analyzer, but I don't know enough about how the settings work or what to fix

flodiebold commented 2 years ago

Please remove rust-analyzer.linkedProjects completely. I would also suggest removing the other rust-analyzer settings unless you're sure you actually want them.

jsoneaday commented 2 years ago

Yep getting rid of linkedprojects fixed it. Can you tell me what this setting does?

bjorn3 commented 2 years ago

It tells rust-analyzer to work on the specified projects rather than auto detecting them based on Cargo.toml. This is necessary in some cases when for example cargo is not used as build system as in that case rust-analyzer can't auto-detect the project structure.

jsoneaday commented 2 years ago

Thank you for working on this in the weekend.

sweihub commented 1 year ago

It tells rust-analyzer to work on the specified projects rather than auto detecting them based on Cargo.toml. This is necessary in some cases when for example cargo is not used as build system as in that case rust-analyzer can't auto-detect the project structure.

I have such issue on Mac, the rust-analyzer fails to work when I open a directory with a bunch of Rust projects.

rust-analyzer works again when I just open a single project.

sweihub commented 1 year ago

It tells rust-analyzer to work on the specified projects rather than auto detecting them based on Cargo.toml. This is necessary in some cases when for example cargo is not used as build system as in that case rust-analyzer can't auto-detect the project structure.

I have such issue on Mac, the rust-analyzer fails to work when I open a directory with a bunch of Rust projects.

rust-analyzer works again when I just open a single project.

redixhumayun commented 7 months ago

It tells rust-analyzer to work on the specified projects rather than auto detecting them based on Cargo.toml. This is necessary in some cases when for example cargo is not used as build system as in that case rust-analyzer can't auto-detect the project structure.

I have such issue on Mac, the rust-analyzer fails to work when I open a directory with a bunch of Rust projects.

rust-analyzer works again when I just open a single project.

I know this issue is closed but I wanted to comment here and say that the same thing is happening to me as well on Mac. When I have multiple repos open in a workspace and I add new folders to one repo, r-a "does nothing". Is there a way to point the tool to the repo I want it to focus on?

nmay231 commented 7 months ago

@sweihub @redixhumayun

I had a similar issue just recently. Turns out rust-analyzer.linkedProjects had been set in the local .vscode/settings.json file without my knowledge. Nuking .vscode (you only need to remove .linkedProjects, probably) and restarting rust-analyzer fixed my problem.