From 306539c6f9b970ec75d0e913d932a915e3da4056 Mon Sep 17 00:00:00 2001 From: Uzair Aftab Date: Wed, 13 Dec 2023 10:34:33 +0100 Subject: [PATCH 1/4] feat(typescript): Move eslint-lsp to the proper plugin, and add autocmd to format on save --- lua/astrocommunity/pack/typescript/init.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/astrocommunity/pack/typescript/init.lua b/lua/astrocommunity/pack/typescript/init.lua index 03d9e73ec..e9b29574b 100644 --- a/lua/astrocommunity/pack/typescript/init.lua +++ b/lua/astrocommunity/pack/typescript/init.lua @@ -49,7 +49,19 @@ return { }, { "williamboman/mason-lspconfig.nvim", - 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-lsp") + end, + init = function() + vim.api.nvim_create_autocmd("BufWritePost", { + desc = "Fix all eslint errors", + pattern = { "*.tsx", "*.ts", "*.jsx", "*.js" }, + group = "...", + callback = function() + if vim.fn.exists ":EslintFixAll" > 0 then vim.cmd "EslintFixAll" end + end, + }) + end, }, { "jay-babu/mason-null-ls.nvim", From 8f242bc1f33ca2caccdba098c7a211243384f8ec Mon Sep 17 00:00:00 2001 From: Uzair Aftab <48220549+Uzaaft@users.noreply.github.com> Date: Fri, 15 Dec 2023 20:33:33 +0100 Subject: [PATCH 2/4] Update lua/astrocommunity/pack/typescript/init.lua Co-authored-by: Micah Halter --- lua/astrocommunity/pack/typescript/init.lua | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lua/astrocommunity/pack/typescript/init.lua b/lua/astrocommunity/pack/typescript/init.lua index e9b29574b..0facc02c4 100644 --- a/lua/astrocommunity/pack/typescript/init.lua +++ b/lua/astrocommunity/pack/typescript/init.lua @@ -50,15 +50,22 @@ return { { "williamboman/mason-lspconfig.nvim", opts = function(_, opts) - opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, "tsserver", "eslint-lsp") - end, - init = function() - vim.api.nvim_create_autocmd("BufWritePost", { - desc = "Fix all eslint errors", - pattern = { "*.tsx", "*.ts", "*.jsx", "*.js" }, - group = "...", - callback = function() - if vim.fn.exists ":EslintFixAll" > 0 then vim.cmd "EslintFixAll" end + 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, From f36a1d903f14445644c7301481bafe944af94ca4 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Fri, 15 Dec 2023 14:35:57 -0500 Subject: [PATCH 3/4] Update lua/astrocommunity/pack/typescript/init.lua --- lua/astrocommunity/pack/typescript/init.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/astrocommunity/pack/typescript/init.lua b/lua/astrocommunity/pack/typescript/init.lua index 0facc02c4..b32e618b2 100644 --- a/lua/astrocommunity/pack/typescript/init.lua +++ b/lua/astrocommunity/pack/typescript/init.lua @@ -51,7 +51,6 @@ return { "williamboman/mason-lspconfig.nvim", 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", From a92bdaacaffd94e6b84a74eaa4ecfd207efeb358 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Fri, 15 Dec 2023 14:39:27 -0500 Subject: [PATCH 4/4] Update lua/astrocommunity/pack/typescript/init.lua --- lua/astrocommunity/pack/typescript/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/astrocommunity/pack/typescript/init.lua b/lua/astrocommunity/pack/typescript/init.lua index b32e618b2..385080791 100644 --- a/lua/astrocommunity/pack/typescript/init.lua +++ b/lua/astrocommunity/pack/typescript/init.lua @@ -50,7 +50,8 @@ return { { "williamboman/mason-lspconfig.nvim", opts = function(_, opts) - opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, "tsserver", "eslint") + 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",