-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add an Optional CargoTargetSpec
-like Data to rust-project.json
#15892
Comments
@davidbarsky could you expand a little bit on what these extra fields actually do? This is out of my mind's L1 cache, so it's not immediately obvious to me how they could be used.
I am not entirely sure what this talks about (again, this is because at this point I remeber nothing :) ), but if this is about "what crate does foo.rs belong too" functionality (which is the first step of any analysis), that should be handled by source roots. See
For this one in particular, I think we could do something super general, like in
where keys are a fixed set of commands with standrad semantics, and values are command-lines. note that I still believe that integrating that into flycheck would be fundamentally wrong, but if it's easy to do transparently, then we could do it (like, flycheck itself is fundamentally wrong, but we are still having it, cause its useful).
👍 I think adding extra "display" information would be useful. Though, the danger here is mixing up things which are display only (and can be approximate fuzzy things, because human would sort them out) with things which have specific semantics (and where any fuzziness would confuse computers). We actually already have |
@matklad Thanks so much for taking the time!
Sure! To back up, neither of those two fields— I'll also quickly explain how we implemented the near-Cargo-like experience with Buck, since I think it provides some useful background context/demonstrate the value that this has for us, but feel to skip over this:
Notably, rust-analyzer did not not need to be aware of any new fields in order for us to implement this functionality.
I hacked something together by replacing the existing Cargo-based runnable functionality in rust-analyzer with Buck-based runnables. I didn't push it anywhere, but it works weirdly well. I didn't consider adding the runnables to the
You know, I've absolutely come around on flycheck being a hack for a bunch of reasons, but being able to construct a flycheck command using the crate name and/or the target label is pretty useful. At least for Cargo-based users, this would allow for per-crate flychecks, which I've personally wanted in
Yeah, I've avoided putting anything too load bearing in the "display" information. In this case though, I think that I'd it be valuable to do both (or at the very least, derive display information from the semantically load-bearing information) because there are a few spots where manifest path is used around rust-analyzer in a meaningful way. Footnotes |
On Fuchsia we took a similar approach to extending We primarily use GN/Ninja for our build system, and GN generates a We currently don't have any use for linking A concern I have with We're also mildly concerned about adding too much to |
Thanks for responding!
The primary utility of such a field (at least, for me) is to reload rust-analyzer whenever the corresponding manifest file changes, but I can understand that not being particularly useful for you.
Gotcha: at least under Buck, it's decently easy/reliable to figure out what crates owns what file, but I don't see any reason why
For the purposes of the linked PR, I'd like to move the commands responsible for runnables and flycheck out of each individual crate and onto the same level as |
Yeah we currently use a single Y'all's solution with separate workspaces/on-the-fly Anyways, as long as it still includes the ability for the flycheck command to get passed the modified file I think we're happy with the approach given that #12882 is our main concern. FWIW I feel pretty much the same way about flycheck as your comment: sure it could be handled outside of the r-a, but dang is it convenient that r-a knows how to read rustc/clippy json diagnostics and give you code actions for suggested replacements and such. I think that convenience is enough to warrant a bit of extra complexity to handle it in a build-system-agnostic way. |
Motivations
Hi! I'm writing this issue not entirely convinced that it's the right approach, but I figured I'd at least open an issue for discussion/feedback. Anyways: We've added two fields to the rust-project.json format in the rust-analyzer/buck integration, which have been really useful. They are:
build_file
corresponding to theBUCK
file defining the crate(s), serving the same function that aManifestPath
does today in rust-analyzer.label
corresponding to the build system's name of the crate (details: https://buck2.build/docs/concepts/glossary/#target-label), which is roughly a Buck/Bazel-flavored URI for a build target or a more user-visible version thepackage_flag
method incrates/project-mode/src/cargo_workspace/CargoWorkspace
.We've added these fields because determining the
ManifestPath
and the owning targets on the fly by querying buck adds some non-trivial, perceptible latencies (200-300 milliseconds at the average, with some substantially higher latencies at the tail) in what users would otherwise expect to be a near-instant response. Similar operations in rust-analyzer are in the low single-digit milliseconds, to its immense credit!I decided to open this issue to propose upstreaming these changes when I was working on adding generic runnable support1 and realized that a decent chunk of the information needed to successfully create a runnable (specifically, the manifest file) could be very easily added to a
CargoTargetSpec
via arust-project.json
, enabling a set of long-tail features and functionality that I've wanted to tackle in a Buck context but was blocked by either too-high latencies or rust-analyzer's lack of visibility into this information. These features include:rust-project.json
-based projects, which requireManifestPath
(c.f., AddManifestPath
toCrateData
; update dependency view to use ManifestPath #14931)$saved_file
interpolation is even more so), it might be feasible to replace that with building a specificCargoTargetSpec::package
, which should have benefits for larger Cargo workspaces as well.Approach
I'd like to add an optional
TargetSpec
(renamed fromCargoTargetSpec
) toproject_model/src/project_json/Crate
, where any build system that opts into providing aTargetSpec
would be required to provide all information thatTargetSpec
expects. My goal for providing this constraint is to minimize maintenance costs for rust-analyzer.Alternatives/Caveats.
I worry about proposing this feature because I worry:
rust-project.json
(in that the rust-project.json format is the lowered version of a cargo graph, and this would be introducing something that is conceptually adjacent to it.)Footnotes
Note that the current state of runnables can largely work if this line is commented out and the
rust-buck-companion
extension queries the owner of the file in question, but that's not an approach that I'd like to take because latencies of querying a build system are too high. ↩The text was updated successfully, but these errors were encountered: