internal: Add flycheck test for custom check command and debounce#21666
Merged
ShoyuVanilla merged 1 commit intorust-lang:masterfrom Feb 18, 2026
Merged
internal: Add flycheck test for custom check command and debounce#21666ShoyuVanilla merged 1 commit intorust-lang:masterfrom
ShoyuVanilla merged 1 commit intorust-lang:masterfrom
Conversation
This adds an integration test for flycheck with a custom check command. On its own, the test actually fails due to an issue with the debounce logic. We would trigger a flycheck when the workspace is loaded, but the check command references $saved_file and flycheck does nothing (we don't know which file was saved). Since we debounce state changes over 50 milliseconds, we would then discard the later save request that actually specifies the file. This bug is probably very rare in practice, 50 milliseconds isn't very long. I think it's a genuine fix though. AI disclosure: Partly written by Opus 4.6.
fe98487 to
607829e
Compare
ShoyuVanilla
approved these changes
Feb 18, 2026
Wilfred
added a commit
to Wilfred/rust-analyzer
that referenced
this pull request
Feb 25, 2026
When rust-analyzer receives textDocument/didChangeWatchedFiles, we
want to trigger a flycheck in all workspaces if we can't find which
workspace owns those files.
However, since we used .any() instead of .all(), this behaviour was
always triggered when the user had more than one workspace.
For cargo-based projects, this just makes rust-analyzer slower. For
projects with a custom check command using $saved_file or
{saved_file}, this introduced a race condition that sometimes
prevented diagnostics.
When we see the following flycheck events in this order:
// Created by textDocument/didSave.
RequestStateChange(Restart { ... saved_file: Some("foo.rs") })
// Created by textDocument/didChangeWatchedFiles
RequestStateChange(Restart { ... saved_file: None })
Then the flycheck debounce takes the last event, we invoke flycheck
with saved_file: None, and no flycheck occurs (because we require a
value to substitute in $saved_file).
Previously the debounce took the first event (until rust-lang#21666), but that
just meant a race condition when events arrive in the opposite order.
Instead, use .all() and add an integration test to exercise this
behaviour.
AI disclosure: Once I understood the problem, I used Opus 4.6 to do
the first draft of this integration test.
Wilfred
added a commit
to Wilfred/rust-analyzer
that referenced
this pull request
Feb 25, 2026
When rust-analyzer receives textDocument/didChangeWatchedFiles, we
want to trigger a flycheck in all workspaces if we can't find which
workspace owns those files.
However, since we used .any() instead of .all(), this behaviour was
always triggered when the user had more than one workspace.
For cargo-based projects, this just makes rust-analyzer slower. For
projects with a custom check command using $saved_file or
{saved_file}, this introduced a race condition that sometimes
prevented diagnostics.
When we see the following flycheck events in this order:
// Created by textDocument/didSave.
RequestStateChange(Restart { ... saved_file: Some("foo.rs") })
// Created by textDocument/didChangeWatchedFiles
RequestStateChange(Restart { ... saved_file: None })
Then the flycheck debounce takes the last event, we invoke flycheck
with saved_file: None, and no flycheck occurs (because we require a
value to substitute in $saved_file).
Previously the debounce took the first event (until rust-lang#21666), but that
just meant a race condition when events arrive in the opposite order.
Instead, use .all() and add an integration test to exercise this
behaviour.
AI disclosure: Once I understood the problem, I used Opus 4.6 to do
the first draft of this integration test.
Wilfred
added a commit
to Wilfred/rust-analyzer
that referenced
this pull request
Mar 2, 2026
When rust-analyzer receives textDocument/didChangeWatchedFiles, we
want to trigger a flycheck in all workspaces if we can't find which
workspace owns those files.
However, since we used .any() instead of .all(), this behaviour was
always triggered when the user had more than one workspace.
For cargo-based projects, this just makes rust-analyzer slower. For
projects with a custom check command using $saved_file or
{saved_file}, this introduced a race condition that sometimes
prevented diagnostics.
When we see the following flycheck events in this order:
// Created by textDocument/didSave.
RequestStateChange(Restart { ... saved_file: Some("foo.rs") })
// Created by textDocument/didChangeWatchedFiles
RequestStateChange(Restart { ... saved_file: None })
Then the flycheck debounce takes the last event, we invoke flycheck
with saved_file: None, and no flycheck occurs (because we require a
value to substitute in $saved_file).
Previously the debounce took the first event (until rust-lang#21666), but that
just meant a race condition when events arrive in the opposite order.
Instead, use .all() and add an integration test to exercise this
behaviour.
AI disclosure: Once I understood the problem, I used Opus 4.6 to do
the first draft of this integration test.
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.
This adds an integration test for flycheck with a custom check command.
On its own, the test actually fails due to an issue with the debounce logic. We would trigger a flycheck when the workspace is loaded, but the check command references $saved_file and flycheck does nothing (we don't know which file was saved).
Since we debounce state changes over 50 milliseconds, we would then discard the later save request that actually specifies the file.
This bug is probably very rare in practice, 50 milliseconds isn't very long. I think it's a genuine fix though.
AI disclosure: Partly written by Opus 4.6.