Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust-analyzer does not always find cargo.toml in Yarn Monorepo #13688

Closed
ghost opened this issue Nov 28, 2022 · 3 comments
Closed

Rust-analyzer does not always find cargo.toml in Yarn Monorepo #13688

ghost opened this issue Nov 28, 2022 · 3 comments
Labels
C-support Category: support questions

Comments

@ghost
Copy link

ghost commented Nov 28, 2022

I have addressed the issue, but I became aware of the following behavior.

In a yarn monorepo with doom-emacs editor (LSP and such installed properly) I open main.rs in the following directory structure

.git/
package.json
packages/
  an-unrelated-package/
    <contents not relevant>
apps/
  an-unrelated-js-app/
    <contents not relevant>
  an-example-rust-application/
    Cargo.toml
    src/
      main.rs

In this the rust-analyzer LSP provided me the following error: LSP :: rust-analyzer failed to discover workspace

It is possible to force it to identify the workspace. However I am unaware of exact ways to force it to reliably find the workspace without human intervention.


Workaround:

When opening the file or maybe files at that directory level for the first time, I am prompted by the following interactive message.

main.rs is not part of any project

i ==> import project root path/to/the/root/directory/of/the/git/repo/
I ==> import the project interactively
. ==> import the project at the current directory /apps/an-example-rust-application/src
d ==> do not ask again for the current project by adding /path/to/the/git/repo to lsp-session-folder blacklist
D ==> do not ask again by asking the ignore path interactively
n ==> Do nothing: ask again when opening other files from this project

In the first launch only you can use I to correct this. Otherwise move the thing and you'll have another shot. Given that it can save the directory somewhere there is a way somehow to remove that state without moving the directory, but I am not a nerd and cannot tell you.

Perhaps its naiive, but it seems strange that it cannot find this specific instance of Cargo.toml. It is exactly where it would expect it to be relative to the files. It is only abnormal in its relationship to the .git repo.


Here is a minimally reproducible repo for the interested. Its also quite likely that this is related to the stack and not the tool individually (rustic + doom emacs + LSP-mode + rust-analyzer). Given this I have a few open questions.

  1. Where is state saved for rust-analyzer? Is it saved? and where are configuration values read from?
  2. How would I go about making it so it rust-analyzer looks recursively upwards for the Cargo.toml and if such a solution was implemented would y'all have interest in the contribution?
@Veykril
Copy link
Member

Veykril commented Nov 28, 2022

r-a saves no state currently. Config files are dependent on the language client you are using. r-a currently only looks at the root folder and the first children for Cargo.toml files, see #13226. The reason for that is performance, as we do not want to currently scan the entire folder hierarchy for projects.

@flodiebold flodiebold added the C-support Category: support questions label Dec 4, 2022
@ghost
Copy link
Author

ghost commented Dec 14, 2022

Workaround is in issue body. I'm comfortable with this being closed with a "won't do." A good reason for not doing anything is provided by @Veykril. This 'issue' can be further acted on within the language servers I use and isn't within the context of this project.

@flodiebold flodiebold closed this as not planned Won't fix, can't repro, duplicate, stale Dec 14, 2022
@Martin-Narvar
Copy link

I found this issue because I was getting errors from Rust Analyzer about not being able to find Cargo.toml in my monorepo.

In my case the answer was to configure workspaces. After setting this up the analyzer worked as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

3 participants