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

🐛 VS Code extension: Poor support for multi-folder workspaces #1630

Open
1 task done
EvHaus opened this issue Jan 22, 2024 · 19 comments
Open
1 task done

🐛 VS Code extension: Poor support for multi-folder workspaces #1630

EvHaus opened this issue Jan 22, 2024 · 19 comments

Comments

@EvHaus
Copy link

EvHaus commented Jan 22, 2024

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

  • I agree to follow Biome's Code of Conduct
@ematipico
Copy link
Member

Our LSP doesn't support workspaces yet. We have a task to implement and support them: #1573

@jonasfroeller
Copy link

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

  • I agree to follow Biome's Code of Conduct

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

@smikitky
Copy link
Contributor

smikitky commented Apr 4, 2024

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?

@ematipico
Copy link
Member

ematipico commented Apr 4, 2024

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?

@smikitky
Copy link
Contributor

smikitky commented Apr 4, 2024

@ematipico I made a PR, hope it helps.

@adambenali
Copy link

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 biomejs/biome-vscode#201?

@ematipico
Copy link
Member

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.

@adambenali
Copy link

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

@ematipico
Copy link
Member

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:

@nhedger
Copy link
Member

nhedger commented Aug 7, 2024

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.

@quezak
Copy link

quezak commented Aug 29, 2024

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?

@nhedger
Copy link
Member

nhedger commented Aug 29, 2024

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.

@EvHaus
Copy link
Author

EvHaus commented Aug 29, 2024

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

@nhedger
Copy link
Member

nhedger commented Aug 29, 2024

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.

@EvHaus
Copy link
Author

EvHaus commented Aug 30, 2024

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.

@nhedger
Copy link
Member

nhedger commented Aug 30, 2024

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

Command palette: Developer: Set log level...

Then paste the whole output here.

@EvHaus
Copy link
Author

EvHaus commented Aug 31, 2024

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

@DGiannaris
Copy link

DGiannaris commented Aug 31, 2024

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.

@quezak
Copy link

quezak commented Sep 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants