Skip to content

fix: Limit depth to 1 when searching for Cargo.toml #10442

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

Merged
merged 1 commit into from
Oct 3, 2021

Conversation

lnicola
Copy link
Member

@lnicola lnicola commented Oct 3, 2021

...and add rust-project.json.

More or less fixes #7268

@lnicola
Copy link
Member Author

lnicola commented Oct 3, 2021

r? @matklad

@lnicola
Copy link
Member Author

lnicola commented Oct 3, 2021

As proposed by @heaths in #7268 (comment). This might still be too slow on HDDs and cold caches, but I don't think we can do much more.

@lnicola lnicola changed the title Limit depth to 3 when searching for Cargo.toml fix: Limit depth to 3 when searching for Cargo.toml Oct 3, 2021
@matklad
Copy link
Member

matklad commented Oct 3, 2021

@lnicola
Copy link
Member Author

lnicola commented Oct 3, 2021

That makes sense, updated. For some reason, */Cargo.toml works for both Cargo.toml in the project root and in a subdirectory (but not two levels deep).

@matklad
Copy link
Member

matklad commented Oct 3, 2021

bors r+

Excellent find by the way!

bors bot added a commit that referenced this pull request Oct 3, 2021
10442: fix: Limit depth to 3 when searching for `Cargo.toml` r=matklad a=lnicola

...and add `rust-project.json`.

More or less fixes #7268

Co-authored-by: Laurențiu Nicola <[email protected]>
@lnicola lnicola changed the title fix: Limit depth to 3 when searching for Cargo.toml fix: Limit depth to 1 when searching for Cargo.toml Oct 3, 2021
@bors
Copy link
Contributor

bors bot commented Oct 3, 2021

Canceled.

@lnicola
Copy link
Member Author

lnicola commented Oct 3, 2021

bors r=matklad

@bors
Copy link
Contributor

bors bot commented Oct 3, 2021

@bors bors bot merged commit 4b7675f into rust-lang:master Oct 3, 2021
@lnicola lnicola deleted the max-depth branch October 3, 2021 15:06
@CalebEverett
Copy link

CalebEverett commented Oct 7, 2021

How can I get rust-analyzer to discover my workspace if Cargo.toml is deeper than one level? I also have multiple Cargo.toml files in the workspace.

Version: 1.61.0-insider (user setup)
Commit: 2dc8b9580809148e312356852affc4b8d4feb7da
Date: 2021-10-06T08:22:53.147Z
Electron: 13.5.1
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.22471

@lnicola
Copy link
Member Author

lnicola commented Oct 10, 2021

@CalebEverett I suppose it depends. Can you use a Code workspace, or even open separate windows for the Rust and non-Rust parts of your project?

@CalebEverett
Copy link

CalebEverett commented Oct 10, 2021

@CalebEverett I suppose it depends. Can you use a Code workspace, or even open separate windows for the Rust and non-Rust parts of your project?

Hi, thanks. Adding a Cargo.toml to the top level with just the workspace key in it with entries for the other crates worked.

[workspace]
members = [
    "src/cli-rust",
    "src/program-rust",
]

@lnicola
Copy link
Member Author

lnicola commented Oct 10, 2021

Yeah, if both are Cargo projects then a Cargo workspace is totally the way to go.

@akutruff
Copy link

So I just hit this, and it's not an option to move Cargo.toml to the top of my directory structure. Is there a setting? I don't understand why this is so rigid.

@matklad
Copy link
Member

matklad commented Jun 23, 2022

rust-analyzer.linkedProjects (default: [])
Disable project auto-discovery in favor of explicitly specified set of projects.

Elements must be paths pointing to Cargo.toml, rust-project.json, or JSON objects in rust-project.json format.

bors added a commit that referenced this pull request Feb 13, 2024
…go-toml, r=Veykril

Activate on top level `Cargo.toml` and `rust-project.json` files

I believe there is an issue with how rust-analyzer is activated from within a VS Code project.

IIUC, the intent is that when you open a rust project with a top level `Cargo.toml`, then rust-analyzer should just start right up due to a VS Code activation event. This is not currently the case. i.e. run something like `cargo new ~/Desktop/hithere`, then open that folder in VS Code:

https://github.com/rust-lang/rust-analyzer/assets/19150088/1608b985-fd88-4174-a22a-5b3dd0fad84b

It is not until you actually open a Rust file that the extension starts up.

It looks like this was introduced in #10442. I do agree that recursive searching with `**/` is likely overkill, but I'm not sure `*/Cargo.toml` is working as expected in this comment (#10442 (comment)):

> For some reason, */Cargo.toml works for both Cargo.toml in the project root and in a subdirectory (but not two levels deep).

That does not seem to be the case for me. I even went into VS Code itself and added some fake tests for `glob.match()` (which is eventually what gets used for this) and `*/Cargo.toml` doesn't seem to match a top level `Cargo.toml` (and I think that makes sense).

<img width="1087" alt="Screenshot 2024-02-12 at 6 07 08 PM" src="https://github.com/rust-lang/rust-analyzer/assets/19150088/510b0aaa-ac66-48b1-a9e2-a3bdfc237c48">

Lastly, the VS Code search filtering uses the same glob patterns, and it also doesn't match with `*/Cargo.toml`:

https://github.com/rust-lang/rust-analyzer/assets/19150088/4973f5e7-270d-489a-8db4-37469ffe12df

---

If you want both top level `Cargo.toml`s and 1-level-deep `Cargo.toml`s to be detected by VS Code's activation events, then I think we need to lay both of those conditions out explicitly, which I've done in this PR. That does fix the problem for me.

https://github.com/rust-lang/rust-analyzer/assets/19150088/bfcb1223-c45c-479a-9ea4-4be3f36e6838
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[code] rust-analyzer failed to discover workspace
4 participants