From 058742c64c09d467e95f5e1471d2d7ca22c92c5b Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Mon, 3 Jun 2024 17:42:31 -0400 Subject: [PATCH] fix(eslint): use vim.lsp.buf.code_action to implement :EslintFixAll --- .../server_configurations/eslint.lua | 38 +++---------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/lua/lspconfig/server_configurations/eslint.lua b/lua/lspconfig/server_configurations/eslint.lua index c52f827808..7d8909256e 100644 --- a/lua/lspconfig/server_configurations/eslint.lua +++ b/lua/lspconfig/server_configurations/eslint.lua @@ -1,37 +1,6 @@ local util = require 'lspconfig.util' local lsp = vim.lsp -local function fix_all(opts) - opts = opts or {} - - local eslint_lsp_client = util.get_active_client_by_name(opts.bufnr, 'eslint') - if eslint_lsp_client == nil then - return - end - - local request - if opts.sync then - request = function(bufnr, method, params) - eslint_lsp_client.request_sync(method, params, nil, bufnr) - end - else - request = function(bufnr, method, params) - eslint_lsp_client.request(method, params, nil, bufnr) - end - end - - local bufnr = util.validate_bufnr(opts.bufnr or 0) - request(0, 'workspace/executeCommand', { - command = 'eslint.applyAllFixes', - arguments = { - { - uri = vim.uri_from_bufnr(bufnr), - version = lsp.util.buf_versions[bufnr], - }, - }, - }) -end - local root_file = { '.eslintrc', '.eslintrc.js', @@ -163,7 +132,12 @@ return { commands = { EslintFixAll = { function() - fix_all { sync = true, bufnr = 0 } + lsp.buf.code_action { + apply = true, + filter = function(a) + return vim.tbl_get(a, 'command', 'command') == 'eslint.applyAllFixes' + end, + } end, description = 'Fix all eslint problems for this buffer', },