diff --git a/lua/configs/null-ls.lua b/lua/configs/null-ls.lua index 711ab82..58f7447 100644 --- a/lua/configs/null-ls.lua +++ b/lua/configs/null-ls.lua @@ -6,20 +6,38 @@ function M.config() return end + local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) null_ls.setup { sources = { -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md -- sudo pacman -S prettierd - -- null_ls.builtins.formatting.prettierd, + null_ls.builtins.formatting.prettierd.with({ + disabled_filetypes = { "html", "markdown" }, + }), -- sudo pacman -S eslint_d - -- null_ls.builtins.diagnostics.eslint_d.with({ - -- diagnostic_config = { -- see also :help vim.diagnostic.config() - -- virtual_text = false, - -- } - -- }), - } + null_ls.builtins.diagnostics.eslint_d.with({ + condition = function(utils) + return utils.root_has_file({ ".eslintrc.js" }) + end, + diagnostic_config = { -- see also :help vim.diagnostic.config() + virtual_text = false, + } + }), + }, + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ bufnr = bufnr }) + end, + }) + end + end, } end diff --git a/lua/configs/prettier.lua b/lua/configs/prettier.lua deleted file mode 100644 index a2f41c9..0000000 --- a/lua/configs/prettier.lua +++ /dev/null @@ -1,14 +0,0 @@ -local M = {} - -function M.config() - local status_ok, prettier = pcall(require, "prettier") - if not status_ok then - return - end - - prettier.setup({ - bin = 'prettierd' - }) -end - -return M diff --git a/lua/plugins.lua b/lua/plugins.lua index 4d605b1..ad41838 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -139,7 +139,11 @@ packer.startup { -- use { 'simrat39'/symbols-outline.nvim', cmd = 'SymbolsOutline', setup = function ... } -- null-ls LSP injector - use { 'jose-elias-alvarez/null-ls.nvim', config = function() require'configs.null-ls'.config() end } + use { + 'jose-elias-alvarez/null-ls.nvim', + event = 'BufRead', + config = function() require'configs.null-ls'.config() end + } -- highlight hovered-over text use {