rustlings icon indicating copy to clipboard operation
rustlings copied to clipboard

Bug: `rustlings lsp` not working with latest `rust-analyzer` VS Code Extension version.

Open jojobii-arks opened this issue 1 year ago • 5 comments

Issue

On the latest version of the rust-analyzer extension (v0.3.1463), the rust-project.json that is generated from running rustlings lsp is seemingly ignored. IntelliSense, autocomplete, etc., cannot be used despite the rust-project.json being generated and rust-analyzer extension being enabled.

Temporary Solution

Roll back rust-analyzer extension version to v0.3.1451.

How to Replicate

System Details

rust-analyzer VS Code Extension version: v0.3.1463

rustc --version

rustc 1.68.2 (9eb3afe9e 2023-03-27)

rustlings --version

v5.4.1

ls -la

total 20365
drwxr-xr-x 1 josep 197609       0 Apr  4 07:58 ./
drwxr-xr-x 1 josep 197609       0 Apr  2 10:29 ../
-rw-r--r-- 1 josep 197609   53199 Apr  2 10:29 .all-contributorsrc
drwxr-xr-x 1 josep 197609       0 Apr  2 10:29 .devcontainer/
-rw-r--r-- 1 josep 197609     109 Apr  2 10:29 .editorconfig
drwxr-xr-x 1 josep 197609       0 Apr  3 05:56 .git/
drwxr-xr-x 1 josep 197609       0 Apr  2 10:29 .github/
-rw-r--r-- 1 josep 197609     179 Apr  2 10:29 .gitignore
-rw-r--r-- 1 josep 197609     169 Apr  2 10:29 .gitpod.yml
drwxr-xr-x 1 josep 197609       0 Apr  2 10:29 .vscode/
-rw-r--r-- 1 josep 197609   69063 Apr  2 10:29 AUTHORS.md
-rw-r--r-- 1 josep 197609   17152 Apr  2 10:29 Cargo.lock
-rw-r--r-- 1 josep 197609     533 Apr  2 10:29 Cargo.toml
-rw-r--r-- 1 josep 197609   45620 Apr  2 10:29 CHANGELOG.md
-rw-r--r-- 1 josep 197609    4301 Apr  2 10:29 CONTRIBUTING.md
drwxr-xr-x 1 josep 197609       0 Apr  2 10:29 exercises/
-rw-r--r-- 1 josep 197609    1572 Apr  2 10:29 flake.lock
-rw-r--r-- 1 josep 197609    2032 Apr  2 10:29 flake.nix
-rw-r--r-- 1 josep 197609   42700 Apr  2 10:29 info.toml
-rwxr-xr-x 1 josep 197609    3116 Apr  2 10:29 install.ps1*
-rwxr-xr-x 1 josep 197609    4846 Apr  2 10:29 install.sh*
-rw-r--r-- 1 josep 197609    1117 Apr  2 10:29 LICENSE
-rw-r--r-- 1 josep 197609    6667 Apr  2 10:29 README.md
-rw-r--r-- 1 josep 197609    8996 Apr  4 07:56 rust-project.json
-rw-r--r-- 1 josep 197609     284 Apr  2 10:29 shell.nix
drwxr-xr-x 1 josep 197609       0 Apr  2 10:29 src/
drwxr-xr-x 1 josep 197609       0 Apr  2 10:29 target/
-rw-r--r-- 1 josep 197609 2748416 Apr  3 05:55 temp_104912_ThreadId1.pdb
-rw-r--r-- 1 josep 197609 2732032 Apr  2 20:19 temp_106948_ThreadId1.pdb
-rw-r--r-- 1 josep 197609 2748416 Apr  4 07:58 temp_37868_ThreadId1.pdb
-rw-r--r-- 1 josep 197609 2732032 Apr  2 11:49 temp_49388_ThreadId1.pdb
-rw-r--r-- 1 josep 197609 2732032 Apr  2 20:21 temp_54464_ThreadId1.pdb
-rw-r--r-- 1 josep 197609 2732032 Apr  2 20:21 temp_86324_ThreadId1.pdb
-rw-r--r-- 1 josep 197609 2732032 Apr  2 20:21 temp_88736_ThreadId1.pdb
-rw-r--r-- 1 josep 197609 1355776 Apr  2 10:31 temp_99564_ThreadId1.pdb
drwxr-xr-x 1 josep 197609       0 Apr  2 10:29 tests/

OS name and version: Windows 11 Pro, 22H2, Build 22621.1413

this is probably better suited for rust-lang/rust-analyzer but I'm still learning Rust 😓

jojobii-arks avatar Apr 04 '23 15:04 jojobii-arks

I am also having this issue with rust-analyzer v0.3.1472. Downgrading to v0.3.1451 solved the issue for me as well

skycoop avatar Apr 11 '23 01:04 skycoop

I also met this issue, rollback to v1451 can solve this for me on Windows 11, but MACOS VENTURA doesn't have this issue.

kin789246 avatar Apr 19 '23 01:04 kin789246

Well, I'm not the only one having this problem. Can we expect a fix soon?

thespeck avatar Apr 19 '23 07:04 thespeck

It's not an issue on our end, the rust-project.json specification hasn't changed afaik (if it did, it'd break on non-Windows platforms as well). I'm not sure what the rust-analyzer developers' timeline or understanding of this issue is, though.

shadows-withal avatar Apr 19 '23 16:04 shadows-withal

Seems like https://github.com/rust-lang/rust-analyzer/issues/14663 has been posted, backlinking it here to help those in that issue.

shadows-withal avatar Apr 26 '23 19:04 shadows-withal

Found this after banging my head against the wall for a couple of hours thinking that I'm doing something wrong with rust-project.json or the rust-analyzer vscode plugin. Rolling back to v0.3.1451 fixed this for me too. Thank you! ❤️

Lexey40o avatar May 02 '23 20:05 Lexey40o

So I'm looking into this right now, a simple fix for your side would be to make the root_module entries in the generated rust-project.json absolute paths. (digging into why this broke from our side as well though, seems a bit odd)

Okay the cause is that the canonicalization screws with our VFS, unsure what we will do here, so I recommend that your json generator should emit absolute paths for everything for now.

Veykril avatar May 03 '23 13:05 Veykril

@Veykril that sounds like a good workaround for now, many thanks to you and @matklad for debugging this issue :)

shadows-withal avatar May 04 '23 08:05 shadows-withal

Fixed on main in 9508e97, will push a release ~today.

shadows-withal avatar May 17 '23 14:05 shadows-withal

Thanks for the 5.5.0 release @shadows-withal!

Using v0.3.1514 of the rust-analyzer vscode plugin (this latest version is only available on GitHub Releases as of writing) and 5.5.0 of Rustlings the issue appears to still be present.

Here are some details of my system:

Item Value
rustlings --version v5.5.0
rust-analyzer v0.3.1514
rustc --version rustc 1.69.0 (84c898d65 2023-04-16)
Operating System Windows 10 Home, version 22H2, build 19045.2965

After running rustlings lsp I can see that the root_module path values in rust-project.json are absolute. Here's one for example:

"\\\\?\\C:\\Users\\<user>\\source\\repos\\rustlings\\exercises\\vecs\\vecs2.rs"

It's a little unexpected because I thought this rust-analyzer fix would've solved it if the 5.5.0 rustlings release didn't.

Lexey40o avatar May 17 '23 18:05 Lexey40o

@Lexey40o Weird! I'll pass it on.

shadows-withal avatar May 17 '23 18:05 shadows-withal

Ah, the problem is the UNC path I believe (the \\\\?\\ prefix). Our VFS will have a non UNC path indexed so it won't be able to resolve this properly. I assume you are using rust's path canonicalize function somewhere to get the absolute path which unfortunately returns UNC paths on windows ... That said, and I am sorry for not having brought that up here again afterwards but relative paths should just work again. We effectively ended up reverting the changes and took a stance for the current behavior now (as before we weren't sure which one we really wanted to stick with).

There is no decent way for us to handle different paths pointing to the same thing here unfortunately, s owe can't really do anything about unc paths and just opt to not support them currently.

Veykril avatar May 17 '23 18:05 Veykril

@Veykril gotcha!

Reverted back to rustlings 5.4.1 and its rustlings lsp generation is working with rust-analyzer v0.3.1514.

Lexey40o avatar May 17 '23 18:05 Lexey40o

That said, and I am sorry for not having brought that up here again afterwards but relative paths should just work again.

Ah okay, that's fine, I'll revert that change and push a patch version. Thanks for letting us know!

shadows-withal avatar May 17 '23 19:05 shadows-withal

@Lexey40o could you confirm it works again with Rustlings 5.5.1?

shadows-withal avatar May 17 '23 19:05 shadows-withal

@shadows-withal it sure is! Reran rustlings lsp with rustlings 5.5.1 and it's generating relative paths again, which looks to be working with rust-analyzer v0.3.1514. Thanks for the patch! 🎉

Lexey40o avatar May 17 '23 19:05 Lexey40o

Perfect, closing it for real now

shadows-withal avatar May 17 '23 19:05 shadows-withal

rustlings lsp work for me in rustlings 5.5.1 and 5.4.1. It is problem about rust-analyzer. I have change rust-analyzer v0.3.1506 to rust-analyzer v0.4.1522 Pre-Release, it is work!

jiangyixin2001 avatar May 21 '23 11:05 jiangyixin2001

Hi all,

Trying rustlings out and this bug is happening to me in 5.6.1.

Relevant information: OS: Ubuntu 22.04 rustlings: 5.6.1 rustc --version: rustc 1.74.0 (79e9716c9 2023-11-13) rust-analyzer extension: Bug in both

  • v0.3.1748
  • v0.4.1753 (pre-release)

Steps to replicate:

  • Install rustlings
  • Run rustlings lsp
  • In VS Code attempt command pallet command rust-analyzer: Restart server (no change)
  • Restart VS Code (no change)

Any other steps anyone can think of?

addisonjones3 avatar Dec 02 '23 15:12 addisonjones3