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

Breaking changes to ESLint and formatter options #65

Closed jose-elias-alvarez closed 2 years ago

jose-elias-alvarez commented 3 years ago

02ea3e319fb4894ed974b4ddf001417f1e25c4db exposes the built-in options for the ESLint and formatting sources registered via this plugin, which allows full configuration of basically any aspect of these sources (while still maintaining the convenience of registering them on tsserver attach and automatically resolving local executables).

The commit removed the following options:

All of these can be handled by modifying eslint_opts / formatter_opts:

eslint_show_rule_id

require("nvim-lsp-ts-utils").setup({
    eslint_enable_diagnostics = true,
    eslint_opts = {
        diagnostics_format = "#{m} [#{c}]",
    },
})

eslint_disable_if_no_config

require("nvim-lsp-ts-utils").setup({
    eslint_enable_diagnostics = true,
    eslint_opts = {
        condition = function(utils)
            -- replace with your preferred config file format
            return utils.root_has_file(".eslintrc.js")
        end,
    },
})

eslint_config_fallback

require("nvim-lsp-ts-utils").setup({
    eslint_enable_diagnostics = true,
    eslint_opts = {
        -- you might want to memoize this for performance
        extra_args = function(params)
            local lsputil = require("lspconfig.util")
            local root = lsputil.root_pattern("package.json")(params.bufname)
            -- replace with your preferred config file format and fallback path
            return lsputil.path.exists(lsputil.path.join(root, ".eslintrc.js")) and {}
                or { "--config", vim.fn.expand("~/.config/.eslintrc.js") }
        end,
    },
})

formatter_config_fallback

require("nvim-lsp-ts-utils").setup({
    enable_formatting = true,
    formatter_opts = {
        -- you might want to memoize this for performance
        extra_args = function(params)
            local lsputil = require("lspconfig.util")
            local root = lsputil.root_pattern("package.json")(params.bufname)
            -- replace with your preferred config file format and fallback path
            return lsputil.path.exists(lsputil.path.join(root, ".prettierrc")) and {}
                or { "--config", vim.fn.expand("~/.config/.prettierrc") }
        end,
    },
})

Note that even if you're using eslint or eslint_d as a formatter, you still want to modify options via formatter_opts, to allow separation.

The commit also made the sources registered by this plugin specific to tsserver filetypes, to avoid unwanted interactions with unspecified filetypes. Users who want to use these sources for other filetypes should register the built-ins directly via null-ls.

VVKot commented 3 years ago

@jose-elias-alvarez it seems that ESLint is not longer discovered from the local node_modules folder. I.e. if I don't have eslint globally installed plugin won't work correctly. Is that expected after this changes?

jose-elias-alvarez commented 3 years ago

@VVKot The mechanism to resolve the ESLint path shouldn't have changed, theoretically, though there were some other changes (using nvim-lspconfig's utils to handle paths) that could be causing issues. Could you set debug = true in your config and post the output from :messages?

VVKot commented 3 years ago
using system executable eslint
using system executable eslint
enabling null-ls eslint code actions integration
successfully registered null-ls integrations
E5108: Error executing lua ...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:14: The coroutine failed with this message: ...e/pack/packer/start/null-ls.nvim/lua/null-ls/helpers.lua:147: command eslint is not executable (make sure it's installed and on your $PATH)

Sorry, missed that. See output above, seems that we're confusing system executable for the one in local node_modules folder. I.e. in this repo/machine case I don't have a ESLint at my path, so I can't do :!eslint but I can do :!node_modules/.bin/eslint. @jose-elias-alvarez

jose-elias-alvarez commented 3 years ago

I see, so something is going wrong with the way the plugin is resolving the path. Could you open another issue and post the output from running :lua require("nvim-lsp-ts-utils.utils").buffer.root() and :lua require("nvim-lsp-ts-utils.utils").resolve_bin("eslint") with a project file loaded? I won’t have time to debug / investigate this for a bit but maybe we can catch something obvious.