From f4fc9e824762709e311399e07750d6d7ee543bf1 Mon Sep 17 00:00:00 2001 From: Sam-programs <130783534+Sam-programs@users.noreply.github.com> Date: Sun, 12 May 2024 02:11:46 +0300 Subject: [PATCH] fix(filters): allow the user to clear builtin filters with `clear_filters` --- lua/noice/config/init.lua | 23 +++++++++++++++++++++++ lua/noice/lsp/progress.lua | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lua/noice/config/init.lua b/lua/noice/config/init.lua index b147c638..87aa9c91 100644 --- a/lua/noice/config/init.lua +++ b/lua/noice/config/init.lua @@ -221,6 +221,28 @@ function M.is_running() return M._running end +function M.setup_filters(config, new_config, key) + if type(config) ~= "table" or type(new_config) ~= "table" then + return + end + if key == "filter" then + if new_config.clear_filters then + new_config.clear_filters = nil + -- Can't use `config = {}` because that would create a new array (instead of modifying the caller's `config`) + for k, _ in pairs(config) do + config[k] = nil + end + for k, v in pairs(new_config) do + config[k] = v + end + end + return + end + for k, _ in pairs(new_config) do + M.setup_filters(config[k], new_config[k], k) + end +end + function M.setup(options) options = options or {} @@ -246,6 +268,7 @@ function M.setup(options) local routes = M.options.routes M.options = vim.tbl_deep_extend("force", M.options, options) vim.list_extend(M.options.routes, routes) + M.setup_filters(M.options, options) if M.options.popupmenu.kind_icons == false then M.options.popupmenu.kind_icons = {} diff --git a/lua/noice/lsp/progress.lua b/lua/noice/lsp/progress.lua index b8305051..5768578d 100644 --- a/lua/noice/lsp/progress.lua +++ b/lua/noice/lsp/progress.lua @@ -16,7 +16,7 @@ M._running = false ---@param data {client_id: integer, params: lsp.ProgressParams} function M.progress(data) local client_id = data.client_id - local params = data.params or data.result -- TODO: Remove data.result after nvim 0.10 release + local params = data.params or data.result -- TODO: Remove data.result after nvim 0.10 release local id = client_id .. "." .. params.token local message = M._progress[id]