Skip to content

fix(eslint): detect Yarn PnP in function form cmd #3900

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions lsp/eslint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ local util = require 'lspconfig.util'
local lsp = vim.lsp

return {
cmd = { 'vscode-eslint-language-server', '--stdio' },
cmd = function(dispatchers)
local eslint_cmd = { 'vscode-eslint-language-server', '--stdio' }
-- No bufnr or root_dir here. Always use cwd() for now.
local root_dir = vim.uv.cwd()

-- Support Yarn2 (PnP) projects
local pnp_cjs = root_dir .. '/.pnp.cjs'
local pnp_js = root_dir .. '/.pnp.js'
if vim.uv.fs_stat(pnp_cjs) or vim.uv.fs_stat(pnp_js) then
eslint_cmd = { 'yarn', 'exec', unpack(eslint_cmd) }
end

return vim.lsp.rpc.start(eslint_cmd, dispatchers)
end,
filetypes = {
'javascript',
'javascriptreact',
Expand Down Expand Up @@ -147,14 +160,6 @@ return {
break
end
end

-- Support Yarn2 (PnP) projects
local pnp_cjs = root_dir .. '/.pnp.cjs'
local pnp_js = root_dir .. '/.pnp.js'
if vim.uv.fs_stat(pnp_cjs) or vim.uv.fs_stat(pnp_js) then
local cmd = config.cmd
config.cmd = vim.list_extend({ 'yarn', 'exec' }, cmd)
end
end
end,
handlers = {
Expand Down