Fix rust_analyzer flycheck label for sources in subdirectories - #4240
Open
brunal wants to merge 1 commit into
Open
Fix rust_analyzer flycheck label for sources in subdirectories#4240brunal wants to merge 1 commit into
brunal wants to merge 1 commit into
Conversation
`query_label_for` built the saved file's label from its basename rather
than its path relative to the package, so for a file at
`foo/bar/src/publisher.rs` it queried
attr(srcs, "//foo/bar:publisher.rs", //foo/bar:*)
which matches nothing. Flycheck then failed with "bazel query returned
no targets" and rust-analyzer reported "Cargo watcher failed, the
command produced no valid metadata".
This problem can easily arise in cargo-compatible codebases, as the
"src/" subdir is standard with cargo.
Note that crate root modules are exempt because `build_file_label_map`
populates the sidecar's `file_labels` from each spec's `root_module`, so
saving `lib.rs` or `main.rs` takes the fast path and never runs the
query. Every other saved file in a package with a `src/` layout hit
this.
Pull the label construction into `source_file_label`/`package_label` so
it can be unit tested, and normalize `\` to `/` there -- both halves are
derived from the saved file, so on Windows they arrive
backslash-separated and `//foo\bar:...` is not a valid label.
Implementation-wise, I simply always normalize, when there could be a
platform-specific implementation.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
query_label_forbuilt the saved file's label from its basename rather than its path relative to the package, so for a file atfoo/bar/src/publisher.rsit queriedwhich matches nothing. Flycheck then failed with "bazel query returned no targets" and rust-analyzer reported "Cargo watcher failed, the command produced no valid metadata".
This problem can easily arise in cargo-compatible codebases, as the "src/" subdir is standard with cargo.
Note that crate root modules are exempt because
build_file_label_mappopulates the sidecar'sfile_labelsfrom each spec'sroot_module, so savinglib.rsormain.rstakes the fast path and never runs the query. Every other saved file in a package with asrc/layout hit this.Pull the label construction into
source_file_label/package_labelso it can be unit tested, and normalize\to/there -- both halves are derived from the saved file, so on Windows they arrive backslash-separated and//foo\bar:...is not a valid label. Implementation-wise, I simply always normalize, when there could be a platform-specific implementation.