From bb4e7dbd8eb420e1702a9434d6fed7bd2d568e89 Mon Sep 17 00:00:00 2001 From: Uzair Aftab <48220549+Uzaaft@users.noreply.github.com> Date: Fri, 15 Dec 2023 21:06:03 +0100 Subject: [PATCH] feat(typescript): Move eslint-lsp to the proper plugin, and add autocmd to format on save (#683) * feat(typescript): Move eslint-lsp to the proper plugin, and add autocmd to format on save * Update lua/astrocommunity/pack/typescript/init.lua Co-authored-by: Micah Halter * Update lua/astrocommunity/pack/typescript/init.lua * Update lua/astrocommunity/pack/typescript/init.lua --------- Co-authored-by: Micah Halter --- lua/astrocommunity/pack/typescript/init.lua | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lua/astrocommunity/pack/typescript/init.lua b/lua/astrocommunity/pack/typescript/init.lua index 72fbdb576..ac994306a 100644 --- a/lua/astrocommunity/pack/typescript/init.lua +++ b/lua/astrocommunity/pack/typescript/init.lua @@ -50,8 +50,26 @@ return { }, { "williamboman/mason-lspconfig.nvim", - optional = true, - opts = function(_, opts) opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, "tsserver") end, + opts = function(_, opts) + opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, { "tsserver", "eslint" }) + + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("eslint_fix_creator", { clear = true }), + desc = "Create autocommand in buffers where eslint attaches", + callback = function(args) + if assert(vim.lsp.get_client_by_id(args.data.client_id)).name == "eslint" then + vim.api.nvim_create_autocmd("BufWritePost", { + desc = "Fix all eslint errors", + buffer = args.buf, + group = vim.api.nvim_create_augroup(("eslint_fix_%d"):format(args.buf), { clear = true }), + callback = function() + if vim.fn.exists ":EslintFixAll" > 0 then vim.cmd.EslintFixAll() end + end, + }) + end + end, + }) + end, }, { "jay-babu/mason-null-ls.nvim",