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

Avoid running clippy on rust analyzer #1372

Open
snowp opened this issue Jun 2, 2022 · 3 comments
Open

Avoid running clippy on rust analyzer #1372

snowp opened this issue Jun 2, 2022 · 3 comments
Labels

Comments

@snowp
Copy link

snowp commented Jun 2, 2022

When using the suggested approach of enabling clippy on build this also ends up being checked when running the rust-analyzer tool. This ends up being pretty tedious during development since it means that the code now has to both compile and pass clippy checks, but I really just want to update the rust project file.

Is there an existing mechanism to disable clippy when using the rust analyzer tool? If not, would it be reasonable to make it possible to pass additional args to the rust analyzer tool so that I gate things with a --config?

@hlopko
Copy link
Member

hlopko commented Jun 3, 2022

Which suggested approach to use clippy do you use? This one?

$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks //hello_lib:all

I presume you added this to your .bazelrc as something like:

build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks

If I wanted to disable clippy for rust analyzer runs in this scenario, I'd add this to the .bazelrc:

build:noclippy --output_groups=-clippy_checks

(https://docs.bazel.build/versions/main/command-line-reference.html#flag--output_groups). Then you should be able to run:

bazel run --config=noclippy @rules_rust//tools/rust_analyzer:gen_rust_project  //my:project

Am I making any sense?

@snowp
Copy link
Author

snowp commented Jun 3, 2022

Yep this makes sense! The main thing I wasn't aware of here is that the parameter passed to run would propagate to the underlying bazel build command that gen_rust_project invokes.

Your suggestion does indeed remove the clippy check, though it seems like enabling the aspect by default still causes the Rust targets to be compiled, so it still fails to generate the rust-analyzer project file if there is a syntax error. Is there a way to also disable this?

Would be great to have this stuff included in the docs, so happy to do a docs PR to help the next person running into this

@snowp
Copy link
Author

snowp commented Jun 3, 2022

Scratch what I said about it working, seems like the problem is still there. It seems like the --config noclippy is not propagated to gen_rust_project's call to build rust_analyzer_aspect.

If I add build --config noclippy to my bazelrc it does disable the rustc + clippy invocation, so it seems like the issue is just about being able to propagate the option between the bazel run invocation and the underlying call to bazel build.

I tried to add --config noclippy at the end of the gen_rust_project command line (thinking that it might just pass through the arguments to bazel), but this seems to fail when it tries to use this list of targets to construct the aquery command later on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants