jose-elias-alvarez / nvim-lsp-ts-utils

Utilities to improve the TypeScript development experience for Neovim's built-in LSP client.
The Unlicense
438 stars 18 forks source link

[FEATURE REQUEST] eslint yarn pnp support #83

Closed academo closed 2 years ago

academo commented 2 years ago

Issues

Feature description

I've been trying to setup eslint using yarn pnp but the current eslint_bin will only accept a fixed value of eslint or eslint_d.

With yarn pnp the eslint binary would be somewhere like ./.yarn/sdks/eslint/bin/eslint.js and it is not necessarily part of your PATH

There is a validation that only allows specific values for the eslint_bin and I wonder if removing such validation would be enough to make yarn pnp work.

If there is another way that someone made this work with yarn pnp please let me know.

Help

Yes, but I don't know how to start. I would need guidance

Implementation help

I managed to make eslint with this setup:

local eslint_command = 'eslint'
local pnp_eslint = vim.fn.findfile('.yarn/sdks/eslint/bin/eslint.js');
if (pnp_eslint) then eslint_command = pnp_eslint end

local null_ls = require('null-ls')
local sources = {
    null_ls.builtins.diagnostics.eslint.with({command = eslint_command})
}
require("null-ls").config {sources = sources}

but of course this doesn't work with the code actions and other functionalities.

No response

jose-elias-alvarez commented 2 years ago

Just removing the validation wouldn't work, since it would still try to find an executable in node_modules and fall back to the global executable if it's not available.

I haven't tried Yarn PnP yet but would accept a PR adding support until I get around to it. An easier alternative may be to try the ESLint language server.

academo commented 2 years ago

@jose-elias-alvarez what about accepting a command to execute and trust it if passed? instead of searching for the command traversing the disk?

jose-elias-alvarez commented 2 years ago

As you noted, you can currently do that via null-ls for diagnostics (and you can do the same for formatting). It's not currently possible for code actions – I'd have to spin it out as an independent source, but honestly I'm not sure it's worth the effort given that the language server does the same thing but better (I'd accept a PR, though).

non25 commented 2 years ago

Wanted to open this issue myself on last weekend. :grin:

I tried making a script in PATH which looks like this:

#!/bin/sh
/home/non/path-to/your/eslint_d.js "$@"

Though I could trick the system, but looks like no success. :grin:

 Client: null-ls (id: 2, pid: 5001, bufnr: [1, 1])
    filetypes:       javascript, javascriptreact, typescript, typescriptreact, javascript.jsx, typescript.tsx
    autostart:       false
    root directory:  /home/non/some-project
    cmd:             nvim

This is from neovim's LspInfo.

Sad times. I'm so used to use eslint code actions to reformat stuff according to the rules and mute eslint now in npm-dependend project. null-ls is amazing. Also null-ls messages don't hang on screen until you re-edit anything like efm's. :+1:

jose-elias-alvarez commented 2 years ago

@non25 If possible I recommend trying the language server. It still has a few bugs to work out but it's generally reliable, and it looks like there is a workaround to use Yarn PnP.

jose-elias-alvarez commented 2 years ago

null-ls added support for this in jose-elias-alvarez/null-ls.nvim#646.