Skip to content

Commit 5e1d7ff

Browse files
committed
Merge branch 'master' into chore-remove-vim-quote-requires-quote
2 parents 56b6262 + a0f3e99 commit 5e1d7ff

25 files changed

+211
-87
lines changed

doc/nvim-tree-lua.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ Subsequent calls to setup will replace the previous configuration.
308308
filesystem_watchers = {
309309
enable = true,
310310
debounce_delay = 50,
311+
ignore_dirs = {},
311312
},
312313
git = {
313314
enable = true,
@@ -373,6 +374,9 @@ Subsequent calls to setup will replace the previous configuration.
373374
watcher = false,
374375
},
375376
},
377+
notify = {
378+
threshold = vim.log.levels.INFO,
379+
},
376380
} -- END_DEFAULT_OPTS
377381
<
378382

@@ -601,6 +605,12 @@ performance.
601605
Idle milliseconds between filesystem change and action.
602606
Type: `number`, Default: `50` (ms)
603607

608+
*nvim-tree.filesystem_watchers.ignore_dirs*
609+
List of vim regex for absolute directory paths that will not be watched.
610+
Backslashes must be escaped e.g. `"my-project/\\.build$"`. See |string-match|.
611+
Useful when path is not in `.gitignore` or git integration is disabled.
612+
Type: {string}, Default: `{}`
613+
604614
*nvim-tree.on_attach*
605615
Function ran when creating the nvim-tree buffer.
606616
This can be used to attach keybindings to the tree buffer.
@@ -992,6 +1002,18 @@ The filter can be cleared with the `F` key by default.
9921002
Whether to filter folders or not.
9931003
Type: `boolean`, Default: `true`
9941004

1005+
*nvim-tree.notify*
1006+
Configuration for notification.
1007+
1008+
*nvim-tree.notify.threshold*
1009+
Specify minimum notification level, uses the values from |vim.log.levels|
1010+
Type: `enum`, Default: `vim.log.levels.INFO`
1011+
1012+
`ERROR`: hard errors e.g. failure to read from the file system.
1013+
`WARNING`: non-fatal errors e.g. unable to system open a file.
1014+
`INFO:` information only e.g. file copy path confirmation.
1015+
`DEBUG:` not used.
1016+
9951017
*nvim-tree.log*
9961018
Configuration for diagnostic logging.
9971019

@@ -1125,6 +1147,7 @@ exists.
11251147
- rename_sub
11261148
- cut
11271149
- paste
1150+
- clear_clipboard
11281151
- print_clipboard
11291152
- copy.node
11301153
- copy.absolute_path
@@ -1168,6 +1191,7 @@ exists.
11681191
- get
11691192
- list
11701193
- toggle
1194+
- clear
11711195
- bulk.move
11721196
- navigate.next
11731197
- navigate.prev
@@ -1426,9 +1450,10 @@ Handlers are registered by calling the `events.subscribe` function available in
14261450
For example, registering a handler for when a node is renamed is done like this:
14271451
>
14281452
local api = require('nvim-tree.api')
1453+
local Event = api.events.Event
14291454
14301455
api.events.subscribe(Event.NodeRenamed, function(data)
1431-
print("Node renamed from " .. data.old_name .. " to " .. data.new_name)
1456+
print("Node renamed from " .. data.old_name .. " to " .. data.new_name)
14321457
end)
14331458
<
14341459

lua/nvim-tree.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
586586
filesystem_watchers = {
587587
enable = true,
588588
debounce_delay = 50,
589+
ignore_dirs = {},
589590
},
590591
git = {
591592
enable = true,
@@ -637,6 +638,9 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
637638
prefix = "[FILTER]: ",
638639
always_show_folders = true,
639640
},
641+
notify = {
642+
threshold = vim.log.levels.INFO,
643+
},
640644
log = {
641645
enable = false,
642646
truncate = false,
@@ -683,10 +687,11 @@ local function validate_options(conf)
683687
local override_typecheck = FIELD_OVERRIDE_TYPECHECK[k] or {}
684688
if def[k] == nil then
685689
-- option does not exist
686-
invalid = string.format("unknown option: %s%s", prefix, k)
690+
invalid = string.format("[NvimTree] unknown option: %s%s", prefix, k)
687691
elseif type(v) ~= type(def[k]) and not override_typecheck[type(v)] then
688692
-- option is of the wrong type and is not a function
689-
invalid = string.format("invalid option: %s%s expected: %s actual: %s", prefix, k, type(def[k]), type(v))
693+
invalid =
694+
string.format("[NvimTree] invalid option: %s%s expected: %s actual: %s", prefix, k, type(def[k]), type(v))
690695
end
691696

692697
if invalid then
@@ -706,13 +711,13 @@ local function validate_options(conf)
706711
validate(conf, DEFAULT_OPTS, "")
707712

708713
if msg then
709-
utils.notify.warn(msg .. " | see :help nvim-tree-setup for available configuration options")
714+
vim.notify_once(msg .. " | see :help nvim-tree-setup for available configuration options", vim.log.levels.WARN)
710715
end
711716
end
712717

713718
function M.setup(conf)
714719
if vim.fn.has "nvim-0.7" == 0 then
715-
utils.notify.warn "nvim-tree.lua requires Neovim 0.7 or higher"
720+
vim.notify_once("nvim-tree.lua requires Neovim 0.7 or higher", vim.log.levels.WARN)
716721
return
717722
end
718723

@@ -739,6 +744,7 @@ function M.setup(conf)
739744
manage_netrw(opts.disable_netrw, opts.hijack_netrw)
740745

741746
M.config = opts
747+
require("nvim-tree.notify").setup(opts)
742748
require("nvim-tree.log").setup(opts)
743749

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

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local lib = require "nvim-tree.lib"
22
local log = require "nvim-tree.log"
33
local utils = require "nvim-tree.utils"
44
local core = require "nvim-tree.core"
5+
local notify = require "nvim-tree.notify"
56

67
local M = {}
78

@@ -79,14 +80,14 @@ local function do_single_paste(source, dest, action_type, action_fn)
7980

8081
dest_stats, errmsg, errcode = vim.loop.fs_stat(dest)
8182
if not dest_stats and errcode ~= "ENOENT" then
82-
utils.notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
83+
notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
8384
return false, errmsg
8485
end
8586

8687
local function on_process()
8788
success, errmsg = action_fn(source, dest)
8889
if not success then
89-
utils.notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
90+
notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
9091
return false, errmsg
9192
end
9293
end
@@ -120,11 +121,17 @@ local function add_to_clipboard(node, clip)
120121
for idx, _node in ipairs(clip) do
121122
if _node.absolute_path == node.absolute_path then
122123
table.remove(clip, idx)
123-
return utils.notify.info(node.absolute_path .. " removed to clipboard.")
124+
return notify.info(node.absolute_path .. " removed to clipboard.")
124125
end
125126
end
126127
table.insert(clip, node)
127-
utils.notify.info(node.absolute_path .. " added to clipboard.")
128+
notify.info(node.absolute_path .. " added to clipboard.")
129+
end
130+
131+
function M.clear_clipboard()
132+
clipboard.move = {}
133+
clipboard.copy = {}
134+
utils.notify.info "Clipboard has been emptied."
128135
end
129136

130137
function M.copy(node)
@@ -149,7 +156,7 @@ local function do_paste(node, action_type, action_fn)
149156
local stats, errmsg, errcode = vim.loop.fs_stat(destination)
150157
if not stats and errcode ~= "ENOENT" then
151158
log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, errmsg)
152-
utils.notify.error("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???"))
159+
notify.error("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???"))
153160
return
154161
end
155162
local is_dir = stats and stats.type == "directory"
@@ -211,18 +218,18 @@ function M.print_clipboard()
211218
end
212219
end
213220

214-
return utils.notify.info(table.concat(content, "\n") .. "\n")
221+
return notify.info(table.concat(content, "\n") .. "\n")
215222
end
216223

217224
local function copy_to_clipboard(content)
218225
if M.use_system_clipboard == true then
219226
vim.fn.setreg("+", content)
220227
vim.fn.setreg('"', content)
221-
return utils.notify.info(string.format("Copied %s to system clipboard!", content))
228+
return notify.info(string.format("Copied %s to system clipboard!", content))
222229
else
223230
vim.fn.setreg('"', content)
224231
vim.fn.setreg("1", content)
225-
return utils.notify.info(string.format("Copied %s to neovim clipboard!", content))
232+
return notify.info(string.format("Copied %s to neovim clipboard!", content))
226233
end
227234
end
228235

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ local events = require "nvim-tree.events"
33
local lib = require "nvim-tree.lib"
44
local core = require "nvim-tree.core"
55
local watch = require "nvim-tree.explorer.watch"
6+
local notify = require "nvim-tree.notify"
67

78
local M = {}
89

910
local function create_and_notify(file)
1011
local ok, fd = pcall(vim.loop.fs_open, file, "w", 420)
1112
if not ok then
12-
utils.notify.error("Couldn't create file " .. file)
13+
notify.error("Couldn't create file " .. file)
1314
return
1415
end
1516
vim.loop.fs_close(fd)
@@ -69,7 +70,7 @@ function M.fn(node)
6970
end
7071

7172
if utils.file_exists(new_file_path) then
72-
utils.notify.warn "Cannot create: file already exists"
73+
notify.warn "Cannot create: file already exists"
7374
return
7475
end
7576

@@ -94,14 +95,14 @@ function M.fn(node)
9495
elseif not utils.file_exists(path_to_create) then
9596
local success = vim.loop.fs_mkdir(path_to_create, 493)
9697
if not success then
97-
utils.notify.error("Could not create folder " .. path_to_create)
98+
notify.error("Could not create folder " .. path_to_create)
9899
is_error = true
99100
break
100101
end
101102
end
102103
end
103104
if not is_error then
104-
utils.notify.info(new_file_path .. " was properly created")
105+
notify.info(new_file_path .. " was properly created")
105106
end
106107
events._dispatch_folder_created(new_file_path)
107108
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
@@ -2,6 +2,7 @@ local utils = require "nvim-tree.utils"
22
local events = require "nvim-tree.events"
33
local view = require "nvim-tree.view"
44
local lib = require "nvim-tree.lib"
5+
local notify = require "nvim-tree.notify"
56

67
local M = {}
78

@@ -41,7 +42,7 @@ end
4142
local function remove_dir(cwd)
4243
local handle = vim.loop.fs_scandir(cwd)
4344
if type(handle) == "string" then
44-
return utils.notify.error(handle)
45+
return notify.error(handle)
4546
end
4647

4748
while true do
@@ -80,18 +81,18 @@ function M.fn(node)
8081
if node.nodes ~= nil and not node.link_to then
8182
local success = remove_dir(node.absolute_path)
8283
if not success then
83-
return utils.notify.error("Could not remove " .. node.name)
84+
return notify.error("Could not remove " .. node.name)
8485
end
8586
events._dispatch_folder_removed(node.absolute_path)
8687
else
8788
local success = vim.loop.fs_unlink(node.absolute_path)
8889
if not success then
89-
return utils.notify.error("Could not remove " .. node.name)
90+
return notify.error("Could not remove " .. node.name)
9091
end
9192
events._dispatch_file_removed(node.absolute_path)
9293
clear_buffer(node.absolute_path)
9394
end
94-
utils.notify.info(node.absolute_path .. " was properly removed.")
95+
notify.info(node.absolute_path .. " was properly removed.")
9596
if M.enable_reload then
9697
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
9798
end

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local lib = require "nvim-tree.lib"
22
local utils = require "nvim-tree.utils"
33
local events = require "nvim-tree.events"
4+
local notify = require "nvim-tree.notify"
45

56
local M = {}
67

@@ -10,15 +11,15 @@ end
1011

1112
function M.rename(node, to)
1213
if utils.file_exists(to) then
13-
utils.notify.warn(err_fmt(node.absolute_path, to, "file already exists"))
14+
notify.warn(err_fmt(node.absolute_path, to, "file already exists"))
1415
return
1516
end
1617

1718
local success, err = vim.loop.fs_rename(node.absolute_path, to)
1819
if not success then
19-
return utils.notify.warn(err_fmt(node.absolute_path, to, err))
20+
return notify.warn(err_fmt(node.absolute_path, to, err))
2021
end
21-
utils.notify.info(node.absolute_path .. "" .. to)
22+
notify.info(node.absolute_path .. "" .. to)
2223
utils.rename_loaded_buffers(node.absolute_path, to)
2324
events._dispatch_node_renamed(node.absolute_path, to)
2425
end

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

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

34
local M = {
45
config = {
@@ -41,13 +42,13 @@ function M.fn(node)
4142
M.config.trash.require_confirm = true
4243
end
4344
else
44-
utils.notify.warn "Trash is currently a UNIX only feature!"
45+
notify.warn "Trash is currently a UNIX only feature!"
4546
return
4647
end
4748

4849
local binary = M.config.trash.cmd:gsub(" .*$", "")
4950
if vim.fn.executable(binary) == 0 then
50-
utils.notify.warn(binary .. " is not executable.")
51+
notify.warn(binary .. " is not executable.")
5152
return
5253
end
5354

@@ -69,7 +70,7 @@ function M.fn(node)
6970
if node.nodes ~= nil and not node.link_to then
7071
trash_path(function(_, rc)
7172
if rc ~= 0 then
72-
utils.notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
73+
notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
7374
return
7475
end
7576
events._dispatch_folder_removed(node.absolute_path)
@@ -80,7 +81,7 @@ function M.fn(node)
8081
else
8182
trash_path(function(_, rc)
8283
if rc ~= 0 then
83-
utils.notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
84+
notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
8485
return
8586
end
8687
events._dispatch_file_removed(node.absolute_path)

lua/nvim-tree/actions/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
local log = require "nvim-tree.log"
44
local view = require "nvim-tree.view"
5-
local util = require "nvim-tree.utils"
5+
local notify = require "nvim-tree.notify"
66

77
-- BEGIN_DEFAULT_MAPPINGS
88
local DEFAULT_MAPPINGS = {
@@ -305,7 +305,7 @@ local function merge_mappings(user_mappings)
305305
if not is_empty(map.action) then
306306
M.custom_keypress_funcs[map.action] = map.action_cb
307307
else
308-
util.notify.warn "action can't be empty if action_cb provided"
308+
notify.warn "action can't be empty if action_cb provided"
309309
end
310310
end
311311
end

0 commit comments

Comments
 (0)