Rust Analyzer Warning in VS Code for Non-Rust Projects
Dear Support Team,
I am writing to report a persistent issue I am facing with Rust Analyzer in Visual Studio Code (VS Code). Whenever I open a non-Rust project in VS Code, I consistently receive the following warning:
This warning message appears every time I work on a project that is unrelated to Rust development. Although I understand that Rust Analyzer primarily caters to Rust projects, the constant recurrence of this warning for non-Rust projects is highly disruptive and hinders my workflow significantly.
While I understand that Rust Analyzer is primarily designed for Rust projects, the presence of this warning for non-Rust projects can be bothersome. If other language servers were to adopt a similar behavior and display warnings for unsupported languages, it would greatly impede productivity and make working on different projects frustrating.
I kindly request your assistance in resolving this matter promptly. It would be greatly appreciated if you could provide guidance on how to disable or suppress this warning specifically for non-Rust projects in VS Code. By doing so, we can create a more seamless and efficient development environment, allowing users to work without unnecessary interruptions.
Should you require any additional information or clarification from my end, please do not hesitate to let me know. I eagerly await your response and appreciate your attention to this matter.
Thank you for your understanding and support.
Sincerely, Aamir
rust-analyzer is not supposed to start unless you have a Rust file, one called Cargo.toml or rust-project.json: https://github.com/rust-lang/rust-analyzer/blob/master/editors/code/package.json#L66.
Can you check you don't have any of these in your project? And also if it happens somewhere else, like in a directory with just one or two files that's not under D:\Projects.
I have same trouble. I've created empty dir with only package.json:
> ls -all
total 8
drwxr-xr-x 3 me staff 96 3 июл 16:56 .
drwxr-xr-x 42 me staff 1344 3 июл 16:55 ..
-rw-r--r-- 1 me staff 199 3 июл 16:56 package.json
And rust-analyzer trying to start. I'm on MacOS Ventura 13.3.1 (a).
Bug reproducing on both rust-analyzer v0.4.1574 and rust-analyzer v0.3.1575
That doesn't reproduce for me on windows. Can you check with all your extension but rust-analyzer disabled?
Yep, when I disable all extensions, rust-analyzer begin to work correctly. Hoing to turn on one by one and search which one will cause problem.
And I found a cause - this extension. @aamironline do you use this ext too? UPD it seems, another similar extension also affects this.
relevant marketplace link: https://marketplace.visualstudio.com/items?itemName=actboy168.tasks
This happens when I trigger my run task by pressing ctrl+alt+enter (but only when doing this). I looked at the default key bindings and there's no reason why it should. I have none of the extensions mentioned installed.
Some extension of yours most likely queries the all your extensions' tasks which triggers the task activation event for all of them, there is no much we can do about that as VSCode is the one sending rust-analyzer the activation event due to that.
I'm on macOS 14.5 and rust-analyzer constantly starts up with an error in my swift projects.
Confirm happening for me on Linux (Fedora 40) when running with code . or code-insiders . in non-Rust project (empty folder).
The only way I can disable is to disable rust-analyzer for each workspace that is not a Rust project. This isn't a workable solution. The other way around would be to disable rust-analyzer globally and then manually enable it manually per Rust workspace. That's equally unworkable.
I thought it might be this option in settings.json:
"rust-analyzer.linkedProjects": [
"./Cargo.toml",
],
However, commenting that out and restarting VS Code did not work.
In fact, I have the following settings also:
"rust-analyzer.numThreads": 10,
"rust-analyzer.completion.autoimport.enable": true,
"rust-analyzer.check.command": "clippy",
Commented out all of them and restarted. No effect, still get the red box with error (test is an empty folder):
2024-08-06T00:40:59.895882Z ERROR failed to find any projects in [AbsPathBuf("/home/tom/test")]
2024-08-06T00:40:59.897988Z ERROR FetchWorkspaceError:
rust-analyzer failed to discover workspace
I have the same problem within a swift project.
Did a few window reload commands, but rust-analyzer tried activating each time. Then I fully closed the window and reopened from command line: code <path-to-project>, and now the activation of the rust-analyzer was gone.
rust-analyzer is starting for any project anytime I create or modify a new file. My guess is it's configured to look for Rust files all the time and is incorrectly announcing itself when it can't find anything.
This is what I see in the output:
2024-08-10T19:37:45.855081Z ERROR failed to find any projects in [AbsPathBuf("/home/xxx/any-project")]
2024-08-10T19:37:45.856997Z ERROR FetchWorkspaceError:
rust-analyzer failed to discover workspace
My only recourse has been to disable the extension for each and every non-Rust workspace. Not great.
r-a starts when the client tells it to, if you have VSCode and r-a starts up without any rust files (or Cargo.tomls/locks) present it is likely another extension of yours starting it by querying all task kinds.
@Veykril You're 100% right - the issue is not with r-a but with the 'Trigger Task on Save' extension - thanks for pointing me in the right direction. My apologies to the devs for the shade!
i don't have that extension yet i have this problem?
I'd just disabled all my extensions except for r-a to first confirm that r-a is not running for non-Rust projects. In my case it's not. Then I re-enabled each extension until I saw the behavior. My test consisted of a single markdown file that, when edited and saved, triggered the Rust analyzer.
The material issue here may be that r-a is too vocal about the rust-analyzer failed to discover workspace outcome. It's certainly not worthy of an ERROR level log. Useful for debugging perhaps but the noise is causing people to spend a lot of cycles here.
That seems rather odd given our activation events being :
"activationEvents": [
"workspaceContains:Cargo.toml",
"workspaceContains:*/Cargo.toml",
"workspaceContains:rust-project.json",
"workspaceContains:*/rust-project.json",
"workspaceContains:.rust-project.json",
"workspaceContains:*/.rust-project.json"
],
We will remove the big warning once we have lazy project discovery, but before that I am opposed to removing it as people tend to get even more confused when r-a does not pick up their project and the user not realizing that wondering why they don't get any features. (there is a reason why its so in the face right now)
@gar1t mind sharing what extension it was?
EDIT: nvm, you've already mentioned it.
@gar1t for me it seems like the swift extension indirectly triggers rust analyzer when it creates a .vscode/launch.json for a lldb debug session, that launch file seems to be automatically created and so rust analyzer just spawns in whenever the swift extension activates 🤷
@Veykril This is the only extension I've run into that makes this sort of nonsensical announcement ("ERROR ERROR - nothing to see here!"). It caused me to uninstall it months ago as it kept flashing a red message for all my non-Rust projects. I didn't understand why and it was easier for me that the time to just remove it.
I took time yesterday to create a new project, run extension bisect, and then run a sequential check to find the cause of the extension start. This is all actual time and effort I spent to ensure that my development experience isn't flashing pointless red errors for my non-Rust projects.
I'd weigh this dynamic against the occasions that r-a fails to load and confuses users.
Thankfully this thread at least gives users a heads-up so they can take the time to track down the extension that triggers this r-a behavior.
Hello guys,
This extension also creates an issue for me : https://github.com/actboy168/vscode-tasks
Wait for an optimal solution.
Curious to know if there is a work around for this.
Can you do workspaceContains check again on activation and decide whether to show the warning color?
On my machine, debugging (simply press F5) with vscode-cpptools (currently v1.22.11) will trigger rust-analyzer too.
Only those two extensions are enabled. I have tried removing settings.json and tasks.json but that doesn't work.
I think my problem is that I use a workspace with multiple subprojects. Some of these subprojects have rust, some do not. And this is causing a problem as it appears this extension was built with the assumption that the workspace itself was a single project.
The ERROR marker is definitely useful as it's easy (especially for new users) to open the incorrect directory (say one above the one containing the Cargo.toml) then wonder why rust-analyzer doesn't work for them.
I believe the marker is more important than supporting external extensions that activate rust-analyzer when they shouldn't. @rust-lang/rust-analyzer thoughts?
We can provide an (off-by-default) setting to disable that marker though.