| Summary: | rust-analyzer language server hits error condition while starting, "failed to find any projects" (LSP plugin) | ||
|---|---|---|---|
| Product: | [Applications] kate | Reporter: | Adam Fontenot <adam.m.fontenot+kde> |
| Component: | general | Assignee: | KWrite Developers <kwrite-bugs-null> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | waqar.17a |
| Priority: | NOR | ||
| Version First Reported In: | 24.08.0 | ||
| Target Milestone: | --- | ||
| Platform: | Arch Linux | ||
| OS: | Linux | ||
| Latest Commit: | https://invent.kde.org/utilities/kate/-/commit/8a790b3b895624fca4848fe308753ab22dd46e61 | Version Fixed/Implemented In: | |
| Sentry Crash Report: | |||
You can ignore that error, rust-analyzer continues to work correctly despite what it says.
> The error suggests that rust-analyzer is looking for my projects in my home directory. That's obviously inappropriate, as I specifically loaded the project I wanted to look at in Kate, so Kate should set the project directory (as seen by rust-analyzer) to that directory.
If we do it, then Kate will open a server for every new root it finds, which is a disaster. If you want to do it, change your lsp settings and specify the following for rust-analyzer:
"rootIndicationFileNames": ["Cargo.lock", "Cargo.toml"],
I would suggest taking this up with rust-analyzer, it should be able to discover the root on its own (and it does).
(In reply to Waqar Ahmed from comment #1) > You can ignore that error, rust-analyzer continues to work correctly despite > what it says. If the error is expected, could the plugin be configured to accept this specific error response when starting the server? My issue isn't about the message in the LSP output, it's that it forces open the Output tab (and flashes the tab at you) because it thinks there's some serious problem you need to deal with. I think fixing that would be a good QoL improvement. > If we do it, then Kate will open a server for every new root it finds, which > is a disaster. If you want to do it, change your lsp settings and specify > the following for rust-analyzer: > > "rootIndicationFileNames": ["Cargo.lock", "Cargo.toml"], I don't immediately see why this is so bad: is the idea that if I open multiple projects in a single Kate session, one rust-analyzer instance should be sufficient to handle all of them as if they were one big project? Does rust-analyzer's "project awareness" have any benefits that we're forgoing by doing it this way? > I would suggest taking this up with rust-analyzer, it should be able to > discover the root on its own (and it does). I will file a bug on that end too and see what they make of it, thanks! You don't have to open multiple projects in an actual sense. I mean, you are working on your project and you jump to a definition in a crate or std library. This will start a new server because there is a new root. This is annoying in multiple ways and leads to excessive resource usage quickly.
Another possible way to fix this might be to specify `root` and `userWorkspace` in the lsp settings:
```
"command": ["rust-analyzer"],
"path": ["%{ENV:CARGO_HOME}/bin", "%{ENV:HOME}/.cargo/bin", "%{ENV:USERPROFILE}/.cargo/bin"],
"url": "https://rust-analyzer.github.io",
"highlightingModeRegex": "^Rust$",
"root": "", // this
"useWorkspace": true, // and this
```
IIRC, this tries to use the open project's root. Project here means kate's project in the sidebar.
(In reply to Waqar Ahmed from comment #3) > Another possible way to fix this might be to specify `root` and > `userWorkspace` in the lsp settings: Thanks for the hints! I found that the following combination of settings gives the correct behavior: "useWorkspace": true, "rootIndicationFileNames": ["Cargo.lock", "Cargo.toml"], If you have both of these, rust-analyzer ✅ Automatically detects the correct project when you open a Rust file ✅ Does *not* open a new rust-analyzer instance when I select "go to definition" on an external symbol. If you can verify this behavior and can check that this doesn't have any weird side effects, we could consider making these options part of the Rust defaults? Yeah, I think we can make this the default. Ultimately the users of a language server have to decide what's the best possible default. Also, we have a lot of time to test this before the next release. A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1592 Git commit 8a790b3b895624fca4848fe308753ab22dd46e61 by Waqar Ahmed. Committed on 26/09/2024 at 16:37. Pushed by waqar into branch 'master'. Update dart & rust lsp settings We need rootIndicationFileNames for both these servers so that a rootPath is sent to the server correctly. The servers fail to do this job themselves even though they shouldn't. Besides that, we must set useWorkspace=true so that a new server isn't spawned for every new project root. M +4 -3 addons/lspclient/settings.json https://invent.kde.org/utilities/kate/-/commit/8a790b3b895624fca4848fe308753ab22dd46e61 |
SUMMARY When I open a project in Kate (e.g. a project with a Git history that Kate shows in the "open recent" box when you start it), and click on a Rust code file, rust-analyzer is automatically started. Every time it does this, it shows an error, forcing open the "Output" tab. The error suggests that rust-analyzer is looking for my projects in my home directory. That's obviously inappropriate, as I specifically loaded the project I wanted to look at in Kate, so Kate should set the project directory (as seen by rust-analyzer) to that directory. The help text gives some additional information about hardcoding your projects with `linkedProjects`, but that's obviously not appropriate here. Kate version is 24.08.0 (built myself, same issue with 24.05.2 distribution package). rust-analyzer 20240819 STEPS TO REPRODUCE 1. Open a Rust source file in a project. OBSERVED RESULT The following text gets printed to Output: [22:49:14 LSP Client Log] Started server rust@/home/adam: /usr/bin/rust-analyzer [22:49:14 LSP Server Log] rust@/home/adam 2024-08-23T02:49:14.728559Z ERROR failed to find any projects in [AbsPathBuf("/home/adam")] [22:49:14 LSP Server Warning] rust@/home/adam Failed to discover workspace. Consider adding the `Cargo.toml` of the workspace to the [`linkedProjects`](https://rust-analyzer.github.io/manual.html#rust-analyzer.linkedProjects) setting. [22:49:15 LSP Server Info] Fetching [22:49:14 LSP Server Error] rust@/home/adam Failed to load workspaces. EXPECTED RESULT No error, loads correctly. SOFTWARE/OS VERSIONS Operating System: Arch Linux KDE Plasma Version: 6.1.4 KDE Frameworks Version: 6.5.0 Qt Version: 6.7.2 Kernel Version: 6.10.5-arch1-1 (64-bit) Graphics Platform: Wayland