Skip to content
New issue

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

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

Already on GitHub? # to your account

Rust-analyzer does not function with non-root Cargo.toml #1798

Closed
LDSpits opened this issue Sep 9, 2019 · 10 comments
Closed

Rust-analyzer does not function with non-root Cargo.toml #1798

LDSpits opened this issue Sep 9, 2019 · 10 comments

Comments

@LDSpits
Copy link
Contributor

LDSpits commented Sep 9, 2019

Most of the code in the vscode extension seems to assume that the cargo.toml is located in the workspace root. And that there is one cargo.toml (or project) available.

Currently, when you try to use rust-analyzer with a cargo.toml not in the root the following error message get's shown [ra_lsp_server::main_loop] loading workspace failed: can't find Cargo.toml

@LDSpits
Copy link
Contributor Author

LDSpits commented Sep 10, 2019

One of the ways that I can think of how to resolve this is to use vscode.workspace.findFiles() to locate the cargo.toml, after that we can use the directory the cargo.toml is located in to specify the current working directory for both the CargoWatchProvider and the language server.

@xedrac
Copy link

xedrac commented Oct 25, 2019

Is there a way to point rust analyzer to the Cargo.toml file(s) of interest? I've got a C++/CMake project with some Rust parts which are built with Cargo (invoked by CMake). Currently rust analyzer doesn't work when I load the entire source tree. It seems to assume the entire project is written in Rust.

@matklad
Copy link
Member

matklad commented Nov 24, 2019

I am unlikely to have time to look into this in the nearest future, but I can leave a couple of pointers to the code where this should be handled:

I think we need some kind of additional_roots: [PathBuf] setting, which is just added to this list.

@xedrac
Copy link

xedrac commented Nov 25, 2019

@matklad Thanks for pointing out the code of interest. If I can find a bit of time I may attempt to implement your additional_roots idea.

@JP-Ellis
Copy link

Might it be worth considering what rust-lang.rust have done with rust-client.enableMultiProjectSetup?

In my case, I have a workspace with multiple rust projects, and although I get the correct code completions in each project, I don't get any warnings/errors being raised.

@Luminoth
Copy link

I'd just like to note that, with the RFC up now to transition RA to be the official Rust LSP, this issue is the single blocking issue for me and all of my coworkers looking to make the switch. It unfortunately makes RA completely unusable in all of our projects so we can't even begin to consider the transition to help with reporting issues until this is fixed.

@edwin0cheng
Copy link
Member

cc #2649

@matklad
Copy link
Member

matklad commented Jun 8, 2020

This is now possible by using an explicit config. Doing dynamic auto-discovery is on the TODO list, and should be implemented soon:

#2649 (comment)

@matklad matklad closed this as completed Jun 8, 2020
@serovar
Copy link

serovar commented Dec 1, 2020

Any news about the dynamic auto-discovery?

@matklad
Copy link
Member

matklad commented Dec 2, 2020

static config seem to work great so far, so there are no longer immediate plans for doing auto-discovery. As usual, PRs are welcome, but this is a challenging task.

A nice intermediate goal would be to show a warning if a project is not configured propelly, with an auto-fix which sets up workspace config.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants