mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-26 10:48:45 +02:00
perf(eslint): only run EslintFixAll for the current buffer when there are diagnostics from eslint
This commit is contained in:
parent
b4099a6477
commit
b227d9727a
1 changed files with 7 additions and 2 deletions
|
@ -3,6 +3,7 @@ return {
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
-- other settings removed for brevity
|
-- other settings removed for brevity
|
||||||
opts = {
|
opts = {
|
||||||
|
---@type lspconfig.options
|
||||||
servers = {
|
servers = {
|
||||||
eslint = {
|
eslint = {
|
||||||
settings = {
|
settings = {
|
||||||
|
@ -15,8 +16,12 @@ return {
|
||||||
eslint = function()
|
eslint = function()
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
callback = function(event)
|
callback = function(event)
|
||||||
if require("lspconfig.util").get_active_client_by_name(event.buf, "eslint") then
|
local client = vim.lsp.get_active_clients({ bufnr = event.buf, name = "eslint" })[1]
|
||||||
vim.cmd("EslintFixAll")
|
if client then
|
||||||
|
local diag = vim.diagnostic.get(event.buf, { namespace = vim.lsp.diagnostic.get_namespace(client.id) })
|
||||||
|
if #diag > 0 then
|
||||||
|
vim.cmd("EslintFixAll")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue