Skip to content

internal: Add flycheck test for custom check command and debounce#21666

Merged
ShoyuVanilla merged 1 commit intorust-lang:masterfrom
Wilfred:flycheck_custom_check
Feb 18, 2026
Merged

internal: Add flycheck test for custom check command and debounce#21666
ShoyuVanilla merged 1 commit intorust-lang:masterfrom
Wilfred:flycheck_custom_check

Conversation

@Wilfred
Copy link
Contributor

@Wilfred Wilfred commented Feb 18, 2026

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.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 18, 2026
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.
@Wilfred Wilfred force-pushed the flycheck_custom_check branch from fe98487 to 607829e Compare February 18, 2026 11:12
@ShoyuVanilla ShoyuVanilla added this pull request to the merge queue Feb 18, 2026
Merged via the queue into rust-lang:master with commit 70f4402 Feb 18, 2026
16 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 18, 2026
@Wilfred Wilfred deleted the flycheck_custom_check branch February 18, 2026 20:43
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants