rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Rust Analyzer Warning in VS Code for Non-Rust Projects

Open aamironline opened this issue 2 years ago • 23 comments

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:

image

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

aamironline avatar Jun 17 '23 04:06 aamironline

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.

lnicola avatar Jun 17 '23 04:06 lnicola

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

bromzh avatar Jul 03 '23 13:07 bromzh

That doesn't reproduce for me on windows. Can you check with all your extension but rust-analyzer disabled?

Veykril avatar Jul 03 '23 13:07 Veykril

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.

bromzh avatar Jul 03 '23 15:07 bromzh

And I found a cause - this extension. @aamironline do you use this ext too? UPD it seems, another similar extension also affects this.

bromzh avatar Jul 03 '23 15:07 bromzh

relevant marketplace link: https://marketplace.visualstudio.com/items?itemName=actboy168.tasks

Veykril avatar Jul 03 '23 15:07 Veykril

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.

bn-l avatar Dec 11 '23 02:12 bn-l

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.

Veykril avatar Dec 11 '23 09:12 Veykril

I'm on macOS 14.5 and rust-analyzer constantly starts up with an error in my swift projects.

Screenshot 2024-07-01 at 19 00 25

ghost avatar Jul 01 '24 17:07 ghost

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

tgrushka avatar Aug 06 '24 00:08 tgrushka

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.

koliyo avatar Aug 10 '24 10:08 koliyo

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.

gar1t avatar Aug 10 '24 19:08 gar1t

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 avatar Aug 11 '24 05:08 Veykril

@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!

gar1t avatar Aug 11 '24 13:08 gar1t

i don't have that extension yet i have this problem?

ghost avatar Aug 11 '24 14:08 ghost

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.

gar1t avatar Aug 12 '24 11:08 gar1t

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)

Veykril avatar Aug 12 '24 11:08 Veykril

@gar1t mind sharing what extension it was?

EDIT: nvm, you've already mentioned it.

lnicola avatar Aug 12 '24 11:08 lnicola

@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 🤷

ghost avatar Aug 12 '24 12:08 ghost

Screenshot 2024-08-12 at 14 10 45

ghost avatar Aug 12 '24 12:08 ghost

@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.

gar1t avatar Aug 12 '24 12:08 gar1t

Hello guys,

This extension also creates an issue for me : https://github.com/actboy168/vscode-tasks

Adham-A avatar Sep 09 '24 17:09 Adham-A

Wait for an optimal solution.

wangrongding avatar Oct 11 '24 08:10 wangrongding

Curious to know if there is a work around for this.

jwmurray avatar Nov 08 '24 21:11 jwmurray

Can you do workspaceContains check again on activation and decide whether to show the warning color?

xgdgsc avatar Dec 01 '24 02:12 xgdgsc

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.

Henry-ZHR avatar Dec 02 '24 12:12 Henry-ZHR

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.

CMCDragonkai avatar Mar 04 '25 23:03 CMCDragonkai

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.

ChayimFriedman2 avatar Aug 28 '25 18:08 ChayimFriedman2