Skip to content

Commit ec54d14

Browse files
authored
fix: ts/js LSPs require lockfile #4062
Problem: Some projects don't have a lockfile. Solution: - Fallback to ".git" as a lower-priority root-marker (Nvim 0.11.3+). - Fallback to CWD.
1 parent c8b90ae commit ec54d14

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

lsp/biome.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ return {
4646
-- manager lock file.
4747
local root_markers = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock', 'deno.lock' }
4848
-- Give the root markers equal priority by wrapping them in a table
49-
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers } or root_markers
50-
local project_root = vim.fs.root(bufnr, root_markers)
51-
if not project_root then
52-
return
53-
end
49+
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers, { '.git' } }
50+
or vim.list_extend(root_markers, { '.git' })
51+
-- We fallback to the current working directory if no project root is found
52+
local project_root = vim.fs.root(bufnr, root_markers) or vim.fn.getcwd()
5453

5554
-- We know that the buffer is using Biome if it has a config file
5655
-- in its directory tree.

lsp/eslint.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,10 @@ return {
9393
-- manager lock file.
9494
local root_markers = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock', 'deno.lock' }
9595
-- Give the root markers equal priority by wrapping them in a table
96-
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers } or root_markers
97-
local project_root = vim.fs.root(bufnr, root_markers)
98-
if not project_root then
99-
return
100-
end
96+
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers, { '.git' } }
97+
or vim.list_extend(root_markers, { '.git' })
98+
-- We fallback to the current working directory if no project root is found
99+
local project_root = vim.fs.root(bufnr, root_markers) or vim.fn.getcwd()
101100

102101
-- We know that the buffer is using ESLint if it has a config file
103102
-- in its directory tree.

lsp/svelte.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ return {
1414
cmd = { 'svelteserver', '--stdio' },
1515
filetypes = { 'svelte' },
1616
root_dir = function(bufnr, on_dir)
17-
local root_files = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock', 'deno.lock' }
1817
local fname = vim.api.nvim_buf_get_name(bufnr)
1918
-- Svelte LSP only supports file:// schema. https://github.com/sveltejs/language-tools/issues/2777
2019
if vim.uv.fs_stat(fname) ~= nil then
21-
on_dir(vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1]))
20+
local root_markers = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock', 'deno.lock' }
21+
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers, { '.git' } }
22+
or vim.list_extend(root_markers, { '.git' })
23+
-- We fallback to the current working directory if no project root is found
24+
local project_root = vim.fs.root(bufnr, root_markers) or vim.fn.getcwd()
25+
on_dir(project_root)
2226
end
2327
end,
2428
on_attach = function(client, bufnr)

lsp/ts_ls.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ return {
6060
-- manager lock file.
6161
local root_markers = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock', 'deno.lock' }
6262
-- Give the root markers equal priority by wrapping them in a table
63-
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers } or root_markers
64-
local project_root = vim.fs.root(bufnr, root_markers)
65-
if not project_root then
66-
return
67-
end
63+
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers, { '.git' } }
64+
or vim.list_extend(root_markers, { '.git' })
65+
-- We fallback to the current working directory if no project root is found
66+
local project_root = vim.fs.root(bufnr, root_markers) or vim.fn.getcwd()
6867

6968
on_dir(project_root)
7069
end,

lsp/tsgo.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ return {
3232
-- manager lock file.
3333
local root_markers = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock', 'deno.lock' }
3434
-- Give the root markers equal priority by wrapping them in a table
35-
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers } or root_markers
36-
local project_root = vim.fs.root(bufnr, root_markers)
37-
if not project_root then
38-
return
39-
end
35+
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers, { '.git' } }
36+
or vim.list_extend(root_markers, { '.git' })
37+
-- We fallback to the current working directory if no project root is found
38+
local project_root = vim.fs.root(bufnr, root_markers) or vim.fn.getcwd()
4039

4140
on_dir(project_root)
4241
end,

lsp/vtsls.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ return {
8686
-- manager lock file.
8787
local root_markers = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock', 'deno.lock' }
8888
-- Give the root markers equal priority by wrapping them in a table
89-
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers } or root_markers
90-
local project_root = vim.fs.root(bufnr, root_markers)
91-
if not project_root then
92-
return
93-
end
89+
root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers, { '.git' } }
90+
or vim.list_extend(root_markers, { '.git' })
91+
-- We fallback to the current working directory if no project root is found
92+
local project_root = vim.fs.root(bufnr, root_markers) or vim.fn.getcwd()
9493

9594
on_dir(project_root)
9695
end,

0 commit comments

Comments
 (0)