Repository: vscode
Issue: Adding `quickfix.biome` to `editor.codeActionsOnSave` slows down saving of `*.ts` files
Labels: bug,typescript,editor-code-actions,perf

transferred from: https://github.com/microsoft/vscode-discussions/discussions/1664
ref: https://github.com/biomejs/biome-vscode/issues/229

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: No. This issue occurs when `typescript-language-features` is enabled.

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.95.0-insider (Universal)
- OS Version: Darwin arm64 24.0.0 / macOS 15.0.1

## Background

The Biome VS Code extension guides users to add `quickfix.biome` to `editor.codeActionsOnSave` to fix issues when saving files.

- https://biomejs.dev/reference/vscode/#fix-on-save

However, enabling this setting causes saving `*.ts` files to be delayed by about 500ms.

https://github.com/user-attachments/assets/fc8f4134-2422-411d-9691-1e658e62627b

Surprisingly, this delay occurs even if the Biome extension is not installed. Additionally, disabling the built-in VS Code extension `typescript-language-features` eliminates the delay. For details of the issue and reproduction steps, please see the following comment:

- https://github.com/biomejs/biome-vscode/issues/229#issuecomment-2356257770

## Cause of the delay

As a result of my investigation, I found that the delay is caused by the following code in `typescript-language-features`:

- https://github.com/microsoft/vscode/blob/684f9d47a4a97d7ea747915f4d1595f86f98aaad/extensions/typescript-language-features/src/languageFeatures/quickFix.ts#L254-L256

When `typescript-language-features` receives a `quickfix` code action, it attempts to automatically fix some diagnostics. The execution process is as follows:

1. Receive a `quickfix` code action.
2. Check if there are diagnostics in the open file. If not, exit.
3. Wait for 500ms.
4. Retrieve diagnostics again.
5. Automatically fix any fixable diagnostics obtained in step 4.

The 500ms wait is because the diagnostics obtained in step 2 might be outdated. If this wait time is removed, code fixes might be performed based on old diagnostics. To prevent this, `typescript-language-features` waits for 500ms.

Furthermore, `typescript-language-features` does not only respond to the `quickfix` code action. It responds to all code actions that start with `quickfix`, such as `quickfix.biome` and `quickfix.some-name`. Therefore, adding `quickfix.biome` to `editor.codeActionsOnSave` slows down the saving of `*.ts` files.

As an experiment, I commented out [the line that waits for 500ms](https://github.com/microsoft/vscode/blob/684f9d47a4a97d7ea747915f4d1595f86f98aaad/extensions/typescript-language-features/src/languageFeatures/quickFix.ts#L254-L256) and rebuilt vscode, and the saving of `*.ts` files became faster.

https://github.com/user-attachments/assets/a2e727e6-15eb-4701-890b-71b9dd844272

## Questions

I have several questions regarding this delay issue.

### Q1. Is it acceptable to add `quickfix` or `quickfix.biome` to `editor.codeActionsOnSave`?

In the first place, does VS Code intend for `quickfix` or `quickfix.biome` to be added to `editor.codeActionsOnSave`? Neither `quickfix` nor `quickfix.biome` are included among the completion items for `editor.codeActionsOnSave`.

<img width="592" alt="image" src="https://github.com/user-attachments/assets/54430320-098b-48ee-b4eb-9512d3df9d2b">

Is this because adding `quickfix` or `quickfix.biome` to `editor.codeActionsOnSave` is not intended? Should the Biome extension use `source.fixAll.biome` instead of `quickfix.biome`?

### Q2. Is it okey for `typescript-language-features` to react to `quickfix.biome`?

This delay occurs because `typescript-language-features` is reacting to `quickfix.biome`. I feel that `typescript-language-features` is overly sensitive to code actions. Is this the intended behavior?

Should `typescript-language-features` be modified to react only to `quickfix` and `quickfix.ts`?

### Q3. Is it okay that the `source.fixAll.ts` code action does not wait for 500ms?

In the `quickfix` code action, there is a 500ms wait, but in the `source.fixAll.ts` code action, this does not occur.

- https://github.com/microsoft/vscode/blob/684f9d47a4a97d7ea747915f4d1595f86f98aaad/extensions/typescript-language-features/src/languageFeatures/fixAll.ts#L211-L220

Therefore, in the `source.fixAll.ts` code action, there is a possibility that code fixes are performed based on old diagnostics. Is this the intended behavior?