chore: move nvim-tree.utils.warn -> notify.warn

add notify.error and notify.info
This commit is contained in:
kiyan 2022-07-18 13:46:11 +02:00
parent ec530e73be
commit 21fadc1f38
12 changed files with 40 additions and 29 deletions

View File

@ -640,13 +640,13 @@ local function validate_options(conf)
validate(conf, DEFAULT_OPTS, "")
if msg then
utils.warn(msg .. " | see :help nvim-tree-setup for available configuration options")
utils.notify.warn(msg .. " | see :help nvim-tree-setup for available configuration options")
end
end
function M.setup(conf)
if vim.fn.has "nvim-0.7" == 0 then
utils.warn "nvim-tree.lua requires Neovim 0.7 or higher"
utils.notify.warn "nvim-tree.lua requires Neovim 0.7 or higher"
return
end

View File

@ -65,7 +65,7 @@ function M.fn(node)
utils.clear_prompt()
if utils.file_exists(new_file_path) then
utils.warn "Cannot create: file already exists"
utils.notify.warn "Cannot create: file already exists"
return
end

View File

@ -13,13 +13,13 @@ end
function M.rename(node, to)
if utils.file_exists(to) then
utils.warn(err_fmt(node.absolute_path, to, "file already exists"))
utils.notify.warn(err_fmt(node.absolute_path, to, "file already exists"))
return
end
local success, err = uv.fs_rename(node.absolute_path, to)
if not success then
return utils.warn(err_fmt(node.absolute_path, to, err))
return utils.notify.warn(err_fmt(node.absolute_path, to, err))
end
utils.clear_prompt()
a.nvim_out_write(node.absolute_path .. "" .. to .. "\n")

View File

@ -41,13 +41,13 @@ function M.fn(node)
M.config.trash.require_confirm = true
end
else
utils.warn "Trash is currently a UNIX only feature!"
utils.notify.warn "Trash is currently a UNIX only feature!"
return
end
local binary = M.config.trash.cmd:gsub(" .*$", "")
if vim.fn.executable(binary) == 0 then
utils.warn(binary .. " is not executable.")
utils.notify.warn(binary .. " is not executable.")
return
end
@ -83,7 +83,7 @@ function M.fn(node)
if node.nodes ~= nil and not node.link_to then
trash_path(function(_, rc)
if rc ~= 0 then
utils.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
utils.notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
return
end
events._dispatch_folder_removed(node.absolute_path)
@ -94,7 +94,7 @@ function M.fn(node)
else
trash_path(function(_, rc)
if rc ~= 0 then
utils.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
utils.notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
return
end
events._dispatch_file_removed(node.absolute_path)

View File

@ -305,7 +305,7 @@ local function merge_mappings(user_mappings)
if not is_empty(map.action) then
M.custom_keypress_funcs[map.action] = map.action_cb
else
util.warn "action can't be empty if action_cb provided"
util.notify.warn "action can't be empty if action_cb provided"
end
end
end

View File

@ -10,7 +10,7 @@ local M = {
function M.fn(node)
if #M.config.system_open.cmd == 0 then
require("nvim-tree.utils").warn "Cannot open file with system application. Unrecognized platform."
require("nvim-tree.utils").notify.warn "Cannot open file with system application. Unrecognized platform."
return
end

View File

@ -58,7 +58,7 @@ end
function M.fn(base_node)
local node = base_node.nodes and base_node or core.get_explorer()
if gen_iterator()(node) then
utils.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")
utils.notify.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")
end
renderer.draw()
end

View File

@ -292,7 +292,7 @@ end
local function removed(opts)
if opts.auto_close then
utils.warn "auto close feature has been removed, see note in the README (tips & reminder section)"
utils.notify.warn "auto close feature has been removed, see note in the README (tips & reminder section)"
opts.auto_close = nil
end
end
@ -307,7 +307,7 @@ function M.migrate_legacy_options(opts)
end
end
if msg then
utils.warn(msg)
utils.notify.warn(msg)
end
-- silently move

View File

@ -7,7 +7,7 @@ local M = {}
function M.bulk_move()
if #Marks.get_marks() == 0 then
utils.warn "no bookmark to perform bulk move on, aborting."
utils.notify.warn "no bookmark to perform bulk move on, aborting."
return
end
@ -16,7 +16,7 @@ function M.bulk_move()
return
end
if vim.fn.filewritable(location) ~= 2 then
utils.warn(location .. " is not writable, cannot move.")
utils.notify.warn(location .. " is not writable, cannot move.")
return
end

View File

@ -68,7 +68,7 @@ end
local function nil_() end
local function warn_status(git_status)
utils.warn(
utils.notify.warn(
'Unrecognized git state "'
.. git_status
.. '". Please open up an issue on https://github.com/kyazdani42/nvim-tree.lua/issues with this message.'

View File

@ -15,16 +15,23 @@ function M.path_to_matching_str(path)
return path:gsub("(%-)", "(%%-)"):gsub("(%.)", "(%%.)"):gsub("(%_)", "(%%_)")
end
function M.warn(msg)
vim.schedule(function()
if has_notify then
notify(msg, vim.log.levels.WARN, { title = "NvimTree" })
else
vim.notify("[NvimTree] " .. msg, vim.log.levels.WARN)
end
end)
local function notify_level(level)
return function(msg)
vim.schedule(function()
if has_notify then
notify(msg, level, { title = "NvimTree" })
else
vim.notify("[NvimTree] " .. msg, level)
end
end)
end
end
M.notify = {}
M.notify.warn = notify_level(vim.log.levels.WARN)
M.notify.error = notify_level(vim.log.levels.ERROR)
M.notify.info = notify_level(vim.log.levels.INFO)
function M.str_find(haystack, needle)
return vim.fn.stridx(haystack, needle) ~= -1
end
@ -260,7 +267,7 @@ function M.move_missing_val(src, src_path, src_pos, dst, dst_path, dst_pos)
dst_pos = { dst_pos, "string" },
})
if not ok then
M.warn("move_missing_val: " .. (err or "invalid arguments"))
M.notify.warn("move_missing_val: " .. (err or "invalid arguments"))
end
for pos in string.gmatch(src_path, "([^%.]+)%.*") do

View File

@ -45,7 +45,7 @@ function Watcher:start()
self._e, _, name = uv.new_fs_event()
if not self._e then
self._e = nil
utils.warn(
utils.notify.warn(
string.format("Could not initialize an fs_event watcher for path %s : %s", self._opts.absolute_path, name)
)
return nil
@ -62,7 +62,9 @@ function Watcher:start()
rc, _, name = self._e:start(self._opts.absolute_path, FS_EVENT_FLAGS, event_cb)
if rc ~= 0 then
utils.warn(string.format("Could not start the fs_event watcher for path %s : %s", self._opts.absolute_path, name))
utils.notify.warn(
string.format("Could not start the fs_event watcher for path %s : %s", self._opts.absolute_path, name)
)
return nil
end
@ -74,7 +76,9 @@ function Watcher:destroy()
if self._e then
local rc, _, name = self._e:stop()
if rc ~= 0 then
utils.warn(string.format("Could not stop the fs_event watcher for path %s : %s", self._opts.absolute_path, name))
utils.notify.warn(
string.format("Could not stop the fs_event watcher for path %s : %s", self._opts.absolute_path, name)
)
end
self._e = nil
end