Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running code actions on save breaks imports #4680

Closed
1 of 3 tasks
OliverJAsh opened this issue May 9, 2024 · 11 comments
Closed
1 of 3 tasks

Running code actions on save breaks imports #4680

OliverJAsh opened this issue May 9, 2024 · 11 comments

Comments

@OliverJAsh
Copy link

OliverJAsh commented May 9, 2024

VS Code version

1.89.0

Extension version

2.2.2

Biome version

1.7.3

Operating system

  • Windows
  • macOS
  • Linux

Description

When noUnusedImports is enabled, running code actions on save (source.organizeImports.biome + quickfix.biome) is slow and breaks the imports.

Steps to reproduce

Full reduced test case: https://github.com/OliverJAsh/biome-vscode-quickfix-import-issue/compare/1.7.3. Contents inlined below.

Given:

biome.json:

{
    "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
    "linter": {
      "enabled": true,
      "rules": {
        "correctness": {
          "noUnusedImports": "warn"
        }
      }
    }
  }
  

.vscode/settings.json:

{
  "editor.codeActionsOnSave": {
    "source.organizeImports.biome": "explicit",
    "quickfix.biome": "explicit"
  }
}

index.ts:

// @ts-nocheck

import * as APIClientError from 'app/services/api/APIClientError';
import { TPhotoSlug, Codec } from 'app/services/api/Photo/types/PhotoSlug';

APIClientError;
export type F = TPhotoSlug;

// edit this comment and save the file

When I save index.ts and "code actions on save" runs, I notice two things. Firstly, it feels much slower than I would expect it to be. It adds about 500ms-1s to the save operation (see screen recording below). Secondly, I end up with broken imports—this is similar to biomejs/biome-vscode#179 although note here I'm using the latest version of Biome which—I understand from https://github.com/biomejs/biome/issues/688—is supposed to include the fix.

// @ts-nocheck

import * as APIClientError from 'app/services/api/APIClientError';
import { TPhotoStype lug } from 'app/services/api/Photo/types/PhotoSlug';

APIClientError;
export type F = TPhotoSlug;

// edit this comment and save the file
Screen.Recording.2024-05-09.at.09.51.16.mov

Expected behavior

Save is fast + imports are not broken.

Does this issue occur when using the CLI directly?

Not sure / Not applicable

Logs

No response

@nhedger
Copy link
Member

nhedger commented Dec 1, 2024

Closing as duplicate of biomejs/biome-vscode#229

@nhedger nhedger closed this as completed Dec 1, 2024
@OliverJAsh
Copy link
Author

OliverJAsh commented Dec 2, 2024

@nhedger biomejs/biome-vscode#229 seems to focus on performance, however my issue above also describes an issue with imports breaking. Can we re-open this and update the title?

I can still reproduce this issue on the last version (1.9.4): https://github.com/OliverJAsh/biome-vscode-quickfix-import-issue/tree/1.9.4

@nhedger
Copy link
Member

nhedger commented Dec 2, 2024

Sure, but in that case it belongs in the main repo. I'll move it

@nhedger nhedger reopened this Dec 2, 2024
@nhedger nhedger transferred this issue from biomejs/biome-vscode Dec 2, 2024
@OliverJAsh OliverJAsh changed the title Running code actions on save is very slow and breaks imports Running code actions on save breaks imports Dec 2, 2024
@ematipico
Copy link
Member

@OliverJAsh is it possible that there are multiple processes running? Try to check the task manager, or use biome rage --daemon-logs.

If so, kill the processes. This happens with the old version of the VSCode extension

@OliverJAsh
Copy link
Author

Thanks for the reply @ematipico.

It doesn't seem like that's the case. I can only see one running server. I can also reproduce this issue after restarting my entire system, with no windows/applications open except for the reduced test case I shared.

Are you able to reproduce it using my test case?

@ematipico
Copy link
Member

Yeah, I can consistently replicate the issue. However, this issue doesn't occur with other clients such as Zed.

@OliverJAsh
Copy link
Author

I wonder if it's related to biomejs/biome-vscode#229, because the corruption only seems to happen after the delay.

@ematipico
Copy link
Member

I think so. On my machine I can see that VSCode applies the changes with a delay between the two of them, in fact if I use CTRL+Z, I can see states of the code I didn't have before. I need to hit 2/3 times before reverting the code to how it was.

I am mostly certain that this is a VSCode issue, which isn't able to batch the changes in a single one, and instead it queues them and eventually emits incorrect code.

@OliverJAsh
Copy link
Author

This doesn't seem to be an issue when using source.fixAll.biome instead of quickfix.biome.

@ematipico
Copy link
Member

@OliverJAsh can you close the issue?

@OliverJAsh
Copy link
Author

Sure, but I think the documentation still needs to be updated to mention the new command.

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

No branches or pull requests

3 participants