biomejs/biome

๐Ÿ› Multiple entries in the list of formatters

Closed this issue ยท 26 comments

what happened

  1. Install Biome VSCode extension v2.1.1 in a devcontainer and put it in devcontainer extensions to be auto-installed.
  2. Open preferences (Cmd+Shift+P), "format document with..." -> Biome appears twice in the list.
  3. Rebuild the devcontainer -> Biome appears another two times every time I rebuild

what is expected

Biome VSCode extension should only appear once in the list of formatters and should not increase every time the devcontainer is rebuilt.

Hey,

Thanks for opening this issue.

Could you provide a reproduction?

Hi there! What do you need for a "reproduction"? Do you mean like a list of info about the environment it's running in, or do you mean like a hosted vscode instance showing the bug?

Sorry, should have been more clear.

ideally a repo that contains a dev container in which you install the extension.

Iโ€™d like to try and reproduce the behaviour.

thanks

Hi @nhedger and I think this is very similar with my case. I don't use VSCode DevContainer. I'm just try to use Biome as a formatter via extensions and sometimes biome's formating is strange. I guess each extension instances are trying format.

image

Here is my vscode information:

Version: 1.85.1 (Universal)
Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
Date: 2023-12-13T09:48:06.308Z (1 mo ago)
Electron: 25.9.7
ElectronBuildId: 25551756
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 23.1.0

Biome Extension version is v2.1.1. IMO, I think it cannot produce a reproduction sample because it is not related with user's workspace. but if you need any information, I'm ready to respond :)

Same issue here with extension version 2.1.1

Multiple biome formatter entry

CLI:
  Version:                      1.5.1
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           windows

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         unset
  JS_RUNTIME_VERSION:           "v20.11.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "pnpm/8.14.1"

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

Workspace:
  Open Documents:               0

In version 1.2.2, apparently the extension only has one entry. All versions more recent than this one have this problem, but I couldn't test it on versions 1.4.x, because it was giving an error.

This issue might lie with the underlying biome binary, and not with the VS Code extension.

I've successfully reproduced the issue where multiple formatters are shown in the "Format document with..." action.

In my tests, I've used the latest Biome VS Code extension (2.1.1).

Reproduction

To reproduce, I've ran the tests against the codebase of the extension:

  1. clone git@github.com:biomejs/biome-vscode.git
  2. install dependencies with pnpm install
  3. open biome.json file to trigger the extension
  4. Open command palette
  5. Select Format document with...
  6. Count the number of Biome (default) entries

Biome CLI (1.4.1)

A single Biome (default) entry appears

Biome CLI (1.5.0)

Two Biome (default) entries appear

Biome CLI (1.5.1)

Two Biome (default) entries appear

Biome CLI (1.5.2)

Two Biome (default) entries appear

Screen.Recording.2024-01-17.at.14.21.22.webm

I've just noticed it too in a VS Code window I've had open the entire day now. There's 3 Biome entries in my Format document with... list. However, this workspace is configured with an older Biome version (1.3.3). I am using the latest published extension (2.1.1).

I am absolutely positive that when I checked earlier today there was only a single entry. So I suspect there is some event that may happen that will trigger additional entries to appear. Could it have been a server crash?

I'm almost positive this was introduced by #1104.

Also, the extension does not register a formatting provider itself.

I've just noticed it too in a VS Code window I've had open the entire day now. There's 3 Biome entries in my Format document with... list. However, this workspace is configured with an older Biome version (1.3.3). I am using the latest published extension (2.1.1).

I am absolutely positive that when I checked earlier today there was only a single entry. So I suspect there is some event that may happen that will trigger additional entries to appear. Could it have been a server crash?

What happens if you reload the window ?

What happens if you reload the window ?

It reverted to having only 1.

Also, the extension does not register a formatting provider itself.

So if it's the daemon doing the registering, couldn't a crash explain the behavior? Since it will get restarted and the new instance will register itself too? But then the question is, who is responsible for cleaning up crashed instances? They can't do that themselves...

I'd have to do more tests. I immediately see two entries when the extension starts.

Apologies for the late reply. Here's my biome rage output. For me reloading the window resets the list to 2 entries, which is the minimum.

  Version:                      1.5.1
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.10.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/10.2.3"

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

Workspace:
  Open Documents:               0```

Just now I had again 3 formatter entries, and one thing I do notice is that I sometimes I also get a message from VS Code saying it cannot connect to the Biome daemon. It's not often, and when it happened earlier today I checked and there was still only one formatter entry. But just now it happened again, and then there were three. I cannot say it's the cause, but it is something suspicious.

I can see the following extension log inside VS Code:

Biome binary found at /home/arendjr/Projects/monofiber/node_modules/@biomejs/cli-linux-x64/biome
Copying binary to temporary folder: file:///home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
Executing Biome from: /home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
[cli-stdout] data 24
[cli] exit 0
Connecting to "/tmp/biome-socket-1.3.3" ...
[Info  - 7:25:08 PM] Server initialized with PID: 2770276
Reloading biome executable.
Biome binary found at /home/arendjr/Projects/monofiber/node_modules/@biomejs/cli-linux-x64/biome
[cli-stderr] end
[cli-stderr] finish
[cli-stderr] close
[cli-stdout] end
[cli-stdout] finish
[cli] close 0
[cli-stdout] close
Copying binary to temporary folder: file:///home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
Executing Biome from: /home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
[cli-stdout] data 24
[cli] exit 0
Connecting to "/tmp/biome-socket-1.3.3" ...
[Info  - 7:31:06 PM] Server initialized with PID: 2777362
Reloading biome executable.
Reloading biome executable.
Biome binary found at /home/arendjr/Projects/monofiber/node_modules/@biomejs/cli-linux-x64/biome
Biome binary found at /home/arendjr/Projects/monofiber/node_modules/@biomejs/cli-linux-x64/biome
Copying binary to temporary folder: file:///home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
[cli-stderr] end
[cli-stderr] finish
[cli-stdout] end
[cli-stdout] finish
[cli-stdout] close
[cli] close 0
[cli-stderr] close
Copying binary to temporary folder: file:///home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
Error copying file: EntryNotFound (FileSystemError): Unable to delete nonexistent file '/home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome'
Executing Biome from: /home/arendjr/Projects/monofiber/node_modules/@biomejs/cli-linux-x64/biome
Executing Biome from: /home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
[cli-stdout] data 24
[cli] exit 0
[cli-stdout] data 24
[cli-stdout] end
[cli-stdout] finish
[cli-stderr] end
[cli-stderr] finish
[cli] exit 0
Connecting to "/tmp/biome-socket-1.3.3" ...
[cli-stderr] close
[cli] close 0
[cli-stdout] close
[Info  - 7:31:44 PM] Server initialized with PID: 2777766
Reloading biome executable.
Biome binary found at /home/arendjr/Projects/monofiber/node_modules/@biomejs/cli-linux-x64/biome
[cli-stderr] end
[cli-stderr] finish
[cli-stderr] close
[cli-stdout] end
Connecting to "/tmp/biome-socket-1.3.3" ...
[cli-stdout] finish
[Error - 7:31:45 PM] Biome client: couldn't create connection to server.
Error: connect ECONNREFUSED /tmp/biome-socket-1.3.3
	at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
Reloading client failed: Error: Could not connect to the Biome server at "/tmp/biome-socket-1.3.3": connect ECONNREFUSED /tmp/biome-socket-1.3.3
[cli] close 0
[cli-stdout] close
Copying binary to temporary folder: file:///home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
Executing Biome from: /home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
[cli-stdout] data 24
[cli] exit 0
Reloading biome executable.
Biome binary found at /home/arendjr/Projects/monofiber/node_modules/@biomejs/cli-linux-x64/biome
Copying binary to temporary folder: file:///home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
Executing Biome from: /home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
[cli-stdout] data 24
Reloading biome executable.
Biome binary found at /home/arendjr/Projects/monofiber/node_modules/@biomejs/cli-linux-x64/biome
Copying binary to temporary folder: file:///home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
[cli-stderr] end
[cli-stderr] finish
[cli-stdout] end
[cli-stdout] finish
[cli] exit 0
Connecting to "/tmp/biome-socket-1.3.3" ...
[cli-stdout] close
[cli] close 0
[cli-stderr] close
[Info  - 7:31:45 PM] Server initialized with PID: 2777809
Executing Biome from: /home/arendjr/.config/Code/User/workspaceStorage/27f9d18133d60f7c90f1954460f241d6/biomejs.biome/biome
[cli-stdout] data 24
[cli-stderr] end
[cli-stderr] finish
[cli-stderr] close
[cli-stdout] end
[cli-stdout] finish
[cli] exit 0
Connecting to "/tmp/biome-socket-1.3.3" ...
[cli] close 0
[cli-stdout] close
[Info  - 7:31:45 PM] Server initialized with PID: 2777809
Connecting to "/tmp/biome-socket-1.3.3" ...
[Info  - 7:31:46 PM] Server initialized with PID: 2777809

As you can see the server does seem to restart every now and then, though the log doesn't say why unfortunately.

@arendjr the client reloads when a change is detected in a lockfile.

We do this to handle the user updating the @biomejs/biome package via the cli.

Hmm, so I just tried touch yarn.lock a whole bunch of times, and indeed it reloaded many times. Still have only one formatter entry though, so no dice...

I think the issue may be related to where we create the socket.

It's the only change related to the VSCode extension and the LSP that I could think of: #1238

As suspected, reverting #1104 fixes it for me.

I'm yet to investigate why exactly that happens.

Maybe both dynamic and static registrations go in conflict?

That would be my guess, too.

Alright, so using the advertised client capabilities, I've conditionally registered the providers statically. I'll send a PR.

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.

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.

I still have it in v.1.8.3, and I think I had it all along this year, is there anything else that can be done?

We just published a nightly with a possible fix: cli (release)
It would be great if someone can try it, and let us know.

I still have it in v.1.8.3, and I think I had it all along this year, is there anything else that can be done?

OP and other people haven't replied in long time, so we assumed everything was fixed. I suggest you to create a new issue with a reproduction, and we can look into it.

We just published a nightly with a possible fix: cli (release)
It would be great if someone can try it, and let us know.

I still have it in v.1.8.3, and I think I had it all along this year, is there anything else that can be done?

OP and other people haven't replied in long time, so we assumed everything was fixed. I suggest you to create a new issue with a reproduction, and we can look into it.

I have the same problem in the 1.8.4 nightly build (and earlier versions too). I don't know under what conditions it occurs. This issue causes the code to become corrupted when auto-saving in VSCode. Sometimes it breaks the import statements, sometimes it breaks the middle of the code, etc.

However, whenever this problem occurs, there are "always" multiple formatter instances running. (It seems like a conflict between multiple biome extension clients.)

My running environment is Windows 11 Pro (23H2) and my biome settings are:

{ "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", "files": { "include": [ "./sources/**/*.ts", "./sources/**/*.js", "./sources/**/*.graphql", "./scripts/**/*.ts", "./scripts/**/*.js", "./**/*.json" ] }, "formatter": { "enabled": true, "formatWithErrors": false, "indentStyle": "space", "indentWidth": 2, "lineEnding": "lf", "lineWidth": 80, "attributePosition": "auto" }, "organizeImports": { "enabled": true }, "linter": { "enabled": true, "rules": { "recommended": true, "complexity": { "noStaticOnlyClass": "off" }, "correctness": { "noUnusedVariables": "error", "useArrayLiterals": "error" }, "style": { "useBlockStatements": "error", "useConsistentArrayType": "error", "useForOf": "error", "useShorthandAssign": "error" } } }, "overrides": [ { "include": [ "./sources/common/generations/**/*.ts", "./scripts/tests/**/*.ts" ], "linter": { "rules": { "complexity": { "noBannedTypes": "off" }, "suspicious": { "noExplicitAny": "off" } } } } ], "javascript": { "formatter": { "jsxQuoteStyle": "double", "quoteProperties": "asNeeded", "trailingCommas": "all", "semicolons": "always", "arrowParentheses": "always", "bracketSpacing": true, "bracketSameLine": false, "quoteStyle": "single", "attributePosition": "auto" } } }