]> git.lizzy.rs Git - rust.git/commit
Merge #3309
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Sat, 29 Feb 2020 15:36:03 +0000 (15:36 +0000)
committerGitHub <noreply@github.com>
Sat, 29 Feb 2020 15:36:03 +0000 (15:36 +0000)
commit099a8f37f5fd41f7afe26039b063973617133153
tree1ee876766ad8be3b7dedefbe781f856b0cca63bd
parent0ae7054210b0bbc48ea51c3672be640d3096cfdd
parentb9fbb3da1740ddef0ab5d9dcbb75e50b92ba0c09
Merge #3309

3309: Find cargo toml up the fs r=matklad a=not-much-io

Currently rust-analyzer will look for Cargo.toml in the root of the project and if failing that then go down the filesystem until root.

This unfortunately wouldn't work automatically with (what I imagine is) a fairly common project structure. As an example with multiple languages like:
```
js/
  ..
rust/
  Cargo.toml
  ...
```

Added this small change so rust-analyzer would glance one level up if not found in root or down the filesystem.

## Why not go deeper?

Could be problematic with large project vendored dependencies etc.

## Why not add a Cargo.toml manual setting option?

Loosely related and a good idea, however the convenience of having this automated also is hard to pass up.

## Testing?

Build a binary with various logs and checked it in a project with such a structure:

```
[ERROR ra_project_model] find_cargo_toml()
[ERROR ra_project_model] find_cargo_toml_up_the_fs()
[ERROR ra_project_model] entities: ReadDir("/workspaces/my-project")
[ERROR ra_project_model] candidate: "/workspaces/my-project/rust/Cargo.toml", exists: true
```

## Edge Cases?

If you have multiple Cargo.toml files one level deeper AND not in the root, will get whatever comes first (order undefined), example:
```
crate1/
    Cargo.toml
crate2/
     Cargo.toml
... (no root Cargo.toml)
```

However this is quite unusual and wouldn't have worked before either. This is only resolvable via manually choosing.

Co-authored-by: nmio <kristo.koert@gmail.com>
crates/rust-analyzer/src/main_loop.rs