diff options
author | kylo252 <[email protected]> | 2021-10-23 13:11:05 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2021-10-23 13:11:05 +0200 |
commit | 0ea08c7a1c1de5cb381351230d11513e287c42db (patch) | |
tree | c2eb2a90a7b51ae5fb2eea28b4d3f4df23728131 /lua | |
parent | a96a44a16a46dae0aee0f5689ccfe644d2a27c0f (diff) |
fix(log): don't rely on lvim.builtin.notify.active (#1831)
Diffstat (limited to 'lua')
-rw-r--r-- | lua/lvim/config/defaults.lua | 4 | ||||
-rw-r--r-- | lua/lvim/core/log.lua | 45 | ||||
-rw-r--r-- | lua/lvim/core/notify.lua | 28 |
3 files changed, 39 insertions, 38 deletions
diff --git a/lua/lvim/config/defaults.lua b/lua/lvim/config/defaults.lua index effe1e77..a20e34e1 100644 --- a/lua/lvim/config/defaults.lua +++ b/lua/lvim/config/defaults.lua @@ -28,7 +28,7 @@ return { float_opts = {}, }, }, - ---@usage set to false to restore the default behavior of vim.notify - override_notify = true, + -- currently disabled due to instabilities + override_notify = false, }, } diff --git a/lua/lvim/core/log.lua b/lua/lvim/core/log.lua index 557590e1..9950af28 100644 --- a/lua/lvim/core/log.lua +++ b/lua/lvim/core/log.lua @@ -1,7 +1,6 @@ local Log = {} local logfile = string.format("%s/%s.log", vim.fn.stdpath "cache", "lvim") -local in_headless = #vim.api.nvim_list_uis() == 0 Log.levels = { TRACE = 1, @@ -19,20 +18,20 @@ function Log:init() return nil end - local nvim_notify_params = {} - local nvim_notify_params_injecter = function(_, entry) - for key, value in pairs(nvim_notify_params) do - entry[key] = value - end - return entry - end + local notify_handler = require "lvim.core.notify" - local nvim_notify_default_namer = function(logger, entry) - entry["title"] = logger.name - return entry + ---Check if notify is available + ---@return boolean + local is_notify_available = function() + local in_headless = #vim.api.nvim_list_uis() == 0 + --We can't rely on lvim.builtin.notify.active since this can be used before the config loader + local has_notify_plugin = pcall(require, "notify") + if not in_headless and has_notify_plugin then + return true + end + return false end - nvim_notify_params_injecter(nil, {}) local log_level = Log.levels[(lvim.log.level):upper() or "WARN"] local lvim_log = { lvim = { @@ -65,13 +64,13 @@ function Log:init() }, } - if not in_headless and lvim.builtin.notify.active then + if is_notify_available() then table.insert( lvim_log.lvim.sinks, structlog.sinks.NvimNotify(Log.levels.INFO, { processors = { - nvim_notify_default_namer, - nvim_notify_params_injecter, + notify_handler.default_namer, + notify_handler.params_injecter, }, formatter = structlog.formatters.Format( -- "%s", @@ -94,20 +93,8 @@ function Log:init() local logger = structlog.get_logger "lvim" - if not in_headless and lvim.builtin.notify.active and lvim.log.override_notify then - -- Overwrite vim.notify to use the logger - vim.notify = function(msg, vim_log_level, opts) - nvim_notify_params = vim.tbl_deep_extend("force", lvim.builtin.notify.opts, opts) - -- vim_log_level can be omitted - if vim_log_level == nil then - vim_log_level = Log.levels["INFO"] - end - if type(vim_log_level) == "string" then - vim_log_level = Log.levels[(vim_log_level):upper() or "INFO"] - end - -- https://github.com/neovim/neovim/blob/685cf398130c61c158401b992a1893c2405cd7d2/runtime/lua/vim/lsp/log.lua#L5 - logger:log(vim_log_level + 1, msg) - end + if lvim.log.override_notify then + logger:log(Log.levels.INFO, "Ignoring request to override vim.notify with structlog due to instabilities") end return logger diff --git a/lua/lvim/core/notify.lua b/lua/lvim/core/notify.lua index 7d222a89..5339357b 100644 --- a/lua/lvim/core/notify.lua +++ b/lua/lvim/core/notify.lua @@ -2,25 +2,26 @@ local M = {} function M.config() local pallete = require "onedarker.palette" + lvim.builtin.notify = { active = false, on_config_done = nil, -- TODO: update after https://github.com/rcarriga/nvim-notify/pull/24 opts = { - ---@usage Animation style (see below for details) - stages = "fade_in_slide_out", + ---@usage Animation style one of { "fade", "slide", "fade_in_slide_out", "static" } + stages = "slide", - ---@usage Default timeout for notifications + ---@usage timeout for notifications in ms, default 5000 timeout = 5000, - ---@usage For stages that change opacity this is treated as the highlight behind the window + ---@usage highlight behind the window for stages that change opacity background_colour = pallete.fg, ---@usage Icons for the different levels icons = { - ERROR = "", - WARN = "", - INFO = "", + ERROR = "", + WARN = "", + INFO = "", DEBUG = "", TRACE = "✎", }, @@ -28,4 +29,17 @@ function M.config() } end +M.params_injecter = function(_, entry) + -- FIXME: this is currently getting ignored or is not passed correctly + for key, value in pairs(lvim.builtin.notify.opts) do + entry[key] = value + end + return entry +end + +M.default_namer = function(logger, entry) + entry["title"] = logger.name + return entry +end + return M |