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

🐛 Multiple entries in the list of formatters #1584

Closed
momargoh opened this issue Jan 15, 2024 · 25 comments · Fixed by #1590
Closed

🐛 Multiple entries in the list of formatters #1584

momargoh opened this issue Jan 15, 2024 · 25 comments · Fixed by #1590
Assignees
Labels
A-LSP Area: language server protocol S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@momargoh
Copy link

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.

@nhedger
Copy link
Member

nhedger commented Jan 15, 2024

Hey,

Thanks for opening this issue.

Could you provide a reproduction?

@momargoh
Copy link
Author

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?

@nhedger
Copy link
Member

nhedger commented Jan 15, 2024

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

@iamchanii
Copy link

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 :)

@Levieber
Copy link
Contributor

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

@nhedger nhedger self-assigned this Jan 17, 2024
@Levieber
Copy link
Contributor

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.

@nhedger
Copy link
Member

nhedger commented Jan 17, 2024

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

@arendjr
Copy link
Contributor

arendjr commented Jan 17, 2024

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?

@nhedger
Copy link
Member

nhedger commented Jan 17, 2024

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

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

@nhedger
Copy link
Member

nhedger commented Jan 17, 2024

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 ?

@arendjr
Copy link
Contributor

arendjr commented Jan 17, 2024

What happens if you reload the window ?

It reverted to having only 1.

@arendjr
Copy link
Contributor

arendjr commented Jan 17, 2024

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...

@nhedger
Copy link
Member

nhedger commented Jan 17, 2024

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

@nhedger nhedger transferred this issue from biomejs/biome-vscode Jan 17, 2024
@nhedger nhedger added the A-LSP Area: language server protocol label Jan 17, 2024
@momargoh
Copy link
Author

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```

@arendjr
Copy link
Contributor

arendjr commented Jan 17, 2024

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.

@nhedger
Copy link
Member

nhedger commented Jan 17, 2024

@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.

@arendjr
Copy link
Contributor

arendjr commented Jan 17, 2024

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...

@ematipico
Copy link
Member

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

@nhedger
Copy link
Member

nhedger commented Jan 18, 2024

As suspected, reverting #1104 fixes it for me.

I'm yet to investigate why exactly that happens.

@ematipico
Copy link
Member

Maybe both dynamic and static registrations go in conflict?

@nhedger
Copy link
Member

nhedger commented Jan 18, 2024

That would be my guess, too.

@nhedger
Copy link
Member

nhedger commented Jan 18, 2024

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

@nhedger nhedger changed the title multiple entries in list of formatters 🐛 Multiple entries in list of formatters Jan 18, 2024
@nhedger nhedger changed the title 🐛 Multiple entries in list of formatters 🐛 Multiple entries in the list of formatters Jan 18, 2024
@nhedger nhedger added the S-Bug-confirmed Status: report has been confirmed as a valid bug label Jan 18, 2024
@ematipico
Copy link
Member

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.

@SpasiboKojima
Copy link

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?

@ematipico
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LSP Area: language server protocol S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants