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

Better diagnostics for unlinked projects #8622

Open
matklad opened this issue Apr 22, 2021 · 17 comments
Open

Better diagnostics for unlinked projects #8622

matklad opened this issue Apr 22, 2021 · 17 comments
Labels
C-enhancement Category: enhancement E-medium S-actionable Someone could pick this issue up and work on it right now

Comments

@matklad
Copy link
Member

matklad commented Apr 22, 2021

Problem: when opening a project with unusual struture (Cargo.toml buried deep in the source tree) rust-analyzer doesn't work, without a clear error message.

At the moment, when opening the project, we to detect rust project structure we either use likedProjects config, or, if that is absent, look for Cargo.tomls in level one subdirs. So, we fail to discover deeply nested projects.

Soln1: travers all folders, and not only the top level. This is a bad idea, as this is an unbounded amount of work.

Soln2: lazily load Cargo.projects. That is, when a user opens an .rs file which does not belong to any known project, traverse the directory upwards looking for Cargo.toml. This seems like a best solution UX wise on the first glance. There's a big problem though -- non-determinism. If there are two projects, A and B, and A uses B, then opening B first and invoking find useages won't find usages in A, because we don't know about A yet!

Soln3, what we should do: start like soln2, but, instead of magically loading the file, show a popup "add this file to a list of linked projects?". That way, discovery results are persistent, and user always gets the same workspace.

@matklad matklad added E-medium S-actionable Someone could pick this issue up and work on it right now labels Apr 22, 2021
@flodiebold
Copy link
Member

If there are two projects, A and B, and A uses B, then opening B first and invoking find useages won't find usages in A, because we don't know about A yet!

If A and B aren't in a common Cargo workspace and A just uses B through a path dependency, would we actually find the usages? My guess would be that we see them as completely separate crate graphs?

@matklad
Copy link
Member Author

matklad commented Apr 22, 2021

If we have an entry for A in the linked projects, then yes, we'll find usages (or at least, will be able to find them in theory, depending on how our source2def picks B).

@jonas-schievink
Copy link
Contributor

Soln1: travers all folders, and not only the top level. This is a bad idea, as this is an unbounded amount of work.

It seems like this is a problem for big workspaces, but I've often used projects where just looking into every top-level directory would be enough to discover all Cargo.tomls needed. So perhaps just descending a single level would be another possible solution here.

It would also be interesting to look at how other IDEs do this.

@matklad
Copy link
Member Author

matklad commented Apr 22, 2021

It seems like this is a problem for big workspaces, but I've often used projects where just looking into every top-level directory would be enough to discover all Cargo.tomls needed. So perhaps just descending a single level would be another possible solution here.

That's exactly what we are doing! ;)

It would also be interesting to look at how other IDEs do this.

IntelliJ Rust does 3, with a caveat that the list of liked projects is managed internally and is not exposed via user-editable config file. That is, instead of JSON, there's a GUI for the list of associated projects

image

@flodiebold
Copy link
Member

The problem with changing the configs currently is that it depends on the client, unless we finally introduce rust-analyzer.toml 😬

@matklad
Copy link
Member Author

matklad commented Apr 22, 2021

Yeah, that's true... I wonder if we should add a "change config" LSP extension?

@flodiebold
Copy link
Member

See #8631, we might want to lazily load non-toplevel Cargo projects in any case...

@flodiebold
Copy link
Member

This is also related to #6388, I think -- if we're able to load Cargo projects when you open a file from them, the next step would be to create a fake crate for free-standing files when you open them...

@flodiebold
Copy link
Member

Btw, we also have the "changing configs" use case for cargo features (toggling them on/off)...

@matklad
Copy link
Member Author

matklad commented Apr 26, 2021

Uhh

@bugadani

This comment has been minimized.

@flodiebold

This comment has been minimized.

@bugadani

This comment has been minimized.

@nickwesselman
Copy link

We have a standard project structure that results in Rust packages two levels deep, and thus not working with Rust Analyzer. linkedProjects is a workaround but requires configuring each package individually. Would support for wildcards in linkedProjects be an option?

{
    "rust-analyzer.linkedProjects": [
        "extensions/*/Cargo.toml"
    ]
}

@andar1an
Copy link

We have a standard project structure that results in Rust packages two levels deep, and thus not working with Rust Analyzer. linkedProjects is a workaround but requires configuring each package individually. Would support for wildcards in linkedProjects be an option?

{
    "rust-analyzer.linkedProjects": [
        "extensions/*/Cargo.toml"
    ]
}

I was also hoping for something like this, or being able to define the depth of search like you can for git repos.

@andar1an
Copy link

andar1an commented Jan 26, 2023

Hello :), wondering if there are any updates on being able to use wildcards with linkedProjects? Or lazily loading projects?

@fmhr
Copy link

fmhr commented Jul 25, 2024

vscode does not support wildcards, so this is what we need.
microsoft/vscode#58698

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: enhancement E-medium S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

8 participants