Skip to content

Commit 8af6a1d

Browse files
authored
feat: use node_modules local executable if available #4386
1 parent d27cf1d commit 8af6a1d

14 files changed

Lines changed: 118 additions & 24 deletions

lsp/astro.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ local util = require 'lspconfig.util'
4747

4848
---@type vim.lsp.Config
4949
return {
50-
cmd = { 'astro-ls', '--stdio' },
50+
cmd = function(dispatchers, config)
51+
local cmd = 'astro-ls'
52+
if (config or {}).root_dir then
53+
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
54+
if vim.fn.executable(local_cmd) == 1 then
55+
cmd = local_cmd
56+
end
57+
end
58+
return vim.lsp.rpc.start({ cmd, '--stdio' }, dispatchers)
59+
end,
5160
filetypes = { 'astro' },
5261
root_markers = { 'package.json', 'tsconfig.json', 'jsconfig.json', '.git' },
5362
init_options = {

lsp/biome.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ local util = require 'lspconfig.util'
1717
return {
1818
cmd = function(dispatchers, config)
1919
local cmd = 'biome'
20-
local local_cmd = (config or {}).root_dir and config.root_dir .. '/node_modules/.bin/biome'
21-
if local_cmd and vim.fn.executable(local_cmd) == 1 then
22-
cmd = local_cmd
20+
if (config or {}).root_dir then
21+
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
22+
if vim.fn.executable(local_cmd) == 1 then
23+
cmd = local_cmd
24+
end
2325
end
2426
return vim.lsp.rpc.start({ cmd, 'lsp-proxy' }, dispatchers)
2527
end,

lsp/cssls.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@
2222

2323
---@type vim.lsp.Config
2424
return {
25-
cmd = { 'vscode-css-language-server', '--stdio' },
25+
cmd = function(dispatchers, config)
26+
local cmd = 'vscode-css-language-server'
27+
if (config or {}).root_dir then
28+
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
29+
if vim.fn.executable(local_cmd) == 1 then
30+
cmd = local_cmd
31+
end
32+
end
33+
return vim.lsp.rpc.start({ cmd, '--stdio' }, dispatchers)
34+
end,
2635
filetypes = { 'css', 'scss', 'less' },
2736
init_options = { provideFormatter = true }, -- needed to enable formatting capabilities
2837
root_markers = { 'package.json', '.git' },

lsp/eslint.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ local eslint_config_files = {
7777

7878
---@type vim.lsp.Config
7979
return {
80-
cmd = { 'vscode-eslint-language-server', '--stdio' },
80+
cmd = function(dispatchers, config)
81+
local cmd = 'vscode-eslint-language-server'
82+
if (config or {}).root_dir then
83+
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
84+
if vim.fn.executable(local_cmd) == 1 then
85+
cmd = local_cmd
86+
end
87+
end
88+
return vim.lsp.rpc.start({ cmd, '--stdio' }, dispatchers)
89+
end,
8190
filetypes = {
8291
'javascript',
8392
'javascriptreact',

lsp/glint.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@
2525
---@type vim.lsp.Config
2626
return {
2727
cmd = function(dispatchers, config)
28+
local cmd = 'glint-language-server'
2829
---@diagnostic disable-next-line: undefined-field
29-
local cmd = (config.init_options.glint.useGlobal or not config.root_dir) and { 'glint-language-server' }
30-
or { config.root_dir .. '/node_modules/.bin/glint-language-server' }
31-
return vim.lsp.rpc.start(cmd, dispatchers)
30+
if not config.init_options.glint.useGlobal and (config or {}).root_dir then
31+
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
32+
if vim.fn.executable(local_cmd) == 1 then
33+
cmd = local_cmd
34+
end
35+
end
36+
return vim.lsp.rpc.start({ cmd }, dispatchers)
3237
end,
3338
init_options = {
3439
glint = {

lsp/html.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@
2424

2525
---@type vim.lsp.Config
2626
return {
27-
cmd = { 'vscode-html-language-server', '--stdio' },
27+
cmd = function(dispatchers, config)
28+
local cmd = 'vscode-html-language-server'
29+
if (config or {}).root_dir then
30+
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
31+
if vim.fn.executable(local_cmd) == 1 then
32+
cmd = local_cmd
33+
end
34+
end
35+
return vim.lsp.rpc.start({ cmd, '--stdio' }, dispatchers)
36+
end,
2837
filetypes = { 'html' },
2938
root_markers = { 'package.json', '.git' },
3039
---@type lspconfig.settings.html

lsp/jsonls.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@
2323

2424
---@type vim.lsp.Config
2525
return {
26-
cmd = { 'vscode-json-language-server', '--stdio' },
26+
cmd = function(dispatchers, config)
27+
local cmd = 'vscode-json-language-server'
28+
if (config or {}).root_dir then
29+
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
30+
if vim.fn.executable(local_cmd) == 1 then
31+
cmd = local_cmd
32+
end
33+
end
34+
return vim.lsp.rpc.start({ cmd, '--stdio' }, dispatchers)
35+
end,
2736
filetypes = { 'json', 'jsonc' },
2837
init_options = {
2938
provideFormatter = true,

lsp/oxfmt.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ local util = require 'lspconfig.util'
1717
return {
1818
cmd = function(dispatchers, config)
1919
local cmd = 'oxfmt'
20-
local local_cmd = (config or {}).root_dir and config.root_dir .. '/node_modules/.bin/oxfmt'
21-
if local_cmd and vim.fn.executable(local_cmd) == 1 then
22-
cmd = local_cmd
20+
if (config or {}).root_dir then
21+
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
22+
if vim.fn.executable(local_cmd) == 1 then
23+
cmd = local_cmd
24+
end
2325
end
2426
return vim.lsp.rpc.start({ cmd, '--lsp' }, dispatchers)
2527
end,

lsp/oxlint.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ end
3232
return {
3333
cmd = function(dispatchers, config)
3434
local cmd = 'oxlint'
35-
local local_cmd = (config or {}).root_dir and config.root_dir .. '/node_modules/.bin/oxlint'
36-
if local_cmd and vim.fn.executable(local_cmd) == 1 then
37-
cmd = local_cmd
35+
if (config or {}).root_dir then
36+
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
37+
if vim.fn.executable(local_cmd) == 1 then
38+
cmd = local_cmd
39+
end
3840
end
3941
return vim.lsp.rpc.start({ cmd, '--lsp' }, dispatchers)
4042
end,

lsp/rome.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212

1313
---@type vim.lsp.Config
1414
return {
15-
cmd = { 'rome', 'lsp-proxy' },
15+
cmd = function(dispatchers, config)
16+
local cmd = 'rome'
17+
if (config or {}).root_dir then
18+
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
19+
if vim.fn.executable(local_cmd) == 1 then
20+
cmd = local_cmd
21+
end
22+
end
23+
return vim.lsp.rpc.start({ cmd, 'lsp-proxy' }, dispatchers)
24+
end,
1625
filetypes = {
1726
'javascript',
1827
'javascriptreact',

0 commit comments

Comments
 (0)