biomejs / biome-vscode

Biome extension for Visual Studio Code and VSCodium
https://marketplace.visualstudio.com/items?itemName=biomejs.biome
Apache License 2.0
230 stars 32 forks source link

πŸ› [PreRelease] Extension "Biome" is configured as formatter but it cannot format 'TypeScript JSX'-files #373

Open raix opened 1 month ago

raix commented 1 month ago

VS Code version

1.93.1

Extension version

2024.9.200949

Biome version

1.9.2

Operating system

Description

Updated Biome from 1.8.3 and VS Code extension to pre-release for better support of workspaces. We currently use a workaround in PlatformPlatform

Steps to reproduce

See: CleanShot 2024-09-30 at 21 39 49

Expected behavior

The document should re format as the CLI tool would do e.g. npm run format

Does this issue occur when using the CLI directly?

No

Link to a minimal reproduction

https://github.com/platformplatform/PlatformPlatform

Logs

2024-09-30 21:23:40.701 [info] Biome extension 2024.9.200949 activated
2024-09-30 21:23:40.701 [info] Biome extension started
2024-09-30 21:23:40.701 [info] User-facing commands registered
2024-09-30 21:23:40.701 [info] Started listening for lockfile changes
2024-09-30 21:23:40.701 [info] Started listening for configuration changes
2024-09-30 21:23:40.701 [info] Started listening for active text editor changes

---

npx biome rage --daemon-logs
CLI:
  Version:                      1.9.2
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v22.8.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/10.8.2"

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

Workspace:
  Open Documents:               0

Discovering running Biome servers...

Incompatible Biome Server: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

β„Ή Rage discovered this running server using an incompatible version of Biome.

Server:
  Version:                      1.8.1

Server:
  Status:                       stopped

Incompatible Biome Server: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

β„Ή Rage discovered this running server using an incompatible version of Biome.

Server:
  Version:                      1.8.2

Incompatible Biome Server: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

β„Ή Rage discovered this running server using an incompatible version of Biome.

Server:
  Version:                      1.8.3

Incompatible Biome Server: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

β„Ή Rage discovered this running server using an incompatible version of Biome.

Server:
  Version:                      1.9.1

Incompatible Biome Server: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

β„Ή Rage discovered this running server using an incompatible version of Biome.

Server:
  Version:                      1.9.0
mkromann commented 1 month ago

Having the same issue this morning

ematipico commented 1 month ago

Thank you, @raix, for the report. However, we would appreciate it if you could create a minimal reproduction instead of providing a massive repository. A minimal reproduction would remove possible user/environment options that could tarnish the project.

To create a reproduction, you can use our new CLI tool, which should help you to create a very quick repository with what you need: npm create @biomejs/biome-reproduction

raix commented 1 month ago

@ematipico I've created and pushed a Minimal reproduction using your CLI tool

nhedger commented 1 month ago

I believe I've found the issue. I'll patch it this morning and release a new pre-release. I'll also update this issue with an explanation.

nhedger commented 1 month ago

New release

I've released a new pre-release version, which I believe fixes this issue.

What happened

When the extension generates a document selector to filter which document should be taken into account by a given LSP session, it uses the path specified in the configuration and appends a glob pattern to it.

${project.path}**/*

When the path contains a trailing /, the glob pattern is valid, but if the path does not contain the trailing /, the glob pattern is invalid, which causes VS Code to say that Biome cannot format the file, as it is ignored.

https://github.com/biomejs/biome-vscode/blob/becbd5a4d05d3edd00d074607c063a6edfa1f976/src/session.ts#L350-L354

Fix

I'm now joining all path elements using Uri, which should gracefully handle all sorts of quirks such as missing or duplicate trailing /.

https://github.com/biomejs/biome-vscode/blob/f9aa11226fd6a940f8dcbf0cb2ac951f894983b7/src/session.ts#L350-L357

nhedger commented 1 month ago

@raix Feel free to close the issue once/if you've been able to confirm that it fixes the issue.

raix commented 1 month ago

@nhedger When testing the VS Code extension version v2024.10.20458 the issue is still there when testing the minimal reproduction repo

nhedger commented 1 month ago

Hum, could you try removing "folder": "application", from your settings. This is meant only for project that use multi-root workspaces. Not sure if this creates another issue.

raix commented 1 month ago

@nhedger if I remove the "folder" setting I get: CleanShot 2024-10-02 at 12 27 43

nhedger commented 1 month ago

I've been trying to reproduce this error and encountered it once or twice, but I cannot find a way to trigger it consistently. Are you able to?

raix commented 1 month ago

@nhedger yes, I never experienced it to work.

Does the extension register for being able to handle TypeScript files?

nhedger commented 1 month ago

Sorry, I meant: are you able to consistently reproduce the error seen in your screenshot?

If so, any information that leads to this error happening would help troubleshooting the issue. Using your reproduction repo and the same OS, I can't seem to reproduce. Wondering if other factors are at play here.

The inability of handling typescript files here is a direct consequence of the extension failing to start properly, but it does work under normal circumstances.

raix commented 1 month ago

Sorry, I meant: are you able to consistently reproduce the error seen in your screenshot?

Yes, I always get the dialog regarding configuring a formatter

If so, any information that leads to this error happening would help troubleshooting the issue. Using your reproduction repo and the same OS, I can't seem to reproduce. Wondering if other factors are at play here.

Not sure what I'm looking for tbh. I've tried reinstalling the extension, restarting VS Code, looking in devtools - all clues have been added to this issue.

Thinking of differences - I do not have biome installed globally, only in the project node_modules folder

The inability of handling typescript files here is a direct consequence of the extension failing to start properly, but it does work under normal circumstances.

The extension seems to be running CleanShot 2024-10-05 at 23 19 46

raix commented 1 month ago

Also get the issue when debugging the extension - I do wonder if active project should be undefined when the tsx file is open/selected etc. CleanShot 2024-10-06 at 00 09 21

raix commented 1 month ago

After debugging the extension I found this to be working:

Findings:

{
  "biome.enabled": true,
  "biome.projects": [
    {
      "path": "application",
-    "folder": "application",
-      "configFile": "biome.json"
+      "configFile": "application/biome.json"
    }
  ],
  "biome.requireConfigFile": true
}

Notes:

nhedger commented 1 month ago

Oh, interesting. I would also have expected that config file to be resolved relative to the path. I'll look into this.

codyspate commented 1 month ago

In case it helps the debugging here's my experience with this issue so far.

I'm on Fedora, experiencing the same issue, but its not just for Typescript-JSX. It seems like its pretty much every file

Linux: Fedora 41 VSCode: 1.94.2 Biome Extension: v2.3.0 (also tried pre-release v2024.10.131712) Biome version: 1.9.3

codyspate commented 1 month ago

^^^ It works after specifying "biome.lspBin": "node_modules/.bin/biome" in the workspace settings

KKhanhH commented 3 days ago

@nhedger I'm also getting the same issue with the extension for one of my workspace folders. It seems to occur regardless of whether the workspace is a multifolder workspace or the subfolder is opened directly. Looking at the LSP Trace, the logs show that the workspace directory has Windows trailing backslashes, and the extension is adding an additional forward slash before looking for the biome.json file.

2024-11-15 11:30:35.394 [info] [Trace - 11:30:35 AM] Received request 'client/registerCapability - (13)'.
2024-11-15 11:30:35.394 [info] Params: {
    "registrations": [
        {
            "id": "biome_did_change_extension_settings",
            "method": "workspace/didChangeConfiguration"
        },
        {
            "id": "biome_range_formatting",
            "method": "textDocument/rangeFormatting"
        },
        {
            "id": "biome_on_type_formatting",
            "method": "textDocument/onTypeFormatting",
            "registerOptions": {
                "documentSelector": null,
                "firstTriggerCharacter": "}",
                "moreTriggerCharacter": [
                    "]",
                    ")"
                ]
            }
        },
        {
            "id": "biome_formatting",
            "method": "textDocument/formatting"
        },
        {
            "id": "biome_did_change_workspace_settings",
            "method": "workspace/didChangeWatchedFiles",
            "registerOptions": {
                "watchers": [
                    {
                        "globPattern": "c:\\Users\\username\\Projects\\project_name\\/biome.json",
                        "kind": 7
                    },
                    {
                        "globPattern": "c:\\Users\\username\\Projects\\project_name\\/biome.jsonc",
                        "kind": 7
                    },
                    {
                        "globPattern": "c:\\Users\\username\\Projects\\project_name\\/.editorconfig",
                        "kind": 7
                    },
                    {
                        "globPattern": "c:\\Users\\username\\Projects\\project_name\\/rome.json",
                        "kind": 7
                    }
                ]
            }
        }
    ]
}
KKhanhH commented 3 days ago

Sorry, ignore what I said previously, I created a minimal repro and the issue isn't caused by a trailing slash it looks like. There seems to be an issue with pnpm workspaces, the extension doesn't detect files inside the packages folder, but it seems to be able to detect files inside .vscode folder and everything else fine.

Here is the repro: https://github.com/KKhanhH/biome_repro