aboutsummaryrefslogtreecommitdiffstats
path: root/lsp/biome.lua
diff options
context:
space:
mode:
authorIgor Lacerda <igorlfs@ufmg.br>2025-07-23 22:36:25 -0300
committerGitHub <noreply@github.com>2025-07-23 18:36:25 -0700
commit169745f176f58becad80363c3f8f2315ed6bb365 (patch)
treee0e78072b365cf70cd44483e660d7bb88cd4144a /lsp/biome.lua
parentfix(svelte): use augroup to avoid creating multiple autocmds #3964 (diff)
downloadnvim-lspconfig-169745f176f58becad80363c3f8f2315ed6bb365.tar
nvim-lspconfig-169745f176f58becad80363c3f8f2315ed6bb365.tar.gz
nvim-lspconfig-169745f176f58becad80363c3f8f2315ed6bb365.tar.bz2
nvim-lspconfig-169745f176f58becad80363c3f8f2315ed6bb365.tar.lz
nvim-lspconfig-169745f176f58becad80363c3f8f2315ed6bb365.tar.xz
nvim-lspconfig-169745f176f58becad80363c3f8f2315ed6bb365.tar.zst
nvim-lspconfig-169745f176f58becad80363c3f8f2315ed6bb365.zip
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.
Diffstat (limited to 'lsp/biome.lua')
-rw-r--r--lsp/biome.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/lsp/biome.lua b/lsp/biome.lua
index f1087a4d..d58ae46f 100644
--- a/lsp/biome.lua
+++ b/lsp/biome.lua
@@ -34,11 +34,13 @@ return {
'vue',
},
workspace_required = true,
- root_dir = function(bufnr, on_dir)
- local fname = vim.api.nvim_buf_get_name(bufnr)
+ root_dir = function(_, on_dir)
+ -- To support monorepos, biome recommends starting the search for the root from cwd
+ -- https://biomejs.dev/guides/big-projects/#use-multiple-configuration-files
+ local cwd = vim.fn.getcwd()
local root_files = { 'biome.json', 'biome.jsonc' }
- root_files = util.insert_package_json(root_files, 'biome', fname)
- local root_dir = vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1])
+ root_files = util.insert_package_json(root_files, 'biome', cwd)
+ local root_dir = vim.fs.dirname(vim.fs.find(root_files, { path = cwd, upward = true })[1])
on_dir(root_dir)
end,
}