Skip to content

Commit 0ecd19a

Browse files
committed
feat: configurable notification level
add `notify.default_level` to setup opts
1 parent 1be1e17 commit 0ecd19a

File tree

17 files changed

+110
-61
lines changed

17 files changed

+110
-61
lines changed

doc/nvim-tree-lua.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ Subsequent calls to setup will replace the previous configuration.
370370
watcher = false,
371371
},
372372
},
373+
notify = {
374+
default_level = vim.log.levels.INFO
375+
}
373376
} -- END_DEFAULT_OPTS
374377
<
375378

@@ -1035,6 +1038,13 @@ Configuration for diagnostic logging.
10351038
|nvim-tree.filesystem_watchers| processing, verbose.
10361039
Type: `boolean`, Default: `false`
10371040

1041+
*nvim-tree.notify*
1042+
Configuration for notification.
1043+
1044+
*nvim-tree.notify.default_level*
1045+
Specify notification level, uses the values from |vim.log.levels|
1046+
Type: `enum`, Default: `vim.log.levels.INFO`
1047+
10381048
==============================================================================
10391049
4.1 VINEGAR STYLE *nvim-tree-vinegar*
10401050

lua/nvim-tree.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local api = vim.api
33

44
local lib = require "nvim-tree.lib"
55
local log = require "nvim-tree.log"
6+
local notify = require "nvim-tree.notify"
67
local colors = require "nvim-tree.colors"
78
local renderer = require "nvim-tree.renderer"
89
local view = require "nvim-tree.view"
@@ -653,6 +654,9 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
653654
watcher = false,
654655
},
655656
},
657+
notify = {
658+
default_level = vim.log.levels.INFO,
659+
},
656660
} -- END_DEFAULT_OPTS
657661

658662
local function merge_options(conf)
@@ -708,13 +712,13 @@ local function validate_options(conf)
708712
validate(conf, DEFAULT_OPTS, "")
709713

710714
if msg then
711-
utils.notify.warn(msg .. " | see :help nvim-tree-setup for available configuration options")
715+
notify.warn(msg .. " | see :help nvim-tree-setup for available configuration options")
712716
end
713717
end
714718

715719
function M.setup(conf)
716720
if vim.fn.has "nvim-0.7" == 0 then
717-
utils.notify.warn "nvim-tree.lua requires Neovim 0.7 or higher"
721+
notify.warn "nvim-tree.lua requires Neovim 0.7 or higher"
718722
return
719723
end
720724

@@ -741,6 +745,7 @@ function M.setup(conf)
741745
manage_netrw(opts.disable_netrw, opts.hijack_netrw)
742746

743747
M.config = opts
748+
require("nvim-tree.notify").setup(opts)
744749
require("nvim-tree.log").setup(opts)
745750

746751
log.line("config", "default config + user")

lua/nvim-tree/actions/fs/copy-paste.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local lib = require "nvim-tree.lib"
44
local log = require "nvim-tree.log"
55
local utils = require "nvim-tree.utils"
66
local core = require "nvim-tree.core"
7+
local notify = require "nvim-tree.notify"
78

89
local M = {}
910

@@ -81,14 +82,14 @@ local function do_single_paste(source, dest, action_type, action_fn)
8182

8283
dest_stats, errmsg, errcode = uv.fs_stat(dest)
8384
if not dest_stats and errcode ~= "ENOENT" then
84-
utils.notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
85+
notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
8586
return false, errmsg
8687
end
8788

8889
local function on_process()
8990
success, errmsg = action_fn(source, dest)
9091
if not success then
91-
utils.notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
92+
notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
9293
return false, errmsg
9394
end
9495
end
@@ -122,11 +123,11 @@ local function add_to_clipboard(node, clip)
122123
for idx, _node in ipairs(clip) do
123124
if _node.absolute_path == node.absolute_path then
124125
table.remove(clip, idx)
125-
return utils.notify.info(node.absolute_path .. " removed to clipboard.")
126+
return notify.info(node.absolute_path .. " removed to clipboard.")
126127
end
127128
end
128129
table.insert(clip, node)
129-
utils.notify.info(node.absolute_path .. " added to clipboard.")
130+
notify.info(node.absolute_path .. " added to clipboard.")
130131
end
131132

132133
function M.copy(node)
@@ -151,7 +152,7 @@ local function do_paste(node, action_type, action_fn)
151152
local stats, errmsg, errcode = uv.fs_stat(destination)
152153
if not stats and errcode ~= "ENOENT" then
153154
log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, errmsg)
154-
utils.notify.error("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???"))
155+
notify.error("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???"))
155156
return
156157
end
157158
local is_dir = stats and stats.type == "directory"
@@ -213,18 +214,18 @@ function M.print_clipboard()
213214
end
214215
end
215216

216-
return utils.notify.info(table.concat(content, "\n") .. "\n")
217+
return notify.info(table.concat(content, "\n") .. "\n")
217218
end
218219

219220
local function copy_to_clipboard(content)
220221
if M.use_system_clipboard == true then
221222
vim.fn.setreg("+", content)
222223
vim.fn.setreg('"', content)
223-
return utils.notify.info(string.format("Copied %s to system clipboard!", content))
224+
return notify.info(string.format("Copied %s to system clipboard!", content))
224225
else
225226
vim.fn.setreg('"', content)
226227
vim.fn.setreg("1", content)
227-
return utils.notify.info(string.format("Copied %s to neovim clipboard!", content))
228+
return notify.info(string.format("Copied %s to neovim clipboard!", content))
228229
end
229230
end
230231

lua/nvim-tree/actions/fs/create-file.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ local events = require "nvim-tree.events"
55
local lib = require "nvim-tree.lib"
66
local core = require "nvim-tree.core"
77
local watch = require "nvim-tree.explorer.watch"
8+
local notify = require "nvim-tree.notify"
89

910
local M = {}
1011

1112
local function create_and_notify(file)
1213
local ok, fd = pcall(uv.fs_open, file, "w", 420)
1314
if not ok then
14-
utils.notify.error("Couldn't create file " .. file)
15+
notify.error("Couldn't create file " .. file)
1516
return
1617
end
1718
uv.fs_close(fd)
@@ -71,7 +72,7 @@ function M.fn(node)
7172
end
7273

7374
if utils.file_exists(new_file_path) then
74-
utils.notify.warn "Cannot create: file already exists"
75+
notify.warn "Cannot create: file already exists"
7576
return
7677
end
7778

@@ -96,14 +97,14 @@ function M.fn(node)
9697
elseif not utils.file_exists(path_to_create) then
9798
local success = uv.fs_mkdir(path_to_create, 493)
9899
if not success then
99-
utils.notify.error("Could not create folder " .. path_to_create)
100+
notify.error("Could not create folder " .. path_to_create)
100101
is_error = true
101102
break
102103
end
103104
end
104105
end
105106
if not is_error then
106-
utils.notify.info(new_file_path .. " was properly created")
107+
notify.info(new_file_path .. " was properly created")
107108
end
108109
events._dispatch_folder_created(new_file_path)
109110
if M.enable_reload then

lua/nvim-tree/actions/fs/remove-file.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local utils = require "nvim-tree.utils"
55
local events = require "nvim-tree.events"
66
local view = require "nvim-tree.view"
77
local lib = require "nvim-tree.lib"
8+
local notify = require "nvim-tree.notify"
89

910
local M = {}
1011

@@ -44,7 +45,7 @@ end
4445
local function remove_dir(cwd)
4546
local handle = luv.fs_scandir(cwd)
4647
if type(handle) == "string" then
47-
return utils.notify.error(handle)
48+
return notify.error(handle)
4849
end
4950

5051
while true do
@@ -83,18 +84,18 @@ function M.fn(node)
8384
if node.nodes ~= nil and not node.link_to then
8485
local success = remove_dir(node.absolute_path)
8586
if not success then
86-
return utils.notify.error("Could not remove " .. node.name)
87+
return notify.error("Could not remove " .. node.name)
8788
end
8889
events._dispatch_folder_removed(node.absolute_path)
8990
else
9091
local success = luv.fs_unlink(node.absolute_path)
9192
if not success then
92-
return utils.notify.error("Could not remove " .. node.name)
93+
return notify.error("Could not remove " .. node.name)
9394
end
9495
events._dispatch_file_removed(node.absolute_path)
9596
clear_buffer(node.absolute_path)
9697
end
97-
utils.notify.info(node.absolute_path .. " was properly removed.")
98+
notify.info(node.absolute_path .. " was properly removed.")
9899
if M.enable_reload then
99100
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
100101
end

lua/nvim-tree/actions/fs/rename-file.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local uv = vim.loop
33
local lib = require "nvim-tree.lib"
44
local utils = require "nvim-tree.utils"
55
local events = require "nvim-tree.events"
6+
local notify = require "nvim-tree.notify"
67

78
local M = {}
89

@@ -12,15 +13,15 @@ end
1213

1314
function M.rename(node, to)
1415
if utils.file_exists(to) then
15-
utils.notify.warn(err_fmt(node.absolute_path, to, "file already exists"))
16+
notify.warn(err_fmt(node.absolute_path, to, "file already exists"))
1617
return
1718
end
1819

1920
local success, err = uv.fs_rename(node.absolute_path, to)
2021
if not success then
21-
return utils.notify.warn(err_fmt(node.absolute_path, to, err))
22+
return notify.warn(err_fmt(node.absolute_path, to, err))
2223
end
23-
utils.notify.info(node.absolute_path .. "" .. to)
24+
notify.info(node.absolute_path .. "" .. to)
2425
utils.rename_loaded_buffers(node.absolute_path, to)
2526
events._dispatch_node_renamed(node.absolute_path, to)
2627
end

lua/nvim-tree/actions/fs/trash.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local a = vim.api
22

33
local lib = require "nvim-tree.lib"
4+
local notify = require "nvim-tree.notify"
45

56
local M = {
67
config = {
@@ -43,13 +44,13 @@ function M.fn(node)
4344
M.config.trash.require_confirm = true
4445
end
4546
else
46-
utils.notify.warn "Trash is currently a UNIX only feature!"
47+
notify.warn "Trash is currently a UNIX only feature!"
4748
return
4849
end
4950

5051
local binary = M.config.trash.cmd:gsub(" .*$", "")
5152
if vim.fn.executable(binary) == 0 then
52-
utils.notify.warn(binary .. " is not executable.")
53+
notify.warn(binary .. " is not executable.")
5354
return
5455
end
5556

@@ -71,7 +72,7 @@ function M.fn(node)
7172
if node.nodes ~= nil and not node.link_to then
7273
trash_path(function(_, rc)
7374
if rc ~= 0 then
74-
utils.notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
75+
notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
7576
return
7677
end
7778
events._dispatch_folder_removed(node.absolute_path)
@@ -82,7 +83,7 @@ function M.fn(node)
8283
else
8384
trash_path(function(_, rc)
8485
if rc ~= 0 then
85-
utils.notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
86+
notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
8687
return
8788
end
8889
events._dispatch_file_removed(node.absolute_path)

lua/nvim-tree/actions/tree-modifiers/expand-all.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local core = require "nvim-tree.core"
22
local renderer = require "nvim-tree.renderer"
3-
local utils = require "nvim-tree.utils"
43
local Iterator = require "nvim-tree.iterators.node-iterator"
4+
local notify = require "nvim-tree.notify"
55

66
local M = {}
77

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

lua/nvim-tree/events.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local utils = require "nvim-tree.utils"
1+
local notify = require "nvim-tree.notify"
22

33
local M = {}
44

@@ -30,7 +30,7 @@ local function dispatch(event_name, payload)
3030
for _, handler in pairs(get_handlers(event_name)) do
3131
local success, error = pcall(handler, payload)
3232
if not success then
33-
utils.notify.error("Handler for event " .. event_name .. " errored. " .. vim.inspect(error))
33+
notify.error("Handler for event " .. event_name .. " errored. " .. vim.inspect(error))
3434
end
3535
end
3636
end

lua/nvim-tree/explorer/explore.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local common = require "nvim-tree.explorer.common"
66
local sorters = require "nvim-tree.explorer.sorters"
77
local filters = require "nvim-tree.explorer.filters"
88
local live_filter = require "nvim-tree.live-filter"
9+
local notify = require "nvim-tree.notify"
910

1011
local M = {}
1112

@@ -52,7 +53,7 @@ end
5253
local function get_dir_handle(cwd)
5354
local handle = uv.fs_scandir(cwd)
5455
if type(handle) == "string" then
55-
utils.notify.error(handle)
56+
notify.error(handle)
5657
return
5758
end
5859
return handle

lua/nvim-tree/explorer/reload.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local common = require "nvim-tree.explorer.common"
66
local filters = require "nvim-tree.explorer.filters"
77
local sorters = require "nvim-tree.explorer.sorters"
88
local live_filter = require "nvim-tree.live-filter"
9+
local notify = require "nvim-tree.notify"
910

1011
local M = {}
1112

@@ -22,7 +23,7 @@ function M.reload(node, status)
2223
local cwd = node.link_to or node.absolute_path
2324
local handle = uv.fs_scandir(cwd)
2425
if type(handle) == "string" then
25-
utils.notify.error(handle)
26+
notify.error(handle)
2627
return
2728
end
2829

lua/nvim-tree/legacy.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local utils = require "nvim-tree.utils"
2+
local notify = require "nvim-tree.notify"
23

34
local M = {}
45

@@ -292,12 +293,12 @@ end
292293

293294
local function removed(opts)
294295
if opts.auto_close then
295-
utils.notify.warn "auto close feature has been removed, see note in the README (tips & reminder section)"
296+
notify.warn "auto close feature has been removed, see note in the README (tips & reminder section)"
296297
opts.auto_close = nil
297298
end
298299

299300
if opts.focus_empty_on_setup then
300-
utils.notify.warn "focus_empty_on_setup has been removed and will be replaced by a new startup configuration. Please remove this option. See https://bit.ly/3yJch2T"
301+
notify.warn "focus_empty_on_setup has been removed and will be replaced by a new startup configuration. Please remove this option. See https://bit.ly/3yJch2T"
301302
end
302303
opts.focus_empty_on_setup = nil
303304
end
@@ -312,7 +313,7 @@ function M.migrate_legacy_options(opts)
312313
end
313314
end
314315
if msg then
315-
utils.notify.warn(msg)
316+
notify.warn(msg)
316317
end
317318

318319
-- silently move

0 commit comments

Comments
 (0)