rust-lang / rust-analyzer

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

rust-analyzer on vscode doesn't work #13646

Closed FischLu closed 2 years ago

FischLu commented 2 years ago

OS: Macos CPU: M1 Max Rustc version: rustc 1.65.0 (897e37553 2022-11-02) Cargo version: cargo 1.65.0 (4bc8f24d3 2022-10-20) rust-analyzer version: 0.3.1285-standalone (45ec315e0 2022-11-11) Vscode version: 1.73.1

I have install the rust-analyzer on vscode and use cargo new hello to create a simple workplace, in the hello directory, I run the command code . and Vscode launches but rust-analyzer doesn't do anything inlucding intellisense, code completion etc. But there is NO error message at the bottom tool bar for rust-analyzer.

image

Besides, I have another M1 Macbook air, which has no problem for rust-analyzer, I double checked many times of the configuration between two computers, I didn't see any thing weird.

I searched the issue list in Github and I see the similar one is #12547, I tried to follow the discussion till analysis-stats outputs, in the hello folder I have run the following commands

cargo metadata
~/.vscode/extensions/rust-lang.rust-analyzer-0.3.1285-darwin-arm64/server/rust-analyzer analysis-stats .

the outputs are

Database loaded:     75.09ms (metadata 45.43ms; build 125.00ns)
  crates: 0, mods: 0, decls: 0, fns: 0
Item Collection:     1.61s
  exprs: 0, ??ty: 0 (100%), ?ty: 0 (100%), !ty: 0
Inference:           26.25µs
Total:               1.61s

The Cargo.lock contents

# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "hello"
version = "0.1.0"

The Cargo.toml contents

[package]
name = "hello"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

However on the Macbook air (the correct working one), the commands outputs are

Database loaded:     1.28s (metadata 655.30ms; build 464.95ms)
  crates: 1, mods: 1, decls: 1, fns: 1
Item Collection:     1.57s
  exprs: 10, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
Inference:           809.08ms
Total:               2.38s

It's very strange that in the problematic one, the crates are not detected by rust-analyzer, because of the following line

crates: 0, mods: 0, decls: 0, fns: 0

I have reinstalled the extension (uninstall it from Vscode extension page and delete the ~/.vscode/extensions/rust-lang.rust-analyzer-0.3.1285-darwin-arm64 folder), reinstall the rust itself via rustup self uninstall but doesn't solve the problem.

Because my projects located in ~/Work/Rust/, the path was ~/work/rust/, I changed the first letter to capital letter, I think this should not be a problem, Macos is case-insensitive, even it doesn't, the hello project is just a new created project under new path name, so I have totally no idea... anyone can help? Thanks!

FischLu commented 2 years ago

I fixed the issue by deleting all files from ~/Library/Caches although I don't know why, strange...