biome: šŸ› Import sorting breaks with a particular import line when saving in VSCode

Environment information

CLI:
  Version:                      1.5.1
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v18.17.1"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/9.6.7"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           true
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Workspace:
  Open Documents:               0

Biome VSCode extension version v2.1.1

What happened?

With organizeImports enabled and this config in workspace:

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

just add this particular import line to any script that has a bunch of existing imports.

import {MaxInteger32Value } from '@shared/MaxInteger32Value';

Minimal reproducible case below:

import {MaxInteger32Value } from '@shared/MaxInteger32Value';
import { a } from '@a';
import { b } from '@b';

Something about this particular string causes havoc by duplicating it, and replacing existing import lines below it. See screenshot

This only happens in VSCode, I can’t reproduce it on the playground.

Expected result

Screenshot 2024-01-16 at 11 11 41 AM

Code of Conduct

  • I agree to follow Biome’s Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 40
  • Comments: 56 (22 by maintainers)

Most upvoted comments

I’m going to share this again and close the issue.

The issue is fixed in the pre-release version of VSCode. The bug was caused by how the extension was connected to the server, which caused spawning multiple processes and connections of the Biome Daemon. This becomes evident every time Biome is updated. Hence, on save, multiple instructions were received by the client and caused this.

The pre-release fixed this. I don’t know when we will ship it as stable.

Instructions to fix the issue onwards:

  • install the pre-release version of the extension
  • close your editor
  • use a task manager to kill all the biome processes
  • use biome explain --daemon-logs to identify the cache folder used by biome in your OS (more here https://biomejs.dev/guides/editors/create-a-extension/#daemon-logs)
  • delete all the sockets files that belong to old versions of Biome
  • reopen your editor, the issue is fixed

@ematipico here’s a simple reproduction showing the issue I’m having (maybe not related?):

Before save (swapped imports to be out of order) Screenshot 2024-01-16 at 11 56 53 PM After save Screenshot 2024-01-16 at 11 57 04 PM

Settings Screenshot 2024-01-16 at 11 58 29 PM

fwiw I also just tried disabling source.addMissingImports and got the same result, so this seems like a bug isolated to source.organizeImports.biome. Update: interestingly restarting VSCode or resetting the extension host seems to fix things temporarily, so the example above works again until it starts breaking and then I can reproduce it consistently until I restart again. Maybe there’s some sort of corrupted internal state of either VSCode or the extension?

Is this still only in the pre-release? it’s been awhile

+1. Just started trying biome in my project. organizeImports breaks imports

image image

Update: Reload Window command in VS Code solved the issue

I have also been experiencing this issue. It seems to be because there is many Biome agents running and happens if I have left my Mac on overnight. If I hover over a Biome warning or error I can see the error repeated, sometimes 20 times.

Closing VSCode completely does fix the issue and Biome suggestions are no longer duplicated.

So I would suggest the issue is with Biome seemingly restarting without killing the previous process for some reason?

This has gotten significantly worse for me in the last week or two. Even restarting cursor doesn’t reliably stop it, I’m on the latest prerelease of the extension.

I think the issue is indeed multiple instances of biome running @ematipico. It’d be great to get this fixed though as it’s a regular issue my team is having too and having to reload the editor often isn’t great.

Thanks for all your efforts šŸ™

Use the preview release of the VSCode extension, that should fix it.

Yeah I don’t think the issue caused by multiple instances are fixed. And there’re still failing cases that I’m aware of even there is only one instance. This is a complex issue, but we’ll fix it step by step.

And just like that, I finally witnessed the imports being messed up with my own eyes too! I’d been keeping the session with 4 Biome entries open, and it further reinforces my suspicion of the mangled imports and duplicate formatter entries being related: The mangled imports I witnessed had one of the imports being repeated 4 times:

mangled_imports

One thing of note though, this didn’t happen to me on Save or by manually using Organize Imports. It happened when I renamed a symbol in one file and VS Code applied the refactoring to update that symbol in another file. Maybe that somehow triggered all four formatters to kick in, causing the renamed symbol to appear 4 times.

We just published a nightly with a possible fix: https://github.com/biomejs/biome/releases/tag/cli/v1.5.2-nightly.91c7730

It would be great if someone can try it, and let us know.

Still a problem on 1.5.3

Just a note, the command is now biome explain daemon-logs

Hello, just passing by to say it happens all the time, on each new import to be sorted. It have been happening since the day I started using Biome.

Before sort: image

After sort: image

Expected: image

I have Biome 1.9.4 and my VSCode extension is 2.3.0.

Here is an extract of my project settings.json

"editor.defaultFormatter": "biomejs.biome",
"editor.codeActionsOnSave": {
  "source.organizeImports.biome": "always"
},

I just installed the preview version 2024.12.22126 of the vscode extension. The bug seems to be fixed on the example given in this comment.

Congrats on fixing the bug!

This issue still happens to me with biome@1.9.4 and the latest vscode extensions.

It seems that noUnusedImports make it even worst indeed. It would be nice to increase the priority of this issue if possible šŸ™ Thanks for you work on this library, it’s really good !

i run into garbled imports anytime i try to save where i have a regular import and a type import in the same import line

@sshmaxime Did you read my comment? https://github.com/biomejs/biome/issues/1570#issuecomment-2456703582

If you do install the preview release, remember to kill all processes of biome, it’s possible there are few of them hanging.

I hit this issue quite often as well. I had to remove the ā€œsource.organizeImports.biomeā€: ā€œexplicitā€ setting because biome would constantly break my imports.

Just did little refactoring, removing and shuffling around code and so far it worked flawlessly šŸ‘ But that was only about 15 minutes of coding, I’ll report if anything else pops up.

Also I have noUnusedImports on, might make the issue worse.

I noticed that some of the bugs reported are caused by this very rule.