diff options
| author | William Boman <william@redwill.se> | 2022-07-05 12:48:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-05 03:48:13 -0700 |
| commit | 06161eca0aaaafbede0234216aefaed2e5eb46d8 (patch) | |
| tree | 5cfe8e38d4bdd50cb33eb22757d9054ab35fc833 | |
| parent | fix(lspinfo): may use wrong buffer #1983 (diff) | |
| download | nvim-lspconfig-06161eca0aaaafbede0234216aefaed2e5eb46d8.tar nvim-lspconfig-06161eca0aaaafbede0234216aefaed2e5eb46d8.tar.gz nvim-lspconfig-06161eca0aaaafbede0234216aefaed2e5eb46d8.tar.bz2 nvim-lspconfig-06161eca0aaaafbede0234216aefaed2e5eb46d8.tar.lz nvim-lspconfig-06161eca0aaaafbede0234216aefaed2e5eb46d8.tar.xz nvim-lspconfig-06161eca0aaaafbede0234216aefaed2e5eb46d8.tar.zst nvim-lspconfig-06161eca0aaaafbede0234216aefaed2e5eb46d8.zip | |
feat(eslint): support yarn2 PnP projects #1777
https://yarnpkg.com/features/pnp
Yarn's PnP feature changes the way packages are installed. Instead of building on the `node_modules` resolution, it introduces a single `.pnp.*js` file in the project. This file is responsible for orchestrating and resolving dependencies. The eslint LSP server will assume that regular `node_modules` resolution applies when locating the `eslint` package - which will not work in Yarn PnP projects.
To work around this, Yarn provides the ability to run Node programs in "PnP-compat" mode via `yarn exec` and `yarn node`. My understanding is that this simply hooks into the `require()` function to resolve modules via PnP instead Node's builtin module resolution.
| -rw-r--r-- | lua/lspconfig/server_configurations/eslint.lua | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lua/lspconfig/server_configurations/eslint.lua b/lua/lspconfig/server_configurations/eslint.lua index 81a796df..6cfc1e80 100644 --- a/lua/lspconfig/server_configurations/eslint.lua +++ b/lua/lspconfig/server_configurations/eslint.lua @@ -98,6 +98,13 @@ return { uri = new_root_dir, name = vim.fn.fnamemodify(new_root_dir, ':t'), } + + -- Support Yarn2 (PnP) projects + local pnp_cjs = util.path.join(new_root_dir, '.pnp.cjs') + local pnp_js = util.path.join(new_root_dir, '.pnp.js') + if util.path.exists(pnp_cjs) or util.path.exists(pnp_js) then + config.cmd = vim.list_extend({ 'yarn', 'exec' }, cmd) + end end, handlers = { ['eslint/openDoc'] = function(_, result) |
