-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
base: master
Are you sure you want to change the base?
Conversation
0ecbcc9
to
10429f6
Compare
That is a confusing thing to mention. Even if I still would like to confirm my question from #3889 (comment) : is this decision required as a CLI arg? Then if so, it makes sense to define |
I think you may want to define a |
I agree it's not quite intuitive. Basically having bufnr/root_dir allows it to check if If you take my playground project in #3889, with this PR + the new
Yes, somewhat. It's not an arg of the eslint LS itself but some args of # still in my playground project
$ node
Welcome to Node.js v24.2.0.
Type ".help" for more information.
> process.env.NODE_OPTIONS
undefined
$ yarn exec node
Welcome to Node.js v24.2.0.
Type ".help" for more information.
> process.env.NODE_OPTIONS
'--require /home/frederick/Programming/Others/playground/.pnp.cjs --experimental-loader file:///home/frederick/Programming/Others/playground/.pnp.loader.mjs' AFAIU
I'm not familiar with this function but after having a glace at the docs, I assume it's something that gets called every time a new buffer of a related filetype (.js / .ts) is opened. So I assume you were talking about that in this If I'm not mistaken, unless |
Nevertheless, a one-line comment should mention that.
|
Problem: In the new lsp/eslint.lua, the PnP detection in before_init did not work at all as before_init cannot modify config.cmd [1]. Solution: The code is moved to the new cmd function, which detects PnP by checking .pnp.[c]js and prepends cmd with 'yarn exec' so that Node.js can load a PnP project's ESLint library zip file for ESLint LS. In the old lua/lspconfig/configs/eslint.lua, on_new_config still works, though since [2] the new :Lsp* commands no longer utilise the old files. Note since the cmd function does not have access to either bufnr or the resolved root_dir [3], it only looks for .pnp.[c]js in current working directory. [1] https://github.com/neovim/neovim/blob/93925fe0/runtime/lua/vim/lsp/client.lua#L456-L466 [2] neovim@e4d1c8b [3] https://github.com/neovim/neovim/blob/93925fe0/runtime/lua/vim/lsp.lua#L558
10429f6
to
c86804a
Compare
Done.
Then I think really it'd be nice if something simpler can come out of neovim/neovim#32287 that allows constructing cmd according to root_dir. Then the default behaviour of reuse_client, i.e. reuse if root_dir is the same, should just work nicely too. |
can you show a concrete example meanwhile, why not use |
name: Pull Request
about: Submit a pull request
title: fix(eslint): detect Yarn PnP in function form cmd
c86804a3
fix(eslint): detect Yarn PnP in function form cmdProblem:
In the new lsp/eslint.lua, the PnP detection in before_init did not work
at all as before_init cannot modify config.cmd [1].
Solution:
The code is moved to the new cmd function, which detects PnP by checking
.pnp.[c]js and prepends cmd with 'yarn exec' so that Node.js can load a
PnP project's ESLint library zip file for ESLint LS.
In the old lua/lspconfig/configs/eslint.lua, on_new_config still works,
though since [2] the new :Lsp* commands no longer utilise the old files.
Note since the cmd function does not have access to either bufnr or the
resolved root_dir [3], it only looks for .pnp.[c]js in current working
directory.
[1] https://github.com/neovim/neovim/blob/93925fe0/runtime/lua/vim/lsp/client.lua#L456-L466
[2] e4d1c8b
[3] https://github.com/neovim/neovim/blob/93925fe0/runtime/lua/vim/lsp.lua#L558
Closes #3858
Closes #3889