feat(notify): switch all print/nvim_*write statements to utils.notify

This commit is contained in:
kiyan 2022-07-18 14:04:48 +02:00
parent 21fadc1f38
commit 18447132fc
9 changed files with 23 additions and 25 deletions

View File

@ -1,4 +1,3 @@
local a = vim.api
local uv = vim.loop
local lib = require "nvim-tree.lib"
@ -82,7 +81,7 @@ local function do_single_paste(source, dest, action_type, action_fn)
dest_stats, errmsg, errcode = uv.fs_stat(dest)
if not dest_stats and errcode ~= "ENOENT" then
a.nvim_err_writeln("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
utils.notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
return false, errmsg
end
@ -105,7 +104,7 @@ local function do_single_paste(source, dest, action_type, action_fn)
if should_process then
success, errmsg = action_fn(source, dest)
if not success then
a.nvim_err_writeln("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
utils.notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
return false, errmsg
end
end
@ -119,11 +118,11 @@ local function add_to_clipboard(node, clip)
for idx, _node in ipairs(clip) do
if _node.absolute_path == node.absolute_path then
table.remove(clip, idx)
return a.nvim_out_write(node.absolute_path .. " removed to clipboard.\n")
return utils.notify.info(node.absolute_path .. " removed to clipboard.\n")
end
end
table.insert(clip, node)
a.nvim_out_write(node.absolute_path .. " added to clipboard.\n")
utils.notify.info(node.absolute_path .. " added to clipboard.\n")
end
function M.copy(node)
@ -148,7 +147,7 @@ local function do_paste(node, action_type, action_fn)
local stats, errmsg, errcode = uv.fs_stat(destination)
if not stats and errcode ~= "ENOENT" then
log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, errmsg)
a.nvim_err_writeln("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???"))
utils.notify.error("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???"))
return
end
local is_dir = stats and stats.type == "directory"
@ -210,18 +209,18 @@ function M.print_clipboard()
end
end
return a.nvim_out_write(table.concat(content, "\n") .. "\n")
return utils.notify.info(table.concat(content, "\n") .. "\n")
end
local function copy_to_clipboard(content)
if M.use_system_clipboard == true then
vim.fn.setreg("+", content)
vim.fn.setreg('"', content)
return a.nvim_out_write(string.format("Copied %s to system clipboard! \n", content))
return utils.notify.info(string.format("Copied %s to system clipboard! \n", content))
else
vim.fn.setreg('"', content)
vim.fn.setreg("1", content)
return a.nvim_out_write(string.format("Copied %s to neovim clipboard \n", content))
return utils.notify.info(string.format("Copied %s to neovim clipboard \n", content))
end
end

View File

@ -1,4 +1,3 @@
local a = vim.api
local uv = vim.loop
local utils = require "nvim-tree.utils"
@ -19,7 +18,7 @@ local function create_file(file)
end
local ok, fd = pcall(uv.fs_open, file, "w", 420)
if not ok then
a.nvim_err_writeln("Couldn't create file " .. file)
utils.notify.error("Couldn't create file " .. file)
return
end
uv.fs_close(fd)
@ -90,14 +89,14 @@ function M.fn(node)
elseif not utils.file_exists(path_to_create) then
local success = uv.fs_mkdir(path_to_create, 493)
if not success then
a.nvim_err_writeln("Could not create folder " .. path_to_create)
utils.notify.error("Could not create folder " .. path_to_create)
is_error = true
break
end
end
end
if not is_error then
a.nvim_out_write(new_file_path .. " was properly created\n")
utils.notify.info(new_file_path .. " was properly created\n")
end
events._dispatch_folder_created(new_file_path)
if M.enable_reload then

View File

@ -36,7 +36,7 @@ end
local function remove_dir(cwd)
local handle = luv.fs_scandir(cwd)
if type(handle) == "string" then
return a.nvim_err_writeln(handle)
return utils.notify.error(handle)
end
while true do
@ -75,17 +75,18 @@ function M.fn(node)
if node.nodes ~= nil and not node.link_to then
local success = remove_dir(node.absolute_path)
if not success then
return a.nvim_err_writeln("Could not remove " .. node.name)
return utils.notify.error("Could not remove " .. node.name)
end
events._dispatch_folder_removed(node.absolute_path)
else
local success = luv.fs_unlink(node.absolute_path)
if not success then
return a.nvim_err_writeln("Could not remove " .. node.name)
return utils.notify.error("Could not remove " .. node.name)
end
events._dispatch_file_removed(node.absolute_path)
clear_buffer(node.absolute_path)
end
utils.notify.info(node.absolute_path .. " was properly removed.")
if M.enable_reload then
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end

View File

@ -1,4 +1,3 @@
local a = vim.api
local uv = vim.loop
local lib = require "nvim-tree.lib"
@ -21,8 +20,7 @@ function M.rename(node, to)
if not success then
return utils.notify.warn(err_fmt(node.absolute_path, to, err))
end
utils.clear_prompt()
a.nvim_out_write(node.absolute_path .. "" .. to .. "\n")
utils.notify.info(node.absolute_path .. "" .. to .. "\n")
utils.rename_loaded_buffers(node.absolute_path, to)
events._dispatch_node_renamed(node.absolute_path, to)
end

View File

@ -1,3 +1,5 @@
local utils = require "nvim-tree.utils"
local M = {}
local global_handlers = {}
@ -28,7 +30,7 @@ local function dispatch(event_name, payload)
for _, handler in pairs(get_handlers(event_name)) do
local success, error = pcall(handler, payload)
if not success then
vim.api.nvim_err_writeln("Handler for event " .. event_name .. " errored. " .. vim.inspect(error))
utils.notify.error("Handler for event " .. event_name .. " errored. " .. vim.inspect(error))
end
end
end

View File

@ -1,4 +1,3 @@
local api = vim.api
local uv = vim.loop
local utils = require "nvim-tree.utils"
@ -52,7 +51,7 @@ end
local function get_dir_handle(cwd)
local handle = uv.fs_scandir(cwd)
if type(handle) == "string" then
api.nvim_err_writeln(handle)
utils.notify.error(handle)
return
end
return handle

View File

@ -1,4 +1,3 @@
local api = vim.api
local uv = vim.loop
local utils = require "nvim-tree.utils"
@ -23,7 +22,7 @@ function M.reload(node, status)
local cwd = node.link_to or node.absolute_path
local handle = uv.fs_scandir(cwd)
if type(handle) == "string" then
api.nvim_err_writeln(handle)
utils.notify.error(handle)
return
end

View File

@ -56,7 +56,7 @@ function M.setup(opts)
if M.config.truncate then
os.remove(M.path)
end
print("nvim-tree.lua logging to " .. M.path)
require("nvim-tree.utils").notify.debug("nvim-tree.lua logging to " .. M.path)
end
end

View File

@ -31,6 +31,7 @@ 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)
M.notify.debug = notify_level(vim.log.levels.DEBUG)
function M.str_find(haystack, needle)
return vim.fn.stridx(haystack, needle) ~= -1