Skip to content

Commit 169745f

Browse files
authored
feat(biome): monorepo support #3972
The biome [documentation](https://biomejs.dev/guides/big-projects/#use-multiple-configuration-files) mentions that > When you use Biome’s features - either with the CLI or LSP - the tool looks for the nearest configuration file using the current working directory. > > If Biome doesn’t find the configuration file there, it starts traversing upwards the directories of the file system, until it finds one. I think it makes sense to follow this recommendation, so we can have proper monorepo support. Currently, in a monorepo, a new client is started for each `biome.json` (similar situation as #3910), which is unnecessary, since biome supports monorepos [natively](https://biomejs.dev/guides/big-projects/#monorepo) (as of v2). The alternatives I have considered aren't as robust. The first concern is searching for a `biome.json` to be set as the root. Unfortunately, that's cumbersome: the documentation recommends flagging the files that _aren't_ the root. That means we _can't_ use `root_markers_with_field` to search for a file that **is** the root. The proposed solution solves this issue by behaving as the CLI would. Secondly, we have to check if a project uses biome, via `package.json` and friends, which is the fallback behavior. I've considered using #3955's approach of lock files, but since it would require searching for the field 'biome' within lock files (which are often thousands of lines long), I was worried about causing a performance hiccup.
1 parent f47cd68 commit 169745f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lsp/biome.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ return {
3434
'vue',
3535
},
3636
workspace_required = true,
37-
root_dir = function(bufnr, on_dir)
38-
local fname = vim.api.nvim_buf_get_name(bufnr)
37+
root_dir = function(_, on_dir)
38+
-- To support monorepos, biome recommends starting the search for the root from cwd
39+
-- https://biomejs.dev/guides/big-projects/#use-multiple-configuration-files
40+
local cwd = vim.fn.getcwd()
3941
local root_files = { 'biome.json', 'biome.jsonc' }
40-
root_files = util.insert_package_json(root_files, 'biome', fname)
41-
local root_dir = vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1])
42+
root_files = util.insert_package_json(root_files, 'biome', cwd)
43+
local root_dir = vim.fs.dirname(vim.fs.find(root_files, { path = cwd, upward = true })[1])
4244
on_dir(root_dir)
4345
end,
4446
}

0 commit comments

Comments
 (0)