-
Notifications
You must be signed in to change notification settings - Fork 431
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 option to save the json output from rustc to pass to rust-analyzer #1657
base: main
Are you sure you want to change the base?
Conversation
The error format is checked whenever it's set, not only when rustc_quit_on_rmeta is set.
loop { | ||
let mut line = String::new(); | ||
let read_bytes = reader.read_line(&mut line)?; | ||
if read_bytes == 0 { | ||
break; | ||
} | ||
if let Some(ref mut file) = file_writer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am particularly unhappy about this check happening on every loop, but I do not know of a way to remove it apart from constructing two different functions with duplicated code except this bit.
I considered abstracting with a passed lambda, but I would guess(?) a function call is more heavyweight compared to a a tag check. In any case, I'm not sure this is a performance bottleneck at all, considering we're doing loads more IO. It's just not pretty.
d23a2e9
to
a1fea4c
Compare
Did I somehow cause these build failures - they seem to be 404ing on fetching something? |
The actual error is
I don't think that has anything to do with fetching, looks like the build failures are related to the PR. The issue is that we end up trying to run an action without passing |
Thanks, I must have gotten a line mismatch.. |
f5a2f20
to
5dcbaf1
Compare
5dcbaf1
to
858e124
Compare
Hopefully this fixes compilation issues on windows
2848333
to
0aec7e9
Compare
Not sure what the windows errors are about :/ |
Tried to place the json output files in the same directory (via |
My educated guess is that this is caused by two separate actions trying to generate the same output. If both actions have the same file declared as an output, bazel will error out; I think the clippy aspect doesn't have the |
2070547
to
0aec7e9
Compare
I personally found that The following worked for me:
with get_outputs.cquery containing:
|
Oops, the FTR, I am currently no longer working on this, so any interested parties should feel free to pick this up. |
In that case, I'd be happy to pick this up. My opinions:
This is the user experience I want. I've prototyped this and have it mostly working: VScode has a 'discover project command'. It invokes this with all files you currently have open, and treats the stdout as the rust-project.json. I suggest adding extra options to gen_rust_project so we can run
Vscode would give live feedback for rust code via a command that collected all of those files and generated one large file out of all of them. This appears like it could be achieved with this feature, but I was unable to get it to work, so I'm currently using the on-save feature, which has issues with race conditions (since vscode only updates on save, rather than when the files are updated, if you update multiple files it doesn't work). These files would be updated whenever the user runs "bazel build", if they have the configs |
This will allow for watcher-style flychecks. Currently, we can only run flychecks on every save. This allows for a long-running flycheck that can update diagnostics between file saves (eg. update on every build). Rationale: I'm trying to improve the experience developing using bazel + rust (see [issue](bazelbuild/rules_rust#1657)). The developer experience I'm looking at is: 1. Dev invokes "ibazel build //:my_crate //:my_crate_test". This ensures that whenever the source code changes, it rebuilds. both the crate and the test for the crate. 2. The discover project command is automatically invoked when you open main.rs, which generates a file listing the `.rustc-output` files mentioned below. 3. Dev modifies `my_crate/src/main.rs` and saves in vscode. 4. bazel is automatically invoked on save, and under the hood invokes rustc, which generates `bazel-out/k8-fastbuild/bin/my_crate/my_crate.rustc-output` and `bazel-out/k8-fastbuild/bin/my_crate_test/my_crate_test.rustc_output` for the original crate and the test crate respectively. 5. The non-test crate finishes building 6. A watcher script would see that `my_crate.rustc-output` has been updated, and update the rust-analyzer result for the file. 7. The test crate finishes building 8. The watcher script would see that `my_crate_test.rustc-output` has been updated, and update the rust-analyzer result for the file.
This will allow for watcher-style flychecks. Currently, we can only run flychecks on every save. This allows for a long-running flycheck that can update diagnostics between file saves (eg. update on every build). Rationale: I'm trying to improve the experience developing using bazel + rust (see [issue](bazelbuild/rules_rust#1657)). The developer experience I'm looking at is: 1. Dev invokes "ibazel build //:my_crate //:my_crate_test". This ensures that whenever the source code changes, it rebuilds. both the crate and the test for the crate. 2. The discover project command is automatically invoked when you open main.rs, which generates a file listing the `.rustc-output` files mentioned below. 3. Dev modifies `my_crate/src/main.rs` and saves in vscode. 4. bazel is automatically invoked on save, and under the hood invokes rustc, which generates `bazel-out/k8-fastbuild/bin/my_crate/my_crate.rustc-output` and `bazel-out/k8-fastbuild/bin/my_crate_test/my_crate_test.rustc_output` for the original crate and the test crate respectively. 5. The non-test crate finishes building 6. A watcher script would see that `my_crate.rustc-output` has been updated, and update the rust-analyzer result for the file. 7. The test crate finishes building 8. The watcher script would see that `my_crate_test.rustc-output` has been updated, and update the rust-analyzer result for the file.
…yzer (#1942) @googleson78 originally wrote #1657 in order to solve this problem. As discussed in that PR, they're no longer working on this, so I offered to pick this up. This is the same PR as that one, but has some bugfixes and refactoring applied. --------- Co-authored-by: Georgi Lyubenov <georgi.lyubenov@tweag.io> Co-authored-by: UebelAndre <github@uebelandre.com>
Goal
This is intended to be used to provide output that
rust-analyzer
scheckOnSave.overrideCommand
expects, so that we can get inline diagnostics insiderust-analyzer
when usingrules_rust
.There are a few unresolved issues which I've detailed below, some of them quite core, but I'm posting this in-progress work to get some more opinions, and especially to hear if you like this approach at all. I'm very open to discussing everything here!
Current implementation
The core idea is to have a flag (
output_diagnostics
) that toggles whether we save rustc output. Once this rustc output is saved, a user can then gather all the files containing the rustc json output and simplycat
them or whatever, e.g. they can setcheckOnSave.overrideCommand
to the following script:Unresolved questions
Core idea
Is this approach alright?
Do we instead want to have an entirely separate target for this? One could imagine implementing an aspect that reuses most of the implementation details for the
rust_*
targets. That might be unfortunate because it might end up doing more recompilationBetter UX
Builtin target for outputting the files
It would be great if we had some builtin target that somehow accomplishes what the bash script from above does.
We could also rely on some bazel specific features to find our required files instead of relying on coreutils like
find
.If rust-lang/rust-analyzer#13529 goes through we can even generate that file and insert the target in question there.
Docs
Obviously this needs documentation - I'm not sure where to put it. We need to finalise everything else before we do this bit, I think.