biome icon indicating copy to clipboard operation
biome copied to clipboard

πŸ› VS Code extension: Poor support for multi-folder workspaces

Open EvHaus opened this issue 1 year ago β€’ 22 comments

Environment information

CLI:
  Version:                      1.5.2
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v21.1.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "pnpm/8.10.2"

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

Workspace:
  Open Documents:               0

What happened?

I have several "Folders" in my VS Code "Workspace". Like this:

image

Some of those "Folders" are projects that use Biome, and some aren't. Biome's VS Code extension doesn't handle this very gracefully. There are several issues:

Bug 1: First "Folder" in the VS Code "Workspace" must be a Biome project for any others to work

If you order the "Folders" in your "Workspace" such that the top-most one doesn't have Biome installed, none of the files you open in the older "Folders" will run through Biome checks. It seems like the top-most "Folder" must be a Biome project for the Biome VS Code extension to do anything and will instead show this warning:

image

Bug 2: Biome runs on "Folders" that aren't Biome projects

The inverse of Bug 1 also exists, where if the top-most "Folder" is a Biome project, all other "Folders" will get checked by Biome, even if they don't have Biome installed or configured.

Bug 3: Duplicated problems

For every folder with Biome installed, the "Problems" tab shows duplicate Biome errors:

image

Note how each of those problems is the same problem on the same line & column. It's a duplicate.

Expected result

Expectations listed above in each bug

Code of Conduct

  • [X] I agree to follow Biome's Code of Conduct

EvHaus avatar Jan 22 '24 07:01 EvHaus

Our LSP doesn't support workspaces yet. We have a task to implement and support them: https://github.com/biomejs/biome/issues/1573

ematipico avatar Jan 22 '24 07:01 ematipico

Environment information

CLI:
  Version:                      1.5.2
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v21.1.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "pnpm/8.10.2"

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

Workspace:
  Open Documents:               0

What happened?

I have several "Folders" in my VS Code "Workspace". Like this:

image

Some of those "Folders" are projects that use Biome, and some aren't. Biome's VS Code extension doesn't handle this very gracefully. There are several issues:

Bug 1: First "Folder" in the VS Code "Workspace" must be a Biome project for any others to work

If you order the "Folders" in your "Workspace" such that the top-most one doesn't have Biome installed, none of the files you open in the older "Folders" will run through Biome checks. It seems like the top-most "Folder" must be a Biome project for the Biome VS Code extension to do anything and will instead show this warning:

image

Bug 2: Biome runs on "Folders" that aren't Biome projects

The inverse of Bug 1 also exists, where if the top-most "Folder" is a Biome project, all other "Folders" will get checked by Biome, even if they don't have Biome installed or configured.

Bug 3: Duplicated problems

For every folder with Biome installed, the "Problems" tab shows duplicate Biome errors:

image

Note how each of those problems is the same problem on the same line & column. It's a duplicate.

Expected result

Expectations listed above in each bug

Code of Conduct

  • [x] I agree to follow Biome's Code of Conduct

Thank you for opening the issue, I had the same problem.

jonasfroeller avatar Mar 19 '24 16:03 jonasfroeller

Hi, for the time being, could you describe this limitation in https://biomejs.dev/reference/vscode/ (under "Troubleshooting")?

I wasted an hour trying to get my biome.json working in a multi-root workspace where only one root uses Biome (other roots still depend on Prettier). I managed to enable formatting with Biome on save, but biome.json seems to be ignored by the extension (it works just fine when I manually type npx biome format).

Am I right that it's simply impossible to do this for now, and all I can do is set up isolated VSCode workspaces for each my Biome-enabled folder?

smikitky avatar Apr 04 '24 07:04 smikitky

Hi, for the time being, could you describe this limitation in biomejs.dev/reference/vscode (under "Troubleshooting")?

I wasted an hour trying to get my biome.json working in a multi-root workspace where only one root uses Biome (other roots still depend on Prettier). I managed to enable formatting with Biome on save, but biome.json seems to be ignored by the extension (it works just fine when I manually type npx biome format).

Am I right that it's simply impossible to do this for now, and all I can do is set up isolated VSCode workspaces for each my Biome-enabled folder?

Apologies, @smikitky, for the time you wasted. Would you like to send a PR yourself?

ematipico avatar Apr 04 '24 08:04 ematipico

@ematipico I made a PR, hope it helps.

smikitky avatar Apr 04 '24 08:04 smikitky

Hi @ematipico,

Is the documentation added in #2297 still accurate after adding LSP support (#1573)? Would it be more correct to state that the reason it is not working as expected is rather https://github.com/biomejs/biome-vscode/issues/201?

adambenali avatar Aug 05 '24 21:08 adambenali

I am not really sure, to be honest. When I developed the feature, used the Workspace project feature inside VSCode and it worked really well. Is there a different way to set up workspaces in VSCode that I am not aware about? If so, then it makes sense to call it out.

ematipico avatar Aug 06 '24 15:08 ematipico

@ematipico as of today with biome v1.8.3 and biome-vscode v2.3.0:

  • If you set up a workspace with a single application folder where biome.json is at the root, everything works as expected.
  • If e.g. we imagine a project with two folders, frontend and backend and the path to biome.json is frontend/biome.json, then the extension will not read the frontend configuration, and will, instead, use the default configuration.

Not sure what you mean by "worked really well", but yes, it works, just not with the configuration I'm expecting.

adambenali avatar Aug 07 '24 08:08 adambenali

Well, the second scenario isn't a LSP workspace, am I right?

Nested configuration files aren't supported as you would expect. And it's a problem unrelated to the LSP workspaces.

We might be able to solve these kinds of scenarios here:

  • https://github.com/biomejs/biome/issues/2228
  • https://github.com/biomejs/biome/issues/3307

ematipico avatar Aug 07 '24 08:08 ematipico

Next version (v3) of the VS Code extension will have support for multi-root workspaces. Independent LSP sessions will be created for every workspace folder, and the configuration file at the root of each workspace folder will be taken into account, respectively.

nhedger avatar Aug 07 '24 09:08 nhedger

Question: is it possible / would it be possible to configure folders for biome independently from the workspace's folders: setting?

In our monorepo we don't want to list folders separately in the toplevel setting (because it clutters UI in a few places, and finding files by copypasting the full repo-relative path doesn't work, etc). But, with just one toplevel entry in folders, the biome extension doesn't work:

  // no highlights from biome extension
  "folders": [{ "path": ".", "name": "our-project" }],

  // now biome does highlight the errors, but we don't really want to set it for all 20+ workspaces
  "folders": [
    { "path": "packages/foobar" },
    // ... n more entries
    { "path": ".", "name": "our-project" },
  ],

With eslint & jest plugins it is possible to configure folders separately, e.g.

  "settings": {
    "jestrunner.changeDirectoryToWorkspaceRoot": false,
    "jest.virtualFolders": [
      {
        "rootPath": "packages/foobar",
        "name": "foobar tests",
      },
      // ...
    ],
    // eslint plugin is even better as it allows to use patterns too
    "eslint.workingDirectories": [
      { "pattern": "frontend/*", "changeProcessCWD": true },
      { "pattern": "packages/*", "changeProcessCWD": true },
    ],

// edit: unless the answer above means that in the next vesion such a scenario would be supported out of the box?

quezak avatar Aug 29 '24 15:08 quezak

The next version supports multi root workspaces as well as monorepos within a single root workspace. It's currently available in the pre-release channel of the extension. Feel free to try it and don't hesitate to give feedback.

nhedger avatar Aug 29 '24 17:08 nhedger

Feel free to try it and don't hesitate to give feedback.

I can't get the prerelease version to work at all. All I get is this dialog:

Screenshot 2024-08-29 at 10 28 20β€―AM

That dialog also appears many times when I click "No". Maybe it's showing up once for every folder in my workspace? I don't want to install Biome globally, so I always press "No" there.

In the workspace folder that does have Biome installed, it doesn't work.

My VS Code workspace looks like this:

Screenshot 2024-08-29 at 10 31 29β€―AM

EvHaus avatar Aug 29 '24 17:08 EvHaus

That dialog also appears many times when I click "No". Maybe it's showing up once for every folder in my workspace? I don't want to install Biome globally, so I always press "No" there.

Ah, good catch ! I'll see what we can do about that !

In the workspace folder that does have Biome installed, it doesn't work.

My VS Code workspace looks like this:

You can disable biome by default by setting biome.enabled to false (it's true by default). You can do this either in your user settings, or in the settings field of your .code-workspace file if you have one.

Then to enable the extension only for the reservesense workspace folder, override the biome.enabled to true in your .vscode/settings.json file.

If the extension still fails to detect Biome, please open the output panel and select Biome so we can see the logs. Hopefully this will help us identify the issue.

nhedger avatar Aug 29 '24 18:08 nhedger

I tried following those steps, but Biome still doesn't run and the Output panel simply shows:

2024-08-29 21:54:02.360 [info] 
2024-08-29 21:54:02.360 [info] Biome extension activated
2024-08-29 21:54:08.526 [error] Could not find the Biome binary

It would be helpful if it could log out the path where it's trying to search for the binary. I'm not sure why it can't find it.

EvHaus avatar Aug 30 '24 04:08 EvHaus

Could you set the log level to Debug and reload the window?

Command palette: Developer: Set log level...

Then paste the whole output here.

nhedger avatar Aug 30 '24 08:08 nhedger

Hmm, not much more info in Debug mode:

2024-08-30 20:38:27.546 [info] Biome extension activated
2024-08-30 20:38:31.371 [error] Could not find the Biome binary
2024-08-30 20:38:31.371 [warning] Could not create global session
2024-08-30 20:38:31.372 [info] Biome extension started
2024-08-30 20:38:31.372 [info] User-facing commands registered
2024-08-30 20:38:31.372 [info] Started listening for lockfile changes
2024-08-30 20:38:31.372 [info] Started listening for configuration changes
2024-08-30 20:38:31.372 [info] Started listening for active text editor changes

EvHaus avatar Aug 31 '24 03:08 EvHaus

The next version supports multi root workspaces as well as monorepos within a single root workspace. It's currently available in the pre-release channel of the extension. Feel free to try it and don't hesitate to give feedback.

I'm also experiencing something similar with a multi folder workspace. I used the pre release version of the plugin ( v2024.8.301002 ), but it still doesn't seem to respect the biome.json if it is not in the root level.

If I run biome format --write ./ in the non root folder/package where the biome.json is present the config is respected, the moment I try and edit something manually on a .ts file the default formatting settings take over through the plugin and not the ones in biome.json

Now If I move the biome.json to the root of the project both the plugin and the command respect the config, as is expected.

DGiannaris avatar Aug 31 '24 14:08 DGiannaris

The next version supports multi root workspaces as well as monorepos within a single root workspace. It's currently available in the pre-release channel of the extension. Feel free to try it and don't hesitate to give feedback.

Thanks @nhedger! Is there some special config I need to apply? It seems to work same as I described above your answer:

// workspace settings
  "folders": [
    { "path": ".", "name": "ourproject" },
  ],

// biome output
2024-09-02 13:14:26.232 [info] Biome extension activated
2024-09-02 13:14:26.441 [info] Biome extension stopped
2024-09-02 13:14:34.667 [error] Could not find the Biome binary
2024-09-02 13:14:34.667 [warning] Could not create global session
2024-09-02 13:09:25.817 [info] Copying binary to temporary location.
	original=<REPO_ROOT>/node_modules/@biomejs/cli-darwin-arm64/biome
	destination=/Users/quezak/Library/Application Support/Code - Insiders/User/globalStorage/biomejs.biome/tmp-bin/biome-1.8.3
2024-09-02 13:14:35.078 [info] Created session for project.
	project=/
2024-09-02 13:14:35.078 [info] Biome extension started
2024-09-02 13:14:35.078 [info] User-facing commands registered
2024-09-02 13:14:35.078 [info] Started listening for lockfile changes
2024-09-02 13:14:35.078 [info] Started listening for configuration changes
2024-09-02 13:14:35.078 [info] Started listening for active text editor changes

➑️ ❌ no biome errors in editor

// workspace settings
  "folders": [
    { "path": "packages/backend-common", "name": "backend-common" },
    { "path": ".", "name": "ourproject" },
  ],

// biome output
2024-09-02 13:09:25.782 [error] Could not find the Biome binary
2024-09-02 13:09:25.783 [warning] Could not create global session
2024-09-02 13:30:22.465 [info] Copying binary to temporary location.
	original=<REPO_ROOT>/node_modules/@biomejs/cli-darwin-arm64/biome
	destination=/Users/quezak/Library/Application Support/Code - Insiders/User/globalStorage/biomejs.biome/tmp-bin/biome-1.8.3
2024-09-02 13:09:26.223 [info] Created session for project.
	project=backend-common::/
2024-09-02 13:09:26.238 [info] Created session for project.
	project=ourproject::/
2024-09-02 13:09:26.238 [info] Biome extension restarted

➑️ biome errors are visible in editor

Note that the created session log says project=ourproject::/ (name redacted from actual project name), as opposed to project=/ in the first section, despite the folders: settings entry for the root repo directory was not changed πŸ€”


I've also tried to set various combinations of path & folder options in settings.biome.projects, but with no success (sorry, couldn't find docs how to set them correctly so it was trial and error πŸ˜…)

// workspace settings, trying out with just one package to see if it has any effect
  "folders": [{ "path": ".", "name": "ourproject" }],
    "biome.projects": [
      { "path": "packages/backend-common" },
    ],

// biome output
2024-09-02 13:30:18.642 [info] Configuration change detected.
2024-09-02 13:30:22.416 [error] Could not find the Biome binary
2024-09-02 13:30:22.417 [warning] Could not create global session
2024-09-02 13:30:22.465 [info] Copying binary to temporary location.
	original=<REPO_ROOT>/node_modules/@biomejs/cli-darwin-arm64/biome
	destination=/Users/quezak/Library/Application Support/Code - Insiders/User/globalStorage/biomejs.biome/tmp-bin/biome-1.8.3
2024-09-02 13:30:22.899 [info] Created session for project.
	project=/packages/backend-common
2024-09-02 13:30:22.899 [info] Biome extension restarted

➑️ ❌ no biome errors in editor


For additional info, here's our repo structure:

  • packages/* configured as yarn workspaces (plus a few other dirs)
  • common biome.jsonc in repo root, extended by packages/biome.json via extends: ..., which in turn gets extended in some packages by package/.../biome.jsonc

quezak avatar Sep 02 '24 11:09 quezak

Update with working settings in comment directly following this one https://github.com/biomejs/biome/issues/1630#issuecomment-2738553634

I'm wondering what folks should expect with multi-folder workspaces going forward. Based on some recent issue comments:

  • https://github.com/biomejs/biome-vscode/issues/513#issuecomment-2692754037
  • https://github.com/biomejs/biome/issues/5089#issuecomment-2690968039

It sounds like things are moving away from being able to specify a config file per sub-folder inside a workspace (unless I am misreading these comments).

This would be a significant change for us, since our setup uses separate unique biome config files per subfolder (something like this example):

Tree:

biomeExample
β”œβ”€β”€ biomeExample.code-workspace
└── services
    β”œβ”€β”€ service1
    β”‚Β Β  β”œβ”€β”€ biome_1.jsonc
    β”‚Β Β  β”œβ”€β”€ package.json
    β”‚Β Β  └── yarn.lock
    └── service2
        β”œβ”€β”€ biome_2.jsonc
        β”œβ”€β”€ package.json
        └── yarn.lock

workspace settings:

{
    "folders": [
        {
            "name": "root",
            "path": ".",
        },
        {
            "name": "service1",
            "path": "services/service1"
        },
        {
            "name": "service2",
            "path": "services/service2"
        },
    ],
    "settings": {
        "[javascript][javascriptreact][typescript][typescriptreact]": {
            "editor.defaultFormatter": "biomejs.biome",
            "javascript.preferences.quoteStyle": "single",
        },
        "biome.requireConfigFile": true,
        "biome.projects": [
            {
                "folder": "service1",
                "path": ".",
                "configFile": "./biome_1.jsonc"
            },
            {
                "folder": "service2",
                "path": ".",
                "configFile": "./biome_2.jsonc"
            }
        ]
    },
}

The above currently mostly works with the pre-release Biome vscode extension, with some nuance. It looks like when the biome servers start for each "project", only one config file is discovered and used:

β”œβ”€ INFO biome_lsp::server Starting Biome Language Server...
β”œβ”€ WARN biome_lsp::server The Biome Server was initialized with the deprecated `root_path` parameter: this is not supported, use `root_uri` instead
β”œβ”€ INFO biome_lsp::server Attempting to load the configuration from 'biome.json' file

*****
* Note how `biome_1.jsonc` is loaded:
*****

└─┐biome_fs::fs::os::OsFileSystem::open_with_options{path="/Users/nickhaury/git/biomeExample/services/service1/biome_1.jsonc", options=OpenOptions { read: true, write: false, truncate: false, create: false, create_new: false }}
β”Œβ”€β”˜
└─┐biome_fs::fs::os::OsFile::read_to_string{}
β”Œβ”€β”˜
└─┐biome_json_parser::parse{}
β”Œβ”€β”˜
β”œβ”€ INFO biome_lsp::session Configuration loaded successfully from disk.
β”œβ”€ INFO biome_lsp::session Update workspace settings.
β”œβ”€ DEBUG biome_service::workspace::server Compare the current project with the new one None Some("/Users/nickhaury/git/biomeExample/services/service1") true

*****
* Note how the service path is the expected /services/service1:
*****

└─┐biome_fs::fs::os::OsFileSystem::open_with_options{path="/Users/nickhaury/git/biomeExample/services/service1/package.json", options=OpenOptions { read: true, write: false, truncate: false, create: false, create_new: false }}
...
β”œβ”€ INFO biome_lsp::server Starting Biome Language Server...
β”œβ”€ WARN biome_lsp::server The Biome Server was initialized with the deprecated `root_path` parameter: this is not supported, use `root_uri` instead
β”œβ”€ INFO biome_lsp::server Attempting to load the configuration from 'biome.json' file

*****
* Note how `biome_1.jsonc` is loaded once again instead of `biome_2.jsonc`:
*****

└─┐biome_fs::fs::os::OsFileSystem::open_with_options{path="/Users/nickhaury/git/biomeExample/services/service1/biome_1.jsonc", options=OpenOptions { read: true, write: false, truncate: false, create: false, create_new: false }}
β”Œβ”€β”˜
└─┐biome_fs::fs::os::OsFile::read_to_string{}
β”Œβ”€β”˜
└─┐biome_json_parser::parse{}
β”Œβ”€β”˜
β”œβ”€ INFO biome_lsp::session Configuration loaded successfully from disk.
β”œβ”€ INFO biome_lsp::session Update workspace settings.
β”œβ”€ DEBUG biome_service::workspace::server Compare the current project with the new one None Some("/Users/nickhaury/git/biomeExample/services/service1") true

*****
* Note how the service path is /services/service2:
*****

└─┐biome_fs::fs::os::OsFileSystem::open_with_options{path="/Users/nickhaury/git/biomeExample/services/service2/package.json", options=OpenOptions { read: true, write: false, truncate: false, create: false, create_new: false }}

Based on this, it seems like potentially we would be required to change up our workflow to either rely on a single biome configuration for all sub-services, or we'd need to make separate workspaces for each sub-service.

Just trying to get some sense of how the direction of Biome and the VSCode extension is going so we can plan accordingly if we want to continue to use Biome.

For the time being since we've only implemented using Biome for ~3 services, we are using a workaround where we install different patch versions of Biome in each sub-service (so one has 1.9.4, one has 1.9.3, etc.). This makes one server run per version, and in this case each service is able to use it's own configuration file. Obviously this will not scale as more services are added, so we'll need a longer term solution in place at some point.

Appreciate any insight that can be shared πŸ™‚

nicksama88 avatar Mar 16 '25 00:03 nicksama88

Wanted to give an update to the comment I made just above ^ in https://github.com/biomejs/biome/issues/1630#issuecomment-2727093131

Using the following setup:

  • Biome 1.9.4 installed in each service sub-folder
  • 2025.3.151143 VSCode extension pre-release version
  • MAC M1 14.6.1

the biome extension is now working for our workspace, including handling individual biome.json[c] configuration files appropriately, with the following caveats:

  • either
    • the path setting must not be used in the workspace biome.projects settings (folder setting appears to not cause issues, but also appears to be unnecessary now)
    • the biome.projects workspace setting must be removed entirely.
  • we must use "biome.requireConfigFile": true, which is preferred for our workspace anyway
  • custom names for the biome.json[c] are no longer supported, since the configFile workspace setting was removed (which is not a problem considering the crawler responsible for finding the necessary config file is doing it's job)

This means, at least for our specific monorepo multi-folder workspace project, the extension is now working with less configuration needed, which is nice.

nicksama88 avatar Mar 19 '25 23:03 nicksama88

Bringing back custom config paths is tracked in #5089

siketyan avatar Mar 20 '25 05:03 siketyan

Adding some caveats, it seems Ctrl + P then reload window, reset the extension and ignore the biome.json from every workspace... Did what @nicksama88 explained and it works 1 time before, it "reset", file not found

solimanbali-omedo avatar Apr 29 '25 10:04 solimanbali-omedo