nvim-tree.lua/lua/nvim-tree/notify.lua
Azad 13f967f8e7
chore: add type annotations and resolve LSP warnings (#2555)
* chore: add type annotations to (almost) all functions

* stylua

* Add classes for symlink nodes

* Replace deprecated `@vararg`

* Move node classes to `node` module

* Fix `Symlink*` classes

* add vim and libuv runtime for luals, qualify libuv types

* add scripts/luals-check, not quite ready for CI

* additional nil checks for git/init.lua and git/runner.lua

* additional nil checks for nvim-tree.lua

* wrap vim.cmd-as-a-function calls inside functions

* vim.tbl_filter predicate returns booleans

* Revert "add scripts/luals-check, not quite ready for CI"

This reverts commit c70229cad9.

* Add `MinimalNode` class in `marks` module

* Fix various LSP warnings

* stylua

* Fix `Explorer` class, update related annotations and add necessary checks

* Add missing annotations to `live-filter`

* Add temporary aliases for `uv.*` types

* Resolve remaining LSP warnings

* Revert changes not related to internal types

* Minor adjustments

* Update doc comments style

* Minor adjustments (pt. 2)

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
2023-12-09 11:34:35 +11:00

69 lines
1.7 KiB
Lua

local M = {}
local config = {
threshold = vim.log.levels.INFO,
absolute_path = true,
}
local title_support
---@return boolean
function M.supports_title()
if title_support == nil then
title_support = (package.loaded.notify and (vim.notify == require "notify" or vim.notify == require("notify").notify))
or (package.loaded.noice and (vim.notify == require("noice").notify or vim.notify == require("noice.source.notify").notify))
or (package.loaded.notifier and require("notifier.config").has_component "nvim")
or false
end
return title_support
end
local modes = {
{ name = "trace", level = vim.log.levels.TRACE },
{ name = "debug", level = vim.log.levels.DEBUG },
{ name = "info", level = vim.log.levels.INFO },
{ name = "warn", level = vim.log.levels.WARN },
{ name = "error", level = vim.log.levels.ERROR },
}
do
local dispatch = function(level, msg)
if level < config.threshold or not msg then
return
end
vim.schedule(function()
if not M.supports_title() then
-- add title to the message, with a newline if the message is multiline
msg = string.format("[NvimTree]%s%s", (msg:match "\n" and "\n" or " "), msg)
end
vim.notify(msg, level, { title = "NvimTree" })
end)
end
for _, x in ipairs(modes) do
M[x.name] = function(msg)
return dispatch(x.level, msg)
end
end
end
---@param path string
---@return string
function M.render_path(path)
if config.absolute_path then
return path
else
return vim.fn.fnamemodify(path .. "/", ":h:t")
end
end
function M.setup(opts)
opts = opts or {}
config.threshold = opts.notify.threshold or vim.log.levels.INFO
config.absolute_path = opts.notify.absolute_path
end
return M