Rust-analyzer trying to parse .toml files as .rs inside VSCode

Hi. Sorry if this is off-topic b/c it's not a Rust question. I'm at my wit's end with this.

Inside VSCode, rust-analyzer is trying to interpret some of my .toml files as .rs files. And, as you'd expect, finding hundreds of syntax errors in every .toml file. cargo from the command line does everything as I would expect and shows no errors when building the project.

cargo check --workspace --all-targets also shows no errors whatsoever.

You'd think the internet would have a lot to say about such a fundamental issue, but I've found absolutely nothing relevant. That's why I'm here.

This started when I migrated from the old "Rust" VSCode extension to the "rust-analyzer" extension. I lived with it for a few months thinking a newer version of something would fix it. But after 6 months it's getting really frustrating.

I've reinstalled vscode. Reinstalled rust-analyzer, deleted just about every preference and config I know about.

My versions are:

rustup -V                                        
rustup 1.25.2 (fae52a197 2023-02-01)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.67.1 (d5a82bbd2 2023-02-07)`

cargo -V    
cargo 1.67.1 (8ecd4f20a 2023-01-10)
rust-analyzer
v0.3.1394
Version: 1.75.1 (Universal)
Commit: 441438abd1ac652551dbe4d408dfcec8a499b8bf
Date: 2023-02-08T21:34:59.000Z
Electron: 19.1.9
Chromium: 102.0.5005.194
Node.js: 16.14.2
V8: 10.2.154.23-electron.0
OS: Darwin x64 21.6.0
Sandboxed: No

Another clue is that the one .toml file that it isn't complaining about is the workspace toml. That looks like this:

[workspace]
resolver = "2"
default-members = ["projectd"]
members = [
    #Main
    "projectd",

    #Sub-Crates
    "subs/evidence_store",
    "subs/connection_doorguy",
    "subs/project_common",
]

Does anyone have an inkling where to look next? Thanks for any suggestions.

This seems really strange. Have you accidentally told VS Code that *.toml files are Rust, by sny chance?

You can check by looking at the language identifier in the bottom-right corner of the screen. This can be changed by clicking the "TOML" (or whatever else is there) and going through the file association prompt.

1 Like

Well... It does think they're "Rust".

Unfortunately, when I tell them they're "toml". (I didn't have "TOML" as an option) using "configure file association for '.toml'..." I lose syntax highlighting, but rust-analyzer still throws all the same syntax errors. :frowning:

I then installed the "Even Better TOML" VSCode extension, and now my editor looks like yours. But unfortunately rust-analyzer is still finding syntax errors on every single line. :frowning:

Thanks for the ideas though.

I think the answer was:

rm -rf ~/.cargo
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

:stuck_out_tongue:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.