Skip to content

Cancel stale format-on-type requests - #347115

Merged
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
sameerihs:cancel-stale-format-on-type-requests
Nov 12, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
sameerihs:cancel-stale-format-on-type-requests

Conversation

@sameerihs

@sameerihs Sameer (sameerihs) commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #347114

A delayed format-on-type response can edit a different document after the user switches tabs in the same editor group. Bind each pending request to the formatting session so model, configuration or provider changes cancel it. Remove completed requests from session tracking.

The browser regressions fail before the fix and pass afterward. The public reproduction also fails in installed VS Code 1.145.2: whitespace intended for const x=1; splits the other document's identifier into const v a lue=2;.

Controls cover successful formatting, switching back to the original document and cancellation/disposal. Original macOS validation included client and API-extension compilation, client typechecking and changed-file lint.

CI follow-up

Remove the duplicate public-API regression and its unused imports. In the full API suite, the global type command can target a stale Chat editor left by earlier tests instead of the test document, so its formatter never starts. The retained browser tests cover the same cancellation behavior without depending on global focus. No production Chat/editor-focus behavior or SSH smoke automation is changed.

Additional Windows validation

Commands were run with VSCODE_SKIP_PRELAUNCH=1 for the test scripts:

  • pnpm run build-fast - passed; pnpm run build-fast --client-only also passed after incorporating the latest incoming main merge.
  • node build\hygiene.ts extensions\vscode-api-tests\src\singlefolder-tests\editor.test.ts - passed, including targeted oxlint.
  • .\scripts\test.bat --run src\vs\workbench\contrib\format\test\browser\formatActionsMultiple.test.ts --reporter dot - 9 passing. Running the same command with only the compiled controller temporarily replaced by its pre-fix version produced 5 passing controls and 4 expected regression failures. The fixed output was restored and hash-verified, then all 9 passed again.
  • .\scripts\test-integration.bat --suite api-folder --grep '^(chat|vscode API - editors)' - 28 passing, 14 pending.
  • .\scripts\test-integration.bat --suite api-folder - 340 passing, 58 pending, 2 failures in unchanged tests: the active-editor assertion for active editor not always correct... #49125 and the no-output terminal assertion for Commands with no output show the sandbox command instead of "no output" #303531. The formatter-start timeout is eliminated; these unrelated failures were not modified.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 18:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No actionable review findings remain for the change that ties pending format-on-type requests to the editor’s formatting session.

No open issues 🎉

What changed in this PR

Fixes #347114 by tying pending format-on-type requests to the editor’s formatting session, preventing delayed responses from editing a different document after a tab switch.

Changes:

  • Cancel pending requests when the formatting session ends and remove completed requests from session tracking.
  • Add unit coverage for model switching, cancellation, disposal, and successful formatting.
  • Add a public API regression test for switching documents while formatting is pending.

No actionable findings remain.

File Description
src/​vs/​workbench/​contrib/​format/​test/​browser/​formatActionsMultiple.test.ts Adds format-on-type lifecycle and regression tests.
src/​vs/​editor/​contrib/​format/​browser/​formatActions.ts Binds request cancellation and cleanup to the formatting session.
extensions/​vscode-api-tests/​src/​singlefolder-tests/​editor.test.ts Tests delayed formatting across a same-group document switch.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the change preventing delayed format-on-type results from modifying a different document.

No open issues 🎉

Review effort: Max

@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the formatting Source formatter issues label Nov 12, 2026
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Sameer (@sameerihs) Thank you!

Retain the browser regressions for microsoft#347114 without relying on global editor focus left by earlier Chat API tests. Remove the duplicate API scenario and its unused imports.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 3404e94 into microsoft:main Nov 12, 2026
52 of 53 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

formatting Source formatter issues

5 participants