From c1eb3125e1ed1eed31be3e394a52fe5d652bd63e Mon Sep 17 00:00:00 2001 From: Zeioth Date: Tue, 7 Nov 2023 17:09:25 +0100 Subject: [PATCH] fix+feat: [FIXES] null-ls (by ignoring it). [FEATS] new option `excluded_lsp_clients` [FEATS] config is not exposed through a global so it can be changed on the fly. --- lua/garbage-day/config.lua | 1 + lua/garbage-day/init.lua | 5 ++++- lua/garbage-day/utils.lua | 28 ++++++++++++++++++---------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lua/garbage-day/config.lua b/lua/garbage-day/config.lua index 7b0a528..f8b530b 100644 --- a/lua/garbage-day/config.lua +++ b/lua/garbage-day/config.lua @@ -4,6 +4,7 @@ local M = {} function M.set(opts) M.grace_period = opts.grace_period or (60*15) -- seconds M.excluded_filetypes = opts.excluded_filetypes or { "java", "markdown" } + M.excluded_lsp_clients = opts.excluded_lsp_clients or { "null-ls" } M.stop_invisible = opts.stop_invisible or false M.notifications = opts.notifications or false end diff --git a/lua/garbage-day/init.lua b/lua/garbage-day/init.lua index 01fc6ed..7d3e971 100644 --- a/lua/garbage-day/init.lua +++ b/lua/garbage-day/init.lua @@ -33,6 +33,7 @@ local M = {} --- Entry point of the program function M.setup(opts) config.set(opts) + vim.g.garbage_day_config = config -- Focus lost? vim.api.nvim_create_autocmd({ "FocusLost" }, { @@ -84,7 +85,9 @@ function M.setup(opts) if config.notifications then utils.notify("lsp_has_stopped") end -- fix for null-ls - pcall(function() require("null-ls").enable({}) end) + if not vim.tbl_contains(config.excluded_lsp_clients, 'null-ls') then + pcall(function() require("null-ls").enable({}) end) + end end end }) diff --git a/lua/garbage-day/utils.lua b/lua/garbage-day/utils.lua index 46dfbc3..e708aa0 100644 --- a/lua/garbage-day/utils.lua +++ b/lua/garbage-day/utils.lua @@ -5,18 +5,22 @@ local M = {} -- ---------------------------------------------------------------------------- ---Stop all lsp clients, including the ones in other tabs. ----@param excluded_filetypes table Languages where we don't want to stop LSP. ---@return table stopped_lsp_clients A table like { [client] = buf, ... } ---So we can start them again on FocusGaind. -function M.stop_lsp(excluded_filetypes) +function M.stop_lsp() + local config = vim.g.garbage_day_config + local stopped_lsp_clients = {} for _, client in pairs(vim.lsp.get_active_clients()) do for buf, _ in pairs(client.attached_buffers) do -- If all conditions pass local filetype = vim.api.nvim_get_option_value("filetype", { buf = buf }) - local is_filetype_excluded = vim.tbl_contains(excluded_filetypes, filetype) - if not is_filetype_excluded then + local is_filetype_excluded = vim.tbl_contains(config.excluded_filetypes, filetype) + local is_lsp_client_excluded = vim.tbl_contains(config.excluded_lsp_clients, client.config.name) + if not is_filetype_excluded and + not is_lsp_client_excluded + then -- save client+buf for later stopped_lsp_clients[client] = buf @@ -62,15 +66,16 @@ end ---Stop all lsp clients, including the ones in other tabs. --Except the ones currently asociated to a nvim window in the current tab. ----@param excluded_filetypes table Languages where we don't want to stop LSP. ---@return table stopped_lsp_clients A table like { [client] = buf, ... } ---So we can start them again on BufEnter. -function M.stop_invisible(excluded_filetypes) +function M.stop_invisible() + -- get config + local config = vim.g.garbage_day_config + + -- Get all visible filetypes in the current tab. local stopped_lsp_clients = {} local visible_buffers = {} local visible_filetypes = {} - - -- Get all visible filetypes in the current tab. local current_tab = vim.api.nvim_get_current_tabpage() local visible_windows = vim.api.nvim_tabpage_list_wins(current_tab) for _, win in ipairs(visible_windows) do @@ -87,11 +92,13 @@ function M.stop_invisible(excluded_filetypes) local filetype = vim.api.nvim_get_option_value("filetype", { buf = buf }) local is_buf_visible = vim.tbl_contains(visible_buffers, buf) local is_filetype_visible = visible_filetypes[filetype] - local is_filetype_excluded = vim.tbl_contains(excluded_filetypes, filetype) + local is_filetype_excluded = vim.tbl_contains(config.excluded_filetypes, filetype) + local is_lsp_client_excluded = vim.tbl_contains(config.excluded_lsp_clients, client.config.name) -- If all conditions pass if not is_buf_visible and not is_filetype_visible and - not is_filetype_excluded + not is_filetype_excluded and + not is_lsp_client_excluded then -- save client+buf for later stopped_lsp_clients[client] = buf @@ -129,3 +136,4 @@ end return M +