diff options
Diffstat (limited to 'lua/lvim/core')
| -rw-r--r-- | lua/lvim/core/builtins/init.lua | 1 | ||||
| -rw-r--r-- | lua/lvim/core/log.lua | 81 | ||||
| -rw-r--r-- | lua/lvim/core/lualine/components.lua | 9 | ||||
| -rw-r--r-- | lua/lvim/core/notify.lua | 45 | 
4 files changed, 94 insertions, 42 deletions
diff --git a/lua/lvim/core/builtins/init.lua b/lua/lvim/core/builtins/init.lua index 8f83072e..315deed3 100644 --- a/lua/lvim/core/builtins/init.lua +++ b/lua/lvim/core/builtins/init.lua @@ -15,6 +15,7 @@ local builtins = {    "lvim.core.bufferline",    "lvim.core.autopairs",    "lvim.core.comment", +  "lvim.core.notify",    "lvim.core.lualine",  } diff --git a/lua/lvim/core/log.lua b/lua/lvim/core/log.lua index 9ddc641f..9950af28 100644 --- a/lua/lvim/core/log.lua +++ b/lua/lvim/core/log.lua @@ -18,22 +18,22 @@ 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 +  local notify_handler = require "lvim.core.notify" + +  ---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 entry +    return false    end -  local nvim_notify_default_namer = function(logger, entry) -    entry["title"] = logger.name -    return entry -  end - -  nvim_notify_params_injecter(nil, {})    local log_level = Log.levels[(lvim.log.level):upper() or "WARN"] -  structlog.configure { +  local lvim_log = {      lvim = {        sinks = {          structlog.sinks.Console(log_level, { @@ -49,25 +49,6 @@ function Log:init()              { level = structlog.formatters.FormatColorizer.color_level() }            ),          }), -        structlog.sinks.NvimNotify(Log.levels.INFO, { -          processors = { -            nvim_notify_default_namer, -            nvim_notify_params_injecter, -          }, -          formatter = structlog.formatters.Format( -- -            "%s", -            { "msg" }, -            { blacklist_all = true } -          ), -          params_map = { -            icon = "icon", -            keep = "keep", -            on_open = "on_open", -            on_close = "on_close", -            timeout = "timeout", -            title = "title", -          }, -        }),          structlog.sinks.File(Log.levels.TRACE, logfile, {            processors = {              structlog.processors.Namer(), @@ -83,15 +64,37 @@ function Log:init()      },    } +  if is_notify_available() then +    table.insert( +      lvim_log.lvim.sinks, +      structlog.sinks.NvimNotify(Log.levels.INFO, { +        processors = { +          notify_handler.default_namer, +          notify_handler.params_injecter, +        }, +        formatter = structlog.formatters.Format( -- +          "%s", +          { "msg" }, +          { blacklist_all = true } +        ), +        params_map = { +          icon = "icon", +          keep = "keep", +          on_open = "on_open", +          on_close = "on_close", +          timeout = "timeout", +          title = "title", +        }, +      }) +    ) +  end + +  structlog.configure(lvim_log) +    local logger = structlog.get_logger "lvim"    if lvim.log.override_notify then -    -- Overwrite vim.notify to use the logger -    vim.notify = function(msg, vim_log_level, opts) -      nvim_notify_params = opts or {} -      -- https://github.com/neovim/neovim/blob/685cf398130c61c158401b992a1893c2405cd7d2/runtime/lua/vim/lsp/log.lua#L5 -      logger:log(vim_log_level + 1, msg) -    end +    logger:log(Log.levels.INFO, "Ignoring request to override vim.notify with structlog due to instabilities")    end    return logger @@ -102,7 +105,7 @@ end  ---@param level string [same as vim.log.log_levels]  function Log:add_entry(level, msg, event)    if self.__handle then -    self.__handle:log(level, msg, event) +    self.__handle:log(level, vim.inspect(msg), event)      return    end @@ -112,7 +115,7 @@ function Log:add_entry(level, msg, event)    end    self.__handle = logger -  self.__handle:log(level, msg, event) +  self.__handle:log(level, vim.inspect(msg), event)  end  ---Retrieves the path of the logfile diff --git a/lua/lvim/core/lualine/components.lua b/lua/lvim/core/lualine/components.lua index b10fdad9..9366df56 100644 --- a/lua/lvim/core/lualine/components.lua +++ b/lua/lvim/core/lualine/components.lua @@ -122,11 +122,14 @@ return {    progress = { "progress", cond = conditions.hide_in_width, color = {} },    spaces = {      function() -      local label = "Spaces: "        if not vim.api.nvim_buf_get_option(0, "expandtab") then -        label = "Tab size: " +        return "Tab size: " .. vim.api.nvim_buf_get_option(0, "tabstop") .. " "        end -      return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " +      local size = vim.api.nvim_buf_get_option(0, "shiftwidth") +      if size == 0 then +        size = vim.api.nvim_buf_get_option(0, "tabstop") +      end +      return "Spaces: " .. size .. " "      end,      cond = conditions.hide_in_width,      color = {}, diff --git a/lua/lvim/core/notify.lua b/lua/lvim/core/notify.lua new file mode 100644 index 00000000..5339357b --- /dev/null +++ b/lua/lvim/core/notify.lua @@ -0,0 +1,45 @@ +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 one of { "fade", "slide", "fade_in_slide_out", "static" } +      stages = "slide", + +      ---@usage timeout for notifications in ms, default 5000 +      timeout = 5000, + +      ---@usage highlight behind the window for stages that change opacity +      background_colour = pallete.fg, + +      ---@usage Icons for the different levels +      icons = { +        ERROR = "", +        WARN = "", +        INFO = "", +        DEBUG = "", +        TRACE = "✎", +      }, +    }, +  } +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  | 
