From 43ee24630d3aa355bdf0837d8d728713379e859c Mon Sep 17 00:00:00 2001 From: "wessel.blokzijl" Date: Fri, 28 Oct 2022 22:52:29 +0200 Subject: [PATCH 1/9] Sync closing of nvim-tree across tabs --- doc/nvim-tree-lua.txt | 3 ++- lua/nvim-tree.lua | 13 +++++++++---- lua/nvim-tree/actions/dispatch.lua | 4 +++- lua/nvim-tree/actions/node/open-file.lua | 4 ++-- lua/nvim-tree/api.lua | 2 +- lua/nvim-tree/lib.lua | 2 +- lua/nvim-tree/live-filter.lua | 2 +- lua/nvim-tree/view.lua | 11 ++++++++--- 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index b4244f2724f..47fff4716a4 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1049,8 +1049,9 @@ You can easily implement a toggle using this too: > local function toggle_replace() local view = require"nvim-tree.view" + local api = require"nvim-tree.api" if view.is_visible() then - view.close() + api.close() else require"nvim-tree".open_replacing_current_buffer() end diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index b87a2e483c2..f4a8d07330a 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -73,7 +73,7 @@ M.on_keypress = require("nvim-tree.actions.dispatch").dispatch function M.toggle(find_file, no_focus, cwd, bang) if view.is_visible() then - view.close() + M.close() else local previous_buf = api.nvim_get_current_buf() M.open(cwd) @@ -86,6 +86,11 @@ function M.toggle(find_file, no_focus, cwd, bang) end end +function M.close() + local config = M.get_config() + view.close(config.open_on_tab) +end + function M.open(cwd) cwd = cwd ~= "" and cwd or nil if view.is_visible() then @@ -441,7 +446,7 @@ local function setup_autocommands(opts) pattern = "NvimTree_*", callback = function() if utils.is_nvim_tree_buf(0) then - view.close() + M.close() end end, }) @@ -766,11 +771,11 @@ function M.setup(conf) require("nvim-tree.watcher").purge_watchers() if not M.setup_called then - setup_vim_commands() + setup_vim_commands(opts) end if M.setup_called and view.is_visible() then - view.close() + M.close() view.abandon_current_window() end diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index 44eff9834b0..63e34578d9b 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -1,10 +1,12 @@ +local api = vim.api + local view = require "nvim-tree.view" local lib = require "nvim-tree.lib" local M = {} local Actions = { - close = view.close, + close = api.close, -- Tree modifiers collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn, diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 6e09fea2e78..f23e4a032b9 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -126,7 +126,7 @@ end local function open_file_in_tab(filename) if M.quit_on_open then - view.close() + api.close() end vim.cmd("tabe " .. vim.fn.fnameescape(filename)) end @@ -280,7 +280,7 @@ function M.fn(mode, filename) end if M.quit_on_open then - view.close() + api.close() end end diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 4d9798e1bec..4779460f1fb 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -17,7 +17,7 @@ end Api.tree.open = require("nvim-tree").open Api.tree.toggle = require("nvim-tree").toggle -Api.tree.close = require("nvim-tree.view").close +Api.tree.close = require("nvim-tree").close Api.tree.focus = require("nvim-tree").focus Api.tree.reload = require("nvim-tree.actions.reloaders.reloaders").reload_explorer Api.tree.change_root = require("nvim-tree").change_dir diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index 93821fd6954..cc387f246bb 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -119,7 +119,7 @@ function M.open(cwd) core.init(cwd or vim.loop.cwd()) end if should_hijack_current_buf() then - view.close() + api.close() view.open_in_current_win() renderer.draw() else diff --git a/lua/nvim-tree/live-filter.lua b/lua/nvim-tree/live-filter.lua index 9143d9fe335..8dfdc90ddc5 100644 --- a/lua/nvim-tree/live-filter.lua +++ b/lua/nvim-tree/live-filter.lua @@ -33,7 +33,7 @@ local function remove_overlay() group = a.nvim_create_augroup("NvimTree", { clear = false }), callback = function() if utils.is_nvim_tree_buf(0) then - view.close() + a.close() end end, }) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 9df2e3abaa6..789b59f6f0f 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -186,7 +186,7 @@ local function save_tab_state() M.View.cursors[tabpage] = a.nvim_win_get_cursor(M.get_winnr()) end -function M.close() +function M.close(all_tabpages) if not M.is_visible() then return end @@ -200,8 +200,13 @@ function M.close() if tree_win == current_win and prev_win > 0 then a.nvim_set_current_win(vim.fn.win_getid(prev_win)) end - if a.nvim_win_is_valid(tree_win) then - a.nvim_win_close(tree_win, true) + a.nvim_win_close(tree_win, true) + if all_tabpages then + for _, v in pairs(M.View.tabpages) do + if v.winnr and a.nvim_win_is_valid(v.winnr) then + a.nvim_win_close(v.winnr, true) + end + end end events._dispatch_on_tree_close() return From 86e98ef649c7ce8f7c9be1fa12c46adc8ab56971 Mon Sep 17 00:00:00 2001 From: "wessel.blokzijl" Date: Fri, 28 Oct 2022 22:52:29 +0200 Subject: [PATCH 2/9] Sync closing of nvim-tree across tabs --- doc/nvim-tree-lua.txt | 3 ++- lua/nvim-tree.lua | 13 +++++++++---- lua/nvim-tree/actions/dispatch.lua | 4 +++- lua/nvim-tree/actions/node/open-file.lua | 4 ++-- lua/nvim-tree/api.lua | 2 +- lua/nvim-tree/lib.lua | 2 +- lua/nvim-tree/live-filter.lua | 2 +- lua/nvim-tree/view.lua | 12 +++++++++--- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 581c92f9c1c..a80ef696a30 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1052,8 +1052,9 @@ You can easily implement a toggle using this too: > local function toggle_replace() local view = require"nvim-tree.view" + local api = require"nvim-tree.api" if view.is_visible() then - view.close() + api.close() else require"nvim-tree".open_replacing_current_buffer() end diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 3dbea44d344..6cd9b12dbff 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -70,7 +70,7 @@ M.on_keypress = require("nvim-tree.actions.dispatch").dispatch function M.toggle(find_file, no_focus, cwd, bang) if view.is_visible() then - view.close() + M.close() else local previous_buf = vim.api.nvim_get_current_buf() M.open(cwd) @@ -83,6 +83,11 @@ function M.toggle(find_file, no_focus, cwd, bang) end end +function M.close() + local config = M.get_config() + view.close(config.open_on_tab) +end + function M.open(cwd) cwd = cwd ~= "" and cwd or nil if view.is_visible() then @@ -438,7 +443,7 @@ local function setup_autocommands(opts) pattern = "NvimTree_*", callback = function() if utils.is_nvim_tree_buf(0) then - view.close() + M.close() end end, }) @@ -763,11 +768,11 @@ function M.setup(conf) require("nvim-tree.watcher").purge_watchers() if not M.setup_called then - setup_vim_commands() + setup_vim_commands(opts) end if M.setup_called and view.is_visible() then - view.close() + M.close() view.abandon_current_window() end diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index 44eff9834b0..63e34578d9b 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -1,10 +1,12 @@ +local api = vim.api + local view = require "nvim-tree.view" local lib = require "nvim-tree.lib" local M = {} local Actions = { - close = view.close, + close = api.close, -- Tree modifiers collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn, diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index c3f725ee824..7fb1c881f2a 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -132,7 +132,7 @@ end local function open_file_in_tab(filename) if M.quit_on_open then - view.close() + api.close() end vim.cmd("tabe " .. vim.fn.fnameescape(filename)) end @@ -299,7 +299,7 @@ function M.fn(mode, filename) end if M.quit_on_open then - view.close() + api.close() end end diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 4d9798e1bec..4779460f1fb 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -17,7 +17,7 @@ end Api.tree.open = require("nvim-tree").open Api.tree.toggle = require("nvim-tree").toggle -Api.tree.close = require("nvim-tree.view").close +Api.tree.close = require("nvim-tree").close Api.tree.focus = require("nvim-tree").focus Api.tree.reload = require("nvim-tree.actions.reloaders.reloaders").reload_explorer Api.tree.change_root = require("nvim-tree").change_dir diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index bb66df44b38..101b182dfcb 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -117,7 +117,7 @@ function M.open(cwd) core.init(cwd or vim.loop.cwd()) end if should_hijack_current_buf() then - view.close() + api.close() view.open_in_current_win() renderer.draw() else diff --git a/lua/nvim-tree/live-filter.lua b/lua/nvim-tree/live-filter.lua index df28911c45a..cfc7eeba3aa 100644 --- a/lua/nvim-tree/live-filter.lua +++ b/lua/nvim-tree/live-filter.lua @@ -31,7 +31,7 @@ local function remove_overlay() group = vim.api.nvim_create_augroup("NvimTree", { clear = false }), callback = function() if utils.is_nvim_tree_buf(0) then - view.close() + a.close() end end, }) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index f8048d5ecf9..7f760577303 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -75,8 +75,7 @@ local function matches_bufnr(bufnr) end local function wipe_rogue_buffer() - for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do - if not matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do if not matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then pcall(vim.api.nvim_buf_delete, bufnr, { force = true }) end end @@ -184,7 +183,7 @@ local function save_tab_state() M.View.cursors[tabpage] = vim.api.nvim_win_get_cursor(M.get_winnr()) end -function M.close() +function M.close(all_tabpages) if not M.is_visible() then return end @@ -201,6 +200,13 @@ function M.close() if vim.api.nvim_win_is_valid(tree_win) then vim.api.nvim_win_close(tree_win, true) end + if all_tabpages then + for _, v in pairs(M.View.tabpages) do + if v.winnr and vim.api.nvim_win_is_valid(v.winnr) then + vim.api.nvim_win_close(v.winnr, true) + end + end + end events._dispatch_on_tree_close() return end From e81742f40e67b8bf55c20c4c36ca37cd555d218b Mon Sep 17 00:00:00 2001 From: "wessel.blokzijl" Date: Sun, 30 Oct 2022 10:30:20 +0100 Subject: [PATCH 3/9] Fix api.close calls --- lua/nvim-tree.lua | 2 +- lua/nvim-tree/actions/dispatch.lua | 4 +--- lua/nvim-tree/actions/node/open-file.lua | 4 ++-- lua/nvim-tree/lib.lua | 2 +- lua/nvim-tree/live-filter.lua | 2 +- lua/nvim-tree/view.lua | 3 ++- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 6cd9b12dbff..27656220464 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -768,7 +768,7 @@ function M.setup(conf) require("nvim-tree.watcher").purge_watchers() if not M.setup_called then - setup_vim_commands(opts) + setup_vim_commands() end if M.setup_called and view.is_visible() then diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index 63e34578d9b..44eff9834b0 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -1,12 +1,10 @@ -local api = vim.api - local view = require "nvim-tree.view" local lib = require "nvim-tree.lib" local M = {} local Actions = { - close = api.close, + close = view.close, -- Tree modifiers collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn, diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 7fb1c881f2a..05b5cdbeab3 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -132,7 +132,7 @@ end local function open_file_in_tab(filename) if M.quit_on_open then - api.close() + view.close(false) end vim.cmd("tabe " .. vim.fn.fnameescape(filename)) end @@ -299,7 +299,7 @@ function M.fn(mode, filename) end if M.quit_on_open then - api.close() + view.close(false) end end diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index 101b182dfcb..d642f539f23 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -117,7 +117,7 @@ function M.open(cwd) core.init(cwd or vim.loop.cwd()) end if should_hijack_current_buf() then - api.close() + view.close(false) view.open_in_current_win() renderer.draw() else diff --git a/lua/nvim-tree/live-filter.lua b/lua/nvim-tree/live-filter.lua index cfc7eeba3aa..28efa9b8512 100644 --- a/lua/nvim-tree/live-filter.lua +++ b/lua/nvim-tree/live-filter.lua @@ -31,7 +31,7 @@ local function remove_overlay() group = vim.api.nvim_create_augroup("NvimTree", { clear = false }), callback = function() if utils.is_nvim_tree_buf(0) then - a.close() + view.close(false) end end, }) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 7f760577303..03ae9bc170d 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -75,7 +75,8 @@ local function matches_bufnr(bufnr) end local function wipe_rogue_buffer() - for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do if not matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do + if not matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then pcall(vim.api.nvim_buf_delete, bufnr, { force = true }) end end From c8a98fe1e59b24f4a82ec6d4d5dd9ecc7851adbe Mon Sep 17 00:00:00 2001 From: "wessel.blokzijl" Date: Sun, 30 Oct 2022 10:38:50 +0100 Subject: [PATCH 4/9] Fix issue from merge --- lua/nvim-tree/actions/dispatch.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index 63e34578d9b..44eff9834b0 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -1,12 +1,10 @@ -local api = vim.api - local view = require "nvim-tree.view" local lib = require "nvim-tree.lib" local M = {} local Actions = { - close = api.close, + close = view.close, -- Tree modifiers collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn, From be2ccd4b1a6077b53f8bfabf1e5c1775ca6dfbdc Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 5 Nov 2022 16:34:41 +1100 Subject: [PATCH 5/9] fix(#1723): find_file for externally created new file results in folder unable to be opened * fix(#1723): find_file for externally created new file results in folder unable to be opened * fix(#1723): find_file for externally created new file results in folder unable to be opened --- lua/nvim-tree/actions/finders/find-file.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lua/nvim-tree/actions/finders/find-file.lua b/lua/nvim-tree/actions/finders/find-file.lua index df55c1551f2..87a4d0b4318 100644 --- a/lua/nvim-tree/actions/finders/find-file.lua +++ b/lua/nvim-tree/actions/finders/find-file.lua @@ -16,20 +16,23 @@ function M.fn(fname) if running[fname] or not core.get_explorer() then return end - running[fname] = true - local ps = log.profile_start("find file %s", fname) -- always match against the real path local fname_real = uv.fs_realpath(fname) if not fname_real then return end - local line = core.get_nodes_starting_line() + running[fname] = true + + local ps = log.profile_start("find file %s", fname) + + -- first line is the root node + local line = core.get_nodes_starting_line() - 1 local absolute_paths_searched = {} - local found = Iterator.builder(core.get_explorer().nodes) + local found = Iterator.builder({ core.get_explorer() }) :matcher(function(node) return node.absolute_path == fname_real or node.link_to == fname_real end) @@ -46,9 +49,7 @@ function M.fn(fname) if abs_match or link_match then node.open = true - if #node.nodes == 0 then - core.get_explorer():expand(node) - end + core.get_explorer():expand(node) end end) :recursor(function(node) From a23b11dfa35cdf0cfb031881ccb37d5e7bbb643d Mon Sep 17 00:00:00 2001 From: "wessel.blokzijl" Date: Sat, 5 Nov 2022 13:17:24 +0100 Subject: [PATCH 6/9] Implement changes --- lua/nvim-tree.lua | 16 +++++++--------- lua/nvim-tree/actions/dispatch.lua | 3 ++- lua/nvim-tree/actions/node/open-file.lua | 6 ++++-- lua/nvim-tree/api.lua | 3 ++- lua/nvim-tree/lib.lua | 3 ++- lua/nvim-tree/live-filter.lua | 3 ++- lua/nvim-tree/view.lua | 11 ++++++++++- 7 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 38bc0e790db..d9aaea42b5c 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -70,7 +70,8 @@ M.on_keypress = require("nvim-tree.actions.dispatch").dispatch function M.toggle(find_file, no_focus, cwd, bang) if view.is_visible() then - M.close() + view.close() -- TODO Choose one + -- view.close_this_tab_only() -- TODO Choose one else local previous_buf = vim.api.nvim_get_current_buf() M.open(cwd) @@ -83,11 +84,6 @@ function M.toggle(find_file, no_focus, cwd, bang) end end -function M.close() - local config = M.get_config() - view.close(config.open_on_tab) -end - function M.open(cwd) cwd = cwd ~= "" and cwd or nil if view.is_visible() then @@ -443,7 +439,8 @@ local function setup_autocommands(opts) pattern = "NvimTree_*", callback = function() if utils.is_nvim_tree_buf(0) then - M.close() + view.close() -- TODO Choose one + -- view.close_this_tab_only() -- TODO Choose one end end, }) @@ -774,11 +771,12 @@ function M.setup(conf) require("nvim-tree.watcher").purge_watchers() if not M.setup_called then - setup_vim_commands(opts) + setup_vim_commands() end if M.setup_called and view.is_visible() then - M.close() + view.close() -- TODO Choose one + -- view.close_this_tab_only() -- TODO Choose one view.abandon_current_window() end diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index 44eff9834b0..25959356eba 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -4,7 +4,8 @@ local lib = require "nvim-tree.lib" local M = {} local Actions = { - close = view.close, + -- close = view.close(), -- TODO Choose one + close = view.close_this_tab_only(), -- TODO Choose one -- Tree modifiers collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn, diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 66b4d222e5e..cd9506ea36c 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -143,7 +143,8 @@ end local function open_file_in_tab(filename) if M.quit_on_open then - view.close(false) + view.close() -- TODO Choose one + -- view.close_this_tab_only() -- TODO Choose one end vim.cmd("tabe " .. vim.fn.fnameescape(filename)) end @@ -306,7 +307,8 @@ function M.fn(mode, filename) end if M.quit_on_open then - view.close(false) + view.close() -- TODO Choose one + -- view.close_this_tab_only() -- TODO Choose one end end diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 09e99754abd..7c539b813e6 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -17,7 +17,8 @@ end Api.tree.open = require("nvim-tree").open Api.tree.toggle = require("nvim-tree").toggle -Api.tree.close = require("nvim-tree").close +Api.tree.close = require("nvim-tree.view").close +Api.tree.close_this_tab = require("nvim-tree.view").close_this_tab_only Api.tree.focus = require("nvim-tree").focus Api.tree.reload = require("nvim-tree.actions.reloaders.reloaders").reload_explorer Api.tree.change_root = require("nvim-tree").change_dir diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index d642f539f23..e1f1420cad5 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -117,7 +117,8 @@ function M.open(cwd) core.init(cwd or vim.loop.cwd()) end if should_hijack_current_buf() then - view.close(false) + -- view.close() -- TODO Choose one + view.close_this_tab_only() -- TODO Choose one view.open_in_current_win() renderer.draw() else diff --git a/lua/nvim-tree/live-filter.lua b/lua/nvim-tree/live-filter.lua index 28efa9b8512..2c1e5985d07 100644 --- a/lua/nvim-tree/live-filter.lua +++ b/lua/nvim-tree/live-filter.lua @@ -31,7 +31,8 @@ local function remove_overlay() group = vim.api.nvim_create_augroup("NvimTree", { clear = false }), callback = function() if utils.is_nvim_tree_buf(0) then - view.close(false) + view.close() -- TODO Choose one + -- view.close_this_tab_only() -- TODO Choose one end end, }) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 42e1a5cbc50..afda15fb1f0 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -184,7 +184,7 @@ local function save_tab_state() M.View.cursors[tabpage] = vim.api.nvim_win_get_cursor(M.get_winnr()) end -function M.close(all_tabpages) +local function close(all_tabpages) if not M.is_visible() then return end @@ -214,6 +214,14 @@ function M.close(all_tabpages) end end +function M.close_this_tab_only() + close(false) +end + +function M.close() + close(M.View.open_on_tab) +end + function M.open(options) if M.is_visible() then return @@ -457,6 +465,7 @@ function M.setup(opts) M.View.height = options.height M.View.initial_width = get_size() M.View.hide_root_folder = options.hide_root_folder + M.View.open_on_tab = opts.open_on_tab M.View.preserve_window_proportions = options.preserve_window_proportions M.View.winopts.number = options.number M.View.winopts.relativenumber = options.relativenumber From bdc4ec6abd3e6c78eb5dea5f8b94c2698c3aad51 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 6 Nov 2022 10:08:32 +1100 Subject: [PATCH 7/9] fix(#1716): focus file/directory when created in a sub-directory, don't dispatch FolderCreated on file creation (#1722) * fix(#1716): focus file/directory when created in a sub-directory, don't dispatch FolderCreated on file creation * fix(#1716): focus file/directory when created in a sub-directory * fix(#1716): focus file/directory when created in a sub-directory --- lua/nvim-tree/actions/fs/create-file.lua | 16 ++++------------ lua/nvim-tree/actions/reloaders/reloaders.lua | 11 +++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lua/nvim-tree/actions/fs/create-file.lua b/lua/nvim-tree/actions/fs/create-file.lua index ab3d27aaed6..cc19cce28b9 100644 --- a/lua/nvim-tree/actions/fs/create-file.lua +++ b/lua/nvim-tree/actions/fs/create-file.lua @@ -4,7 +4,6 @@ local utils = require "nvim-tree.utils" local events = require "nvim-tree.events" local lib = require "nvim-tree.lib" local core = require "nvim-tree.core" -local watch = require "nvim-tree.explorer.watch" local notify = require "nvim-tree.notify" local M = {} @@ -101,22 +100,15 @@ function M.fn(node) is_error = true break end + events._dispatch_folder_created(path_to_create) end end if not is_error then notify.info(new_file_path .. " was properly created") end - events._dispatch_folder_created(new_file_path) - if M.enable_reload then - require("nvim-tree.actions.reloaders.reloaders").reload_explorer() - else - -- synchronous call required so that we may focus the file now - node = node.nodes ~= nil and node or node.parent - if node then - watch.refresh_path(node.absolute_path) - end - end - utils.focus_file(utils.path_remove_trailing(new_file_path)) + + -- implicitly refreshes contents + require("nvim-tree.actions.finders.find-file").fn(new_file_path) end) end diff --git a/lua/nvim-tree/actions/reloaders/reloaders.lua b/lua/nvim-tree/actions/reloaders/reloaders.lua index c2b403a6954..8aac6f62246 100644 --- a/lua/nvim-tree/actions/reloaders/reloaders.lua +++ b/lua/nvim-tree/actions/reloaders/reloaders.lua @@ -3,6 +3,7 @@ local view = require "nvim-tree.view" local renderer = require "nvim-tree.renderer" local explorer_module = require "nvim-tree.explorer" local core = require "nvim-tree.core" +local log = require "nvim-tree.log" local M = {} @@ -39,11 +40,16 @@ function M.reload_explorer() end event_running = true + local ps = log.profile_start "reload_explorer" + local projects = git.reload() refresh_nodes(core.get_explorer(), projects) if view.is_visible() then renderer.draw() end + + log.profile_end(ps, "reload_explorer") + event_running = false end @@ -53,9 +59,14 @@ function M.reload_git() end event_running = true + local ps = log.profile_start "reload_git" + local projects = git.reload() M.reload_node_status(core.get_explorer(), projects) renderer.draw() + + log.profile_end(ps, "reload_git") + event_running = false end From 6d6a44626d4dec58bb61bd40d5bd63d69818c540 Mon Sep 17 00:00:00 2001 From: Tomohiro Endo Date: Sun, 6 Nov 2022 08:30:12 +0900 Subject: [PATCH 8/9] fix(watcher): failure on watcher teardown message (#1726) --- lua/nvim-tree/watcher.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree/watcher.lua b/lua/nvim-tree/watcher.lua index 54bb9bd7de9..5a2b1709733 100644 --- a/lua/nvim-tree/watcher.lua +++ b/lua/nvim-tree/watcher.lua @@ -89,7 +89,7 @@ function Event:destroy(message) if self._fs_event then if message then - utils.notify.warn(message) + notify.warn(message) end local rc, _, name = self._fs_event:stop() From 8cc369695b3a0ae3ddf9538bc1f87bbf8cdbecca Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 6 Nov 2022 10:37:33 +1100 Subject: [PATCH 9/9] fix: replace vim.* "requires" with explicit calls to vim functions (#1701) --- lua/nvim-tree.lua | 85 +++++++++--------- lua/nvim-tree/actions/finders/find-file.lua | 3 +- lua/nvim-tree/actions/finders/search-node.lua | 23 +++-- lua/nvim-tree/actions/fs/copy-paste.lua | 18 ++-- lua/nvim-tree/actions/fs/create-file.lua | 8 +- lua/nvim-tree/actions/fs/remove-file.lua | 27 +++--- lua/nvim-tree/actions/fs/rename-file.lua | 4 +- lua/nvim-tree/actions/fs/trash.lua | 8 +- lua/nvim-tree/actions/init.lua | 4 +- lua/nvim-tree/actions/node/file-popup.lua | 15 ++-- lua/nvim-tree/actions/node/open-file.lua | 60 ++++++------- lua/nvim-tree/actions/node/system-open.lua | 10 +-- lua/nvim-tree/actions/root/change-dir.lua | 6 +- lua/nvim-tree/colors.lua | 6 +- lua/nvim-tree/diagnostics.lua | 7 +- lua/nvim-tree/explorer/common.lua | 4 +- lua/nvim-tree/explorer/explore.lua | 10 +-- lua/nvim-tree/explorer/init.lua | 4 +- lua/nvim-tree/explorer/node-builders.lua | 21 +++-- lua/nvim-tree/explorer/reload.lua | 10 +-- lua/nvim-tree/git/init.lua | 4 +- lua/nvim-tree/git/runner.lua | 15 ++-- lua/nvim-tree/lib.lua | 14 ++- lua/nvim-tree/live-filter.lua | 32 ++++--- lua/nvim-tree/log.lua | 6 +- .../renderer/components/full-name.lua | 40 ++++----- lua/nvim-tree/renderer/init.lua | 22 +++-- lua/nvim-tree/utils.lua | 27 +++--- lua/nvim-tree/view.lua | 88 +++++++++---------- lua/nvim-tree/watcher.lua | 3 +- 30 files changed, 263 insertions(+), 321 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 664389ae585..46ddcbd5a2d 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -1,6 +1,3 @@ -local luv = vim.loop -local api = vim.api - local lib = require "nvim-tree.lib" local log = require "nvim-tree.log" local colors = require "nvim-tree.colors" @@ -29,7 +26,7 @@ end function M.change_root(filepath, bufnr) -- skip if current file is in ignore_list - local ft = api.nvim_buf_get_option(bufnr, "filetype") or "" + local ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or "" for _, value in pairs(_config.update_focused_file.ignore_list) do if utils.str_find(filepath, value) or utils.str_find(ft, value) then return @@ -75,7 +72,7 @@ function M.toggle(find_file, no_focus, cwd, bang) if view.is_visible() then view.close() else - local previous_buf = api.nvim_get_current_buf() + local previous_buf = vim.api.nvim_get_current_buf() M.open(cwd) if _config.update_focused_file.enable or find_file then M.find_file(false, previous_buf, bang) @@ -101,8 +98,8 @@ function M.open_replacing_current_buffer(cwd) return end - local buf = api.nvim_get_current_buf() - local bufname = api.nvim_buf_get_name(buf) + local buf = vim.api.nvim_get_current_buf() + local bufname = vim.api.nvim_buf_get_name(buf) if bufname == "" or vim.loop.fs_stat(bufname) == nil then return end @@ -121,8 +118,8 @@ end function M.tab_change() if view.is_visible { any_tabpage = true } then - local bufname = api.nvim_buf_get_name(0) - local ft = api.nvim_buf_get_option(0, "ft") + local bufname = vim.api.nvim_buf_get_name(0) + local ft = vim.api.nvim_buf_get_option(0, "ft") for _, filter in ipairs(M.config.ignore_buf_on_tab_change) do if bufname:match(filter) ~= nil or ft:match(filter) ~= nil then return @@ -135,14 +132,14 @@ end local function find_existing_windows() return vim.tbl_filter(function(win) - local buf = api.nvim_win_get_buf(win) - return api.nvim_buf_get_name(buf):match "NvimTree" ~= nil - end, api.nvim_list_wins()) + local buf = vim.api.nvim_win_get_buf(win) + return vim.api.nvim_buf_get_name(buf):match "NvimTree" ~= nil + end, vim.api.nvim_list_wins()) end local function is_file_readable(fname) - local stat = luv.fs_stat(fname) - return stat and stat.type == "file" and luv.fs_access(fname, "R") + local stat = vim.loop.fs_stat(fname) + return stat and stat.type == "file" and vim.loop.fs_access(fname, "R") end function M.find_file(with_open, bufnr, bang) @@ -150,11 +147,11 @@ function M.find_file(with_open, bufnr, bang) return end - bufnr = bufnr or api.nvim_get_current_buf() - if not api.nvim_buf_is_valid(bufnr) then + bufnr = bufnr or vim.api.nvim_get_current_buf() + if not vim.api.nvim_buf_is_valid(bufnr) then return end - local bufname = api.nvim_buf_get_name(bufnr) + local bufname = vim.api.nvim_buf_get_name(bufnr) local filepath = utils.canonical_path(vim.fn.fnamemodify(bufname, ":p")) if not is_file_readable(filepath) then return @@ -181,8 +178,8 @@ function M.open_on_directory() return end - local buf = api.nvim_get_current_buf() - local bufname = api.nvim_buf_get_name(buf) + local buf = vim.api.nvim_get_current_buf() + local bufname = vim.api.nvim_buf_get_name(buf) if vim.fn.isdirectory(bufname) ~= 1 then return end @@ -198,7 +195,7 @@ end local prev_line function M.place_cursor_on_node() - local l = api.nvim_win_get_cursor(0)[1] + local l = vim.api.nvim_win_get_cursor(0)[1] if l == prev_line then return end @@ -209,22 +206,22 @@ function M.place_cursor_on_node() return end - local line = api.nvim_get_current_line() - local cursor = api.nvim_win_get_cursor(0) + local line = vim.api.nvim_get_current_line() + local cursor = vim.api.nvim_win_get_cursor(0) local idx = vim.fn.stridx(line, node.name) if idx >= 0 then - api.nvim_win_set_cursor(0, { cursor[1], idx }) + vim.api.nvim_win_set_cursor(0, { cursor[1], idx }) end end function M.on_enter(netrw_disabled) - local bufnr = api.nvim_get_current_buf() - local bufname = api.nvim_buf_get_name(bufnr) - local buftype = api.nvim_buf_get_option(bufnr, "filetype") + local bufnr = vim.api.nvim_get_current_buf() + local bufname = vim.api.nvim_buf_get_name(bufnr) + local buftype = vim.api.nvim_buf_get_option(bufnr, "filetype") local ft_ignore = _config.ignore_ft_on_setup - local stats = luv.fs_stat(bufname) + local stats = vim.loop.fs_stat(bufname) local is_dir = stats and stats.type == "directory" local is_file = stats and stats.type == "file" local cwd @@ -234,7 +231,7 @@ function M.on_enter(netrw_disabled) vim.cmd("noautocmd cd " .. cwd) end - local lines = not is_dir and api.nvim_buf_get_lines(bufnr, 0, -1, false) or {} + local lines = not is_dir and vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) or {} local buf_has_content = #lines > 1 or (#lines == 1 and lines[1] ~= "") local buf_is_dir = is_dir and netrw_disabled @@ -265,7 +262,7 @@ function M.on_enter(netrw_disabled) -- Session that left a NvimTree Buffer opened, reopen with it local existing_tree_wins = find_existing_windows() if existing_tree_wins[1] then - api.nvim_set_current_win(existing_tree_wins[1]) + vim.api.nvim_set_current_win(existing_tree_wins[1]) end if should_open or should_hijack or existing_tree_wins[1] ~= nil then @@ -297,27 +294,27 @@ local function manage_netrw(disable_netrw, hijack_netrw) end local function setup_vim_commands() - api.nvim_create_user_command("NvimTreeOpen", function(res) + vim.api.nvim_create_user_command("NvimTreeOpen", function(res) M.open(res.args) end, { nargs = "?", complete = "dir" }) - api.nvim_create_user_command("NvimTreeClose", view.close, { bar = true }) - api.nvim_create_user_command("NvimTreeToggle", function(res) + vim.api.nvim_create_user_command("NvimTreeClose", view.close, { bar = true }) + vim.api.nvim_create_user_command("NvimTreeToggle", function(res) M.toggle(false, false, res.args) end, { nargs = "?", complete = "dir" }) - api.nvim_create_user_command("NvimTreeFocus", M.focus, { bar = true }) - api.nvim_create_user_command("NvimTreeRefresh", reloaders.reload_explorer, { bar = true }) - api.nvim_create_user_command("NvimTreeClipboard", copy_paste.print_clipboard, { bar = true }) - api.nvim_create_user_command("NvimTreeFindFile", function(res) + vim.api.nvim_create_user_command("NvimTreeFocus", M.focus, { bar = true }) + vim.api.nvim_create_user_command("NvimTreeRefresh", reloaders.reload_explorer, { bar = true }) + vim.api.nvim_create_user_command("NvimTreeClipboard", copy_paste.print_clipboard, { bar = true }) + vim.api.nvim_create_user_command("NvimTreeFindFile", function(res) M.find_file(true, nil, res.bang) end, { bang = true, bar = true }) - api.nvim_create_user_command("NvimTreeFindFileToggle", function(res) + vim.api.nvim_create_user_command("NvimTreeFindFileToggle", function(res) M.toggle(true, false, res.args, res.bang) end, { bang = true, nargs = "?", complete = "dir" }) - api.nvim_create_user_command("NvimTreeResize", function(res) + vim.api.nvim_create_user_command("NvimTreeResize", function(res) M.resize(res.args) end, { nargs = 1, bar = true }) - api.nvim_create_user_command("NvimTreeCollapse", collapse_all.fn, { bar = true }) - api.nvim_create_user_command("NvimTreeCollapseKeepBuffers", function() + vim.api.nvim_create_user_command("NvimTreeCollapse", collapse_all.fn, { bar = true }) + vim.api.nvim_create_user_command("NvimTreeCollapseKeepBuffers", function() collapse_all.fn(true) end, { bar = true }) end @@ -331,10 +328,10 @@ function M.change_dir(name) end local function setup_autocommands(opts) - local augroup_id = api.nvim_create_augroup("NvimTree", { clear = true }) + local augroup_id = vim.api.nvim_create_augroup("NvimTree", { clear = true }) local function create_nvim_tree_autocmd(name, custom_opts) local default_opts = { group = augroup_id } - api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts)) + vim.api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts)) end -- reset highlights when colorscheme is changed @@ -410,9 +407,9 @@ local function setup_autocommands(opts) create_nvim_tree_autocmd("BufEnter", { pattern = "NvimTree_*", callback = function() - local bufnr = api.nvim_get_current_buf() + local bufnr = vim.api.nvim_get_current_buf() vim.schedule(function() - api.nvim_buf_call(bufnr, function() + vim.api.nvim_buf_call(bufnr, function() vim.cmd [[norm! zz]] end) end) diff --git a/lua/nvim-tree/actions/finders/find-file.lua b/lua/nvim-tree/actions/finders/find-file.lua index 87a4d0b4318..58dbb9b217d 100644 --- a/lua/nvim-tree/actions/finders/find-file.lua +++ b/lua/nvim-tree/actions/finders/find-file.lua @@ -1,5 +1,4 @@ local log = require "nvim-tree.log" -local uv = vim.loop local view = require "nvim-tree.view" local utils = require "nvim-tree.utils" local renderer = require "nvim-tree.renderer" @@ -18,7 +17,7 @@ function M.fn(fname) end -- always match against the real path - local fname_real = uv.fs_realpath(fname) + local fname_real = vim.loop.fs_realpath(fname) if not fname_real then return end diff --git a/lua/nvim-tree/actions/finders/search-node.lua b/lua/nvim-tree/actions/finders/search-node.lua index d0b0162cddf..66fb5a3cfa5 100644 --- a/lua/nvim-tree/actions/finders/search-node.lua +++ b/lua/nvim-tree/actions/finders/search-node.lua @@ -1,6 +1,3 @@ -local api = vim.api -local uv = vim.loop - local core = require "nvim-tree.core" local filters = require "nvim-tree.explorer.filters" local find_file = require("nvim-tree.actions.finders.find-file").fn @@ -17,22 +14,22 @@ local function search(search_dir, input_path) local function iter(dir) local realpath, path, name, stat, handle, _ - handle, _ = uv.fs_scandir(dir) + handle, _ = vim.loop.fs_scandir(dir) if not handle then return end - realpath, _ = uv.fs_realpath(dir) + realpath, _ = vim.loop.fs_realpath(dir) if not realpath or vim.tbl_contains(realpaths_searched, realpath) then return end table.insert(realpaths_searched, realpath) - name, _ = uv.fs_scandir_next(handle) + name, _ = vim.loop.fs_scandir_next(handle) while name do path = dir .. "/" .. name - stat, _ = uv.fs_stat(path) + stat, _ = vim.loop.fs_stat(path) if not stat then break end @@ -50,7 +47,7 @@ local function search(search_dir, input_path) end end - name, _ = uv.fs_scandir_next(handle) + name, _ = vim.loop.fs_scandir_next(handle) end end @@ -63,9 +60,9 @@ function M.fn() end -- temporarily set &path - local bufnr = api.nvim_get_current_buf() - local path_existed, path_opt = pcall(api.nvim_buf_get_option, bufnr, "path") - api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**") + local bufnr = vim.api.nvim_get_current_buf() + local path_existed, path_opt = pcall(vim.api.nvim_buf_get_option, bufnr, "path") + vim.api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**") vim.ui.input({ prompt = "Search: ", completion = "file_in_path" }, function(input_path) if not input_path or input_path == "" then @@ -73,9 +70,9 @@ function M.fn() end -- reset &path if path_existed then - api.nvim_buf_set_option(bufnr, "path", path_opt) + vim.api.nvim_buf_set_option(bufnr, "path", path_opt) else - api.nvim_buf_set_option(bufnr, "path", nil) + vim.api.nvim_buf_set_option(bufnr, "path", nil) end -- strip trailing slash diff --git a/lua/nvim-tree/actions/fs/copy-paste.lua b/lua/nvim-tree/actions/fs/copy-paste.lua index 16ede80ae66..3fccf11deec 100644 --- a/lua/nvim-tree/actions/fs/copy-paste.lua +++ b/lua/nvim-tree/actions/fs/copy-paste.lua @@ -1,5 +1,3 @@ -local uv = vim.loop - local lib = require "nvim-tree.lib" local log = require "nvim-tree.log" local utils = require "nvim-tree.utils" @@ -17,7 +15,7 @@ local function do_copy(source, destination) local source_stats, handle local success, errmsg - source_stats, errmsg = uv.fs_stat(source) + source_stats, errmsg = vim.loop.fs_stat(source) if not source_stats then log.line("copy_paste", "do_copy fs_stat '%s' failed '%s'", source, errmsg) return false, errmsg @@ -31,14 +29,14 @@ local function do_copy(source, destination) end if source_stats.type == "file" then - success, errmsg = uv.fs_copyfile(source, destination) + success, errmsg = vim.loop.fs_copyfile(source, destination) if not success then log.line("copy_paste", "do_copy fs_copyfile failed '%s'", errmsg) return false, errmsg end return true elseif source_stats.type == "directory" then - handle, errmsg = uv.fs_scandir(source) + handle, errmsg = vim.loop.fs_scandir(source) if type(handle) == "string" then return false, handle elseif not handle then @@ -46,14 +44,14 @@ local function do_copy(source, destination) return false, errmsg end - success, errmsg = uv.fs_mkdir(destination, source_stats.mode) + success, errmsg = vim.loop.fs_mkdir(destination, source_stats.mode) if not success then log.line("copy_paste", "do_copy fs_mkdir '%s' failed '%s'", destination, errmsg) return false, errmsg end while true do - local name, _ = uv.fs_scandir_next(handle) + local name, _ = vim.loop.fs_scandir_next(handle) if not name then break end @@ -80,7 +78,7 @@ local function do_single_paste(source, dest, action_type, action_fn) log.line("copy_paste", "do_single_paste '%s' -> '%s'", source, dest) - dest_stats, errmsg, errcode = uv.fs_stat(dest) + dest_stats, errmsg, errcode = vim.loop.fs_stat(dest) if not dest_stats and errcode ~= "ENOENT" then notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???")) return false, errmsg @@ -155,7 +153,7 @@ local function do_paste(node, action_type, action_fn) end local destination = node.absolute_path - local stats, errmsg, errcode = uv.fs_stat(destination) + local stats, errmsg, errcode = vim.loop.fs_stat(destination) if not stats and errcode ~= "ENOENT" then log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, errmsg) notify.error("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???")) @@ -188,7 +186,7 @@ local function do_cut(source, destination) return true end - local success, errmsg = uv.fs_rename(source, destination) + local success, errmsg = vim.loop.fs_rename(source, destination) if not success then log.line("copy_paste", "do_cut fs_rename failed '%s'", errmsg) return false, errmsg diff --git a/lua/nvim-tree/actions/fs/create-file.lua b/lua/nvim-tree/actions/fs/create-file.lua index cc19cce28b9..80bf1e15406 100644 --- a/lua/nvim-tree/actions/fs/create-file.lua +++ b/lua/nvim-tree/actions/fs/create-file.lua @@ -1,5 +1,3 @@ -local uv = vim.loop - local utils = require "nvim-tree.utils" local events = require "nvim-tree.events" local lib = require "nvim-tree.lib" @@ -9,12 +7,12 @@ local notify = require "nvim-tree.notify" local M = {} local function create_and_notify(file) - local ok, fd = pcall(uv.fs_open, file, "w", 420) + local ok, fd = pcall(vim.loop.fs_open, file, "w", 420) if not ok then notify.error("Couldn't create file " .. file) return end - uv.fs_close(fd) + vim.loop.fs_close(fd) events._dispatch_file_created(file) end @@ -94,7 +92,7 @@ function M.fn(node) if is_last_path_file and idx == num_nodes then create_file(path_to_create) elseif not utils.file_exists(path_to_create) then - local success = uv.fs_mkdir(path_to_create, 493) + local success = vim.loop.fs_mkdir(path_to_create, 493) if not success then notify.error("Could not create folder " .. path_to_create) is_error = true diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index 049f906ea58..ff2d4630041 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -1,6 +1,3 @@ -local a = vim.api -local luv = vim.loop - local utils = require "nvim-tree.utils" local events = require "nvim-tree.events" local view = require "nvim-tree.view" @@ -10,13 +7,13 @@ local notify = require "nvim-tree.notify" local M = {} local function close_windows(windows) - if view.View.float.enable and #a.nvim_list_wins() == 1 then + if view.View.float.enable and #vim.api.nvim_list_wins() == 1 then return end for _, window in ipairs(windows) do - if a.nvim_win_is_valid(window) then - a.nvim_win_close(window, true) + if vim.api.nvim_win_is_valid(window) then + vim.api.nvim_win_close(window, true) end end end @@ -26,14 +23,14 @@ local function clear_buffer(absolute_path) for _, buf in pairs(bufs) do if buf.name == absolute_path then if buf.hidden == 0 and (#bufs > 1 or view.View.float.enable) then - local winnr = a.nvim_get_current_win() - a.nvim_set_current_win(buf.windows[1]) + local winnr = vim.api.nvim_get_current_win() + vim.api.nvim_set_current_win(buf.windows[1]) vim.cmd ":bn" if not view.View.float.enable then - a.nvim_set_current_win(winnr) + vim.api.nvim_set_current_win(winnr) end end - a.nvim_buf_delete(buf.bufnr, { force = true }) + vim.api.nvim_buf_delete(buf.bufnr, { force = true }) if M.close_window then close_windows(buf.windows) end @@ -43,13 +40,13 @@ local function clear_buffer(absolute_path) end local function remove_dir(cwd) - local handle = luv.fs_scandir(cwd) + local handle = vim.loop.fs_scandir(cwd) if type(handle) == "string" then return notify.error(handle) end while true do - local name, t = luv.fs_scandir_next(handle) + local name, t = vim.loop.fs_scandir_next(handle) if not name then break end @@ -61,7 +58,7 @@ local function remove_dir(cwd) return false end else - local success = luv.fs_unlink(new_cwd) + local success = vim.loop.fs_unlink(new_cwd) if not success then return false end @@ -69,7 +66,7 @@ local function remove_dir(cwd) end end - return luv.fs_rmdir(cwd) + return vim.loop.fs_rmdir(cwd) end function M.fn(node) @@ -88,7 +85,7 @@ function M.fn(node) end events._dispatch_folder_removed(node.absolute_path) else - local success = luv.fs_unlink(node.absolute_path) + local success = vim.loop.fs_unlink(node.absolute_path) if not success then return notify.error("Could not remove " .. node.name) end diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 6ed024fd609..3ef08b0d268 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -1,5 +1,3 @@ -local uv = vim.loop - local lib = require "nvim-tree.lib" local utils = require "nvim-tree.utils" local events = require "nvim-tree.events" @@ -17,7 +15,7 @@ function M.rename(node, to) return end - local success, err = uv.fs_rename(node.absolute_path, to) + local success, err = vim.loop.fs_rename(node.absolute_path, to) if not success then return notify.warn(err_fmt(node.absolute_path, to, err)) end diff --git a/lua/nvim-tree/actions/fs/trash.lua b/lua/nvim-tree/actions/fs/trash.lua index fea8dad23a0..dc8c624d767 100644 --- a/lua/nvim-tree/actions/fs/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -1,5 +1,3 @@ -local a = vim.api - local lib = require "nvim-tree.lib" local notify = require "nvim-tree.notify" @@ -19,10 +17,10 @@ local function clear_buffer(absolute_path) for _, buf in pairs(bufs) do if buf.name == absolute_path then if buf.hidden == 0 and #bufs > 1 then - local winnr = a.nvim_get_current_win() - a.nvim_set_current_win(buf.windows[1]) + local winnr = vim.api.nvim_get_current_win() + vim.api.nvim_set_current_win(buf.windows[1]) vim.cmd ":bn" - a.nvim_set_current_win(winnr) + vim.api.nvim_set_current_win(winnr) end vim.api.nvim_buf_delete(buf.bufnr, {}) return diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index 96b0c66cae9..f42875f92ed 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -1,7 +1,5 @@ -- @deprecated: new implementation in nvim-tree.keymap. Please do not edit this file. -local a = vim.api - local log = require "nvim-tree.log" local view = require "nvim-tree.view" local notify = require "nvim-tree.notify" @@ -350,7 +348,7 @@ end local function cleanup_existing_mappings() local bufnr = view.get_bufnr() - if bufnr == nil or not a.nvim_buf_is_valid(bufnr) then + if bufnr == nil or not vim.api.nvim_buf_is_valid(bufnr) then return end diff --git a/lua/nvim-tree/actions/node/file-popup.lua b/lua/nvim-tree/actions/node/file-popup.lua index 1724127ef79..3bcc80128e0 100644 --- a/lua/nvim-tree/actions/node/file-popup.lua +++ b/lua/nvim-tree/actions/node/file-popup.lua @@ -1,5 +1,4 @@ local utils = require "nvim-tree.utils" -local a = vim.api local M = {} @@ -34,19 +33,19 @@ local function setup_window(node) noautocmd = true, zindex = 60, }) - local winnr = a.nvim_open_win(0, false, open_win_config) + local winnr = vim.api.nvim_open_win(0, false, open_win_config) current_popup = { winnr = winnr, file_path = node.absolute_path, } - local bufnr = a.nvim_create_buf(false, true) - a.nvim_buf_set_lines(bufnr, 0, -1, false, lines) - a.nvim_win_set_buf(winnr, bufnr) + local bufnr = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) + vim.api.nvim_win_set_buf(winnr, bufnr) end function M.close_popup() if current_popup ~= nil then - a.nvim_win_close(current_popup.winnr, { force = true }) + vim.api.nvim_win_close(current_popup.winnr, { force = true }) vim.cmd "augroup NvimTreeRemoveFilePopup | au! CursorMoved | augroup END" current_popup = nil @@ -69,8 +68,8 @@ function M.toggle_file_info(node) setup_window(node) - a.nvim_create_autocmd("CursorMoved", { - group = a.nvim_create_augroup("NvimTreeRemoveFilePopup", {}), + vim.api.nvim_create_autocmd("CursorMoved", { + group = vim.api.nvim_create_augroup("NvimTreeRemoveFilePopup", {}), callback = M.close_popup, }) end diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index a3a855dda37..1a88f62e29c 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -1,6 +1,4 @@ -- Copyright 2019 Yazdani Kiyan under MIT License -local api = vim.api - local lib = require "nvim-tree.lib" local utils = require "nvim-tree.utils" local view = require "nvim-tree.view" @@ -18,20 +16,20 @@ end ---Get all windows in the current tabpage that aren't NvimTree. ---@return table with valid win_ids local function usable_win_ids() - local tabpage = api.nvim_get_current_tabpage() - local win_ids = api.nvim_tabpage_list_wins(tabpage) + local tabpage = vim.api.nvim_get_current_tabpage() + local win_ids = vim.api.nvim_tabpage_list_wins(tabpage) local tree_winid = view.get_winnr(tabpage) return vim.tbl_filter(function(id) - local bufid = api.nvim_win_get_buf(id) + local bufid = vim.api.nvim_win_get_buf(id) for option, v in pairs(M.window_picker.exclude) do - local ok, option_value = pcall(api.nvim_buf_get_option, bufid, option) + local ok, option_value = pcall(vim.api.nvim_buf_get_option, bufid, option) if ok and vim.tbl_contains(v, option_value) then return false end end - local win_config = api.nvim_win_get_config(id) + local win_config = vim.api.nvim_win_get_config(id) return id ~= tree_winid and win_config.focusable and not win_config.external end, win_ids) end @@ -68,8 +66,8 @@ local function pick_win_id() local laststatus = vim.o.laststatus vim.o.laststatus = 2 - local tabpage = api.nvim_get_current_tabpage() - local win_ids = api.nvim_tabpage_list_wins(tabpage) + local tabpage = vim.api.nvim_get_current_tabpage() + local win_ids = vim.api.nvim_tabpage_list_wins(tabpage) local not_selectable = vim.tbl_filter(function(id) return not vim.tbl_contains(selectable, id) @@ -77,8 +75,8 @@ local function pick_win_id() if laststatus == 3 then for _, win_id in ipairs(not_selectable) do - local ok_status, statusline = pcall(api.nvim_win_get_option, win_id, "statusline") - local ok_hl, winhl = pcall(api.nvim_win_get_option, win_id, "winhl") + local ok_status, statusline = pcall(vim.api.nvim_win_get_option, win_id, "statusline") + local ok_hl, winhl = pcall(vim.api.nvim_win_get_option, win_id, "winhl") win_opts[win_id] = { statusline = ok_status and statusline or "", @@ -86,15 +84,15 @@ local function pick_win_id() } -- Clear statusline for windows not selectable - api.nvim_win_set_option(win_id, "statusline", " ") + vim.api.nvim_win_set_option(win_id, "statusline", " ") end end -- Setup UI for _, id in ipairs(selectable) do local char = M.window_picker.chars:sub(i, i) - local ok_status, statusline = pcall(api.nvim_win_get_option, id, "statusline") - local ok_hl, winhl = pcall(api.nvim_win_get_option, id, "winhl") + local ok_status, statusline = pcall(vim.api.nvim_win_get_option, id, "statusline") + local ok_hl, winhl = pcall(vim.api.nvim_win_get_option, id, "winhl") win_opts[id] = { statusline = ok_status and statusline or "", @@ -102,8 +100,8 @@ local function pick_win_id() } win_map[char] = id - api.nvim_win_set_option(id, "statusline", "%=" .. char .. "%=") - api.nvim_win_set_option(id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker") + vim.api.nvim_win_set_option(id, "statusline", "%=" .. char .. "%=") + vim.api.nvim_win_set_option(id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker") i = i + 1 if i > #M.window_picker.chars then @@ -122,14 +120,14 @@ local function pick_win_id() -- Restore window options for _, id in ipairs(selectable) do for opt, value in pairs(win_opts[id]) do - api.nvim_win_set_option(id, opt, value) + vim.api.nvim_win_set_option(id, opt, value) end end if laststatus == 3 then for _, id in ipairs(not_selectable) do for opt, value in pairs(win_opts[id]) do - api.nvim_win_set_option(id, opt, value) + vim.api.nvim_win_set_option(id, opt, value) end end end @@ -154,9 +152,9 @@ local function on_preview(buf_loaded) if not buf_loaded then vim.bo.bufhidden = "delete" - api.nvim_create_autocmd({ "TextChanged", "TextChangedI" }, { - group = api.nvim_create_augroup("RemoveBufHidden", {}), - buffer = api.nvim_get_current_buf(), + vim.api.nvim_create_autocmd({ "TextChanged", "TextChangedI" }, { + group = vim.api.nvim_create_augroup("RemoveBufHidden", {}), + buffer = vim.api.nvim_get_current_buf(), callback = function() vim.bo.bufhidden = "" end, @@ -195,7 +193,7 @@ end local function set_current_win_no_autocmd(winid, autocmd) local eventignore = vim.opt.eventignore:get() vim.opt.eventignore:append(autocmd) - api.nvim_set_current_win(winid) + vim.api.nvim_set_current_win(winid) vim.opt.eventignore = eventignore end @@ -209,13 +207,13 @@ local function open_in_new_window(filename, mode, win_ids) return end - local create_new_window = #api.nvim_list_wins() == 1 + local create_new_window = #vim.api.nvim_list_wins() == 1 local new_window_side = (view.View.side == "right") and "aboveleft" or "belowright" -- Target is invalid or window does not exist in current tabpage: create new window if not vim.tbl_contains(win_ids, target_winid) then vim.cmd(new_window_side .. " vsplit") - target_winid = api.nvim_get_current_win() + target_winid = vim.api.nvim_get_current_win() lib.target_winid = target_winid -- No need to split, as we created a new window. @@ -226,8 +224,8 @@ local function open_in_new_window(filename, mode, win_ids) elseif not vim.o.hidden then -- If `hidden` is not enabled, check if buffer in target window is -- modified, and create new split if it is. - local target_bufid = api.nvim_win_get_buf(target_winid) - if api.nvim_buf_get_option(target_bufid, "modified") then + local target_bufid = vim.api.nvim_win_get_buf(target_winid) + if vim.api.nvim_buf_get_option(target_bufid, "modified") then mode = "vsplit" end end @@ -257,8 +255,8 @@ local function open_in_new_window(filename, mode, win_ids) end local function is_already_loaded(filename) - for _, buf_id in ipairs(api.nvim_list_bufs()) do - if api.nvim_buf_is_loaded(buf_id) and filename == api.nvim_buf_get_name(buf_id) then + for _, buf_id in ipairs(vim.api.nvim_list_bufs()) do + if vim.api.nvim_buf_is_loaded(buf_id) and filename == vim.api.nvim_buf_get_name(buf_id) then return true end end @@ -283,8 +281,8 @@ function M.fn(mode, filename) return edit_in_current_buf(filename) end - local tabpage = api.nvim_get_current_tabpage() - local win_ids = api.nvim_tabpage_list_wins(tabpage) + local tabpage = vim.api.nvim_get_current_tabpage() + local win_ids = vim.api.nvim_tabpage_list_wins(tabpage) local buf_loaded = is_already_loaded(filename) local found_win = utils.get_win_buf_from_path(filename) @@ -295,7 +293,7 @@ function M.fn(mode, filename) if not found_win then open_in_new_window(filename, mode, win_ids) else - api.nvim_set_current_win(found_win) + vim.api.nvim_set_current_win(found_win) vim.bo.bufhidden = "" end diff --git a/lua/nvim-tree/actions/node/system-open.lua b/lua/nvim-tree/actions/node/system-open.lua index ba72b50262f..861d09084b9 100644 --- a/lua/nvim-tree/actions/node/system-open.lua +++ b/lua/nvim-tree/actions/node/system-open.lua @@ -1,5 +1,3 @@ -local uv = vim.loop - local M = { config = { is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1, @@ -18,10 +16,10 @@ function M.fn(node) cmd = M.config.system_open.cmd, args = M.config.system_open.args, errors = "\n", - stderr = uv.new_pipe(false), + stderr = vim.loop.new_pipe(false), } table.insert(process.args, node.link_to or node.absolute_path) - process.handle, process.pid = uv.spawn( + process.handle, process.pid = vim.loop.spawn( process.cmd, { args = process.args, stdio = { nil, nil, process.stderr }, detached = true }, function(code) @@ -39,7 +37,7 @@ function M.fn(node) error("\n" .. process.pid .. "\nNvimTree system_open: failed to spawn process using '" .. process.cmd .. "'.") return end - uv.read_start(process.stderr, function(err, data) + vim.loop.read_start(process.stderr, function(err, data) if err then return end @@ -47,7 +45,7 @@ function M.fn(node) process.errors = process.errors .. data end end) - uv.unref(process.handle) + vim.loop.unref(process.handle) end function M.setup(opts) diff --git a/lua/nvim-tree/actions/root/change-dir.lua b/lua/nvim-tree/actions/root/change-dir.lua index e638e38fcd7..752c6328f89 100644 --- a/lua/nvim-tree/actions/root/change-dir.lua +++ b/lua/nvim-tree/actions/root/change-dir.lua @@ -1,11 +1,9 @@ -local a = vim.api - local log = require "nvim-tree.log" local utils = require "nvim-tree.utils" local core = require "nvim-tree.core" local M = { - current_tab = a.nvim_get_current_tabpage(), + current_tab = vim.api.nvim_get_current_tabpage(), } local function clean_input_cwd(name) @@ -33,7 +31,7 @@ function M.fn(input_cwd, with_open) return end - local new_tabpage = a.nvim_get_current_tabpage() + local new_tabpage = vim.api.nvim_get_current_tabpage() if is_window_event(new_tabpage) then return end diff --git a/lua/nvim-tree/colors.lua b/lua/nvim-tree/colors.lua index 61dbc62a718..6e6a98d1807 100644 --- a/lua/nvim-tree/colors.lua +++ b/lua/nvim-tree/colors.lua @@ -1,5 +1,3 @@ -local api = vim.api - local M = {} local function get_color_from_hl(hl_name, fallback) @@ -93,12 +91,12 @@ function M.setup() local gui = d.gui and " gui=" .. d.gui or "" local fg = d.fg and " guifg=" .. d.fg or "" local bg = d.bg and " guibg=" .. d.bg or "" - api.nvim_command("hi def NvimTree" .. k .. gui .. fg .. bg) + vim.api.nvim_command("hi def NvimTree" .. k .. gui .. fg .. bg) end local links = get_links() for k, d in pairs(links) do - api.nvim_command("hi def link NvimTree" .. k .. " " .. d) + vim.api.nvim_command("hi def link NvimTree" .. k .. " " .. d) end end diff --git a/lua/nvim-tree/diagnostics.lua b/lua/nvim-tree/diagnostics.lua index fb16d3ca4bd..fab3dadbe41 100644 --- a/lua/nvim-tree/diagnostics.lua +++ b/lua/nvim-tree/diagnostics.lua @@ -1,4 +1,3 @@ -local a = vim.api local utils = require "nvim-tree.utils" local view = require "nvim-tree.view" local core = require "nvim-tree.core" @@ -18,7 +17,7 @@ local sign_names = { local function add_sign(linenr, severity) local buf = view.get_bufnr() - if not a.nvim_buf_is_valid(buf) or not a.nvim_buf_is_loaded(buf) then + if not vim.api.nvim_buf_is_valid(buf) or not vim.api.nvim_buf_is_loaded(buf) then return end local sign_name = sign_names[severity][1] @@ -30,8 +29,8 @@ local function from_nvim_lsp() for _, diagnostic in ipairs(vim.diagnostic.get()) do local buf = diagnostic.bufnr - if a.nvim_buf_is_valid(buf) then - local bufname = a.nvim_buf_get_name(buf) + if vim.api.nvim_buf_is_valid(buf) then + local bufname = vim.api.nvim_buf_get_name(buf) local lowest_severity = buffer_severity[bufname] if not lowest_severity or diagnostic.severity < lowest_severity then buffer_severity[bufname] = diagnostic.severity diff --git a/lua/nvim-tree/explorer/common.lua b/lua/nvim-tree/explorer/common.lua index e3c3e76d32a..c3bed863e1a 100644 --- a/lua/nvim-tree/explorer/common.lua +++ b/lua/nvim-tree/explorer/common.lua @@ -1,5 +1,3 @@ -local uv = vim.loop - local M = {} local function get_dir_git_status(parent_ignored, status, absolute_path) @@ -22,7 +20,7 @@ local function get_git_status(parent_ignored, status, absolute_path) end function M.has_one_child_folder(node) - return #node.nodes == 1 and node.nodes[1].nodes and uv.fs_access(node.nodes[1].absolute_path, "R") + return #node.nodes == 1 and node.nodes[1].nodes and vim.loop.fs_access(node.nodes[1].absolute_path, "R") end function M.update_git_status(node, parent_ignored, status) diff --git a/lua/nvim-tree/explorer/explore.lua b/lua/nvim-tree/explorer/explore.lua index 76e6cfc0094..16c6fac81e4 100644 --- a/lua/nvim-tree/explorer/explore.lua +++ b/lua/nvim-tree/explorer/explore.lua @@ -1,5 +1,3 @@ -local uv = vim.loop - local utils = require "nvim-tree.utils" local builders = require "nvim-tree.explorer.node-builders" local common = require "nvim-tree.explorer.common" @@ -11,14 +9,14 @@ local notify = require "nvim-tree.notify" local M = {} local function get_type_from(type_, cwd) - return type_ or (uv.fs_stat(cwd) or {}).type + return type_ or (vim.loop.fs_stat(cwd) or {}).type end local function populate_children(handle, cwd, node, status) local node_ignored = node.git_status == "!!" local nodes_by_path = utils.bool_record(node.nodes, "absolute_path") while true do - local name, t = uv.fs_scandir_next(handle) + local name, t = vim.loop.fs_scandir_next(handle) if not name then break end @@ -31,7 +29,7 @@ local function populate_children(handle, cwd, node, status) and not nodes_by_path[abs] then local child = nil - if t == "directory" and uv.fs_access(abs, "R") then + if t == "directory" and vim.loop.fs_access(abs, "R") then child = builders.folder(node, abs, name) elseif t == "file" then child = builders.file(node, abs, name) @@ -51,7 +49,7 @@ local function populate_children(handle, cwd, node, status) end local function get_dir_handle(cwd) - local handle = uv.fs_scandir(cwd) + local handle = vim.loop.fs_scandir(cwd) if type(handle) == "string" then notify.error(handle) return diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index 6b9a8c9e5cc..a1559299e5c 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -1,5 +1,3 @@ -local uv = vim.loop - local git = require "nvim-tree.git" local watch = require "nvim-tree.explorer.watch" local common = require "nvim-tree.explorer.common" @@ -13,7 +11,7 @@ local Explorer = {} Explorer.__index = Explorer function Explorer.new(cwd) - cwd = uv.fs_realpath(cwd or uv.cwd()) + cwd = vim.loop.fs_realpath(cwd or vim.loop.cwd()) local explorer = setmetatable({ absolute_path = cwd, nodes = {}, diff --git a/lua/nvim-tree/explorer/node-builders.lua b/lua/nvim-tree/explorer/node-builders.lua index 606f10c6756..1cc04f9a15e 100644 --- a/lua/nvim-tree/explorer/node-builders.lua +++ b/lua/nvim-tree/explorer/node-builders.lua @@ -1,4 +1,3 @@ -local uv = vim.loop local utils = require "nvim-tree.utils" local watch = require "nvim-tree.explorer.watch" @@ -8,13 +7,13 @@ local M = { } function M.folder(parent, absolute_path, name) - local handle = uv.fs_scandir(absolute_path) - local has_children = handle and uv.fs_scandir_next(handle) ~= nil + local handle = vim.loop.fs_scandir(absolute_path) + local has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil return { type = "directory", absolute_path = absolute_path, - fs_stat = uv.fs_stat(absolute_path), + fs_stat = vim.loop.fs_stat(absolute_path), group_next = nil, -- If node is grouped, this points to the next child dir/link node has_children = has_children, name = name, @@ -39,7 +38,7 @@ function M.is_executable(parent, absolute_path, ext) return utils.is_wsl_windows_fs_exe(ext) end end - return uv.fs_access(absolute_path, "X") + return vim.loop.fs_access(absolute_path, "X") end function M.file(parent, absolute_path, name) @@ -50,7 +49,7 @@ function M.file(parent, absolute_path, name) absolute_path = absolute_path, executable = M.is_executable(parent, absolute_path, ext), extension = ext, - fs_stat = uv.fs_stat(absolute_path), + fs_stat = vim.loop.fs_stat(absolute_path), name = name, parent = parent, } @@ -63,11 +62,11 @@ end -- So we need to check for link_to ~= nil when adding new links to the main tree function M.link(parent, absolute_path, name) --- I dont know if this is needed, because in my understanding, there isn't hard links in windows, but just to be sure i changed it. - local link_to = uv.fs_realpath(absolute_path) + local link_to = vim.loop.fs_realpath(absolute_path) local open, nodes, has_children, watcher - if (link_to ~= nil) and uv.fs_stat(link_to).type == "directory" then - local handle = uv.fs_scandir(link_to) - has_children = handle and uv.fs_scandir_next(handle) ~= nil + if (link_to ~= nil) and vim.loop.fs_stat(link_to).type == "directory" then + local handle = vim.loop.fs_scandir(link_to) + has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil open = false nodes = {} watcher = watch.create_watcher(link_to) @@ -76,7 +75,7 @@ function M.link(parent, absolute_path, name) return { type = "link", absolute_path = absolute_path, - fs_stat = uv.fs_stat(absolute_path), + fs_stat = vim.loop.fs_stat(absolute_path), group_next = nil, -- If node is grouped, this points to the next child dir/link node has_children = has_children, link_to = link_to, diff --git a/lua/nvim-tree/explorer/reload.lua b/lua/nvim-tree/explorer/reload.lua index 5e6e7c97f80..a7317461540 100644 --- a/lua/nvim-tree/explorer/reload.lua +++ b/lua/nvim-tree/explorer/reload.lua @@ -1,5 +1,3 @@ -local uv = vim.loop - local utils = require "nvim-tree.utils" local builders = require "nvim-tree.explorer.node-builders" local common = require "nvim-tree.explorer.common" @@ -21,7 +19,7 @@ end function M.reload(node, status) local cwd = node.link_to or node.absolute_path - local handle = uv.fs_scandir(cwd) + local handle = vim.loop.fs_scandir(cwd) if type(handle) == "string" then notify.error(handle) return @@ -37,7 +35,7 @@ function M.reload(node, status) local node_ignored = node.git_status == "!!" local nodes_by_path = utils.key_by(node.nodes, "absolute_path") while true do - local ok, name, t = pcall(uv.fs_scandir_next, handle) + local ok, name, t = pcall(vim.loop.fs_scandir_next, handle) if not ok or not name then break end @@ -48,7 +46,7 @@ function M.reload(node, status) return stat end - stat = uv.fs_stat(path) + stat = vim.loop.fs_stat(path) return stat end @@ -69,7 +67,7 @@ function M.reload(node, status) end if not nodes_by_path[abs] then - if t == "directory" and uv.fs_access(abs, "R") then + if t == "directory" and vim.loop.fs_access(abs, "R") then local folder = builders.folder(node, abs, name) nodes_by_path[abs] = folder table.insert(node.nodes, folder) diff --git a/lua/nvim-tree/git/init.lua b/lua/nvim-tree/git/init.lua index 5c1c796cf91..8eeeb22e8c1 100644 --- a/lua/nvim-tree/git/init.lua +++ b/lua/nvim-tree/git/init.lua @@ -1,5 +1,3 @@ -local uv = vim.loop - local log = require "nvim-tree.log" local utils = require "nvim-tree.utils" local git_utils = require "nvim-tree.git.utils" @@ -74,7 +72,7 @@ function M.get_project_root(cwd) return nil end - local stat, _ = uv.fs_stat(cwd) + local stat, _ = vim.loop.fs_stat(cwd) if not stat or stat.type ~= "directory" then return nil end diff --git a/lua/nvim-tree/git/runner.lua b/lua/nvim-tree/git/runner.lua index c987af372d1..686b5f80bd5 100644 --- a/lua/nvim-tree/git/runner.lua +++ b/lua/nvim-tree/git/runner.lua @@ -1,4 +1,3 @@ -local uv = vim.loop local log = require "nvim-tree.log" local utils = require "nvim-tree.utils" @@ -60,9 +59,9 @@ end function Runner:_run_git_job() local handle, pid - local stdout = uv.new_pipe(false) - local stderr = uv.new_pipe(false) - local timer = uv.new_timer() + local stdout = vim.loop.new_pipe(false) + local stderr = vim.loop.new_pipe(false) + local timer = vim.loop.new_timer() local function on_finish(rc) self.rc = rc or 0 @@ -79,14 +78,14 @@ function Runner:_run_git_job() handle:close() end - pcall(uv.kill, pid) + pcall(vim.loop.kill, pid) end local opts = self:_getopts(stdout, stderr) log.line("git", "running job with timeout %dms", self.timeout) log.line("git", "git %s", table.concat(utils.array_remove_nils(opts.args), " ")) - handle, pid = uv.spawn( + handle, pid = vim.loop.spawn( "git", opts, vim.schedule_wrap(function(rc) @@ -115,8 +114,8 @@ function Runner:_run_git_job() self:_log_raw_output(data) end - uv.read_start(stdout, vim.schedule_wrap(manage_stdout)) - uv.read_start(stderr, vim.schedule_wrap(manage_stderr)) + vim.loop.read_start(stdout, vim.schedule_wrap(manage_stdout)) + vim.loop.read_start(stderr, vim.schedule_wrap(manage_stderr)) end function Runner:_wait() diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index 93821fd6954..bb66df44b38 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -1,5 +1,3 @@ -local api = vim.api - local renderer = require "nvim-tree.renderer" local view = require "nvim-tree.view" local core = require "nvim-tree.core" @@ -19,7 +17,7 @@ function M.get_node_at_cursor() return end - local cursor = api.nvim_win_get_cursor(view.get_winnr()) + local cursor = vim.api.nvim_win_get_cursor(view.get_winnr()) local line = cursor[1] if view.is_help_ui() then local help_lines = require("nvim-tree.renderer.help").compute_lines() @@ -57,7 +55,7 @@ function M.expand_or_collapse(node) end function M.set_target_win() - local id = api.nvim_get_current_win() + local id = vim.api.nvim_get_current_win() local tree_id = view.get_winnr() if tree_id and id == tree_id then M.target_winid = 0 @@ -81,10 +79,10 @@ local function open_view_and_draw() end local function should_hijack_current_buf() - local bufnr = api.nvim_get_current_buf() - local bufname = api.nvim_buf_get_name(bufnr) - local bufmodified = api.nvim_buf_get_option(bufnr, "modified") - local ft = api.nvim_buf_get_option(bufnr, "ft") + local bufnr = vim.api.nvim_get_current_buf() + local bufname = vim.api.nvim_buf_get_name(bufnr) + local bufmodified = vim.api.nvim_buf_get_option(bufnr, "modified") + local ft = vim.api.nvim_buf_get_option(bufnr, "ft") local should_hijack_unnamed = M.hijack_unnamed_buffer_when_opening and bufname == "" and not bufmodified and ft == "" local should_hijack_dir = bufname ~= "" and vim.fn.isdirectory(bufname) == 1 and M.hijack_directories.enable diff --git a/lua/nvim-tree/live-filter.lua b/lua/nvim-tree/live-filter.lua index a91dd1082e9..df28911c45a 100644 --- a/lua/nvim-tree/live-filter.lua +++ b/lua/nvim-tree/live-filter.lua @@ -1,5 +1,3 @@ -local a = vim.api - local view = require "nvim-tree.view" local utils = require "nvim-tree.utils" local Iterator = require "nvim-tree.iterators.node-iterator" @@ -28,9 +26,9 @@ local overlay_winnr = nil local function remove_overlay() if view.View.float.enable and view.View.float.quit_on_focus_loss then -- return to normal nvim-tree float behaviour when filter window is closed - a.nvim_create_autocmd("WinLeave", { + vim.api.nvim_create_autocmd("WinLeave", { pattern = "NvimTree_*", - group = a.nvim_create_augroup("NvimTree", { clear = false }), + group = vim.api.nvim_create_augroup("NvimTree", { clear = false }), callback = function() if utils.is_nvim_tree_buf(0) then view.close() @@ -39,7 +37,7 @@ local function remove_overlay() }) end - a.nvim_win_close(overlay_winnr, { force = true }) + vim.api.nvim_win_close(overlay_winnr, { force = true }) overlay_bufnr = nil overlay_winnr = nil @@ -85,54 +83,54 @@ end local function record_char() vim.schedule(function() - M.filter = a.nvim_buf_get_lines(overlay_bufnr, 0, -1, false)[1] + M.filter = vim.api.nvim_buf_get_lines(overlay_bufnr, 0, -1, false)[1] M.apply_filter() redraw() end) end local function configure_buffer_overlay() - overlay_bufnr = a.nvim_create_buf(false, true) + overlay_bufnr = vim.api.nvim_create_buf(false, true) - a.nvim_buf_attach(overlay_bufnr, true, { + vim.api.nvim_buf_attach(overlay_bufnr, true, { on_lines = record_char, }) - a.nvim_create_autocmd("InsertLeave", { + vim.api.nvim_create_autocmd("InsertLeave", { callback = remove_overlay, once = true, }) - a.nvim_buf_set_keymap(overlay_bufnr, "i", "", "stopinsert", {}) + vim.api.nvim_buf_set_keymap(overlay_bufnr, "i", "", "stopinsert", {}) end local function create_overlay() local min_width = 20 if view.View.float.enable then -- don't close nvim-tree float when focus is changed to filter window - a.nvim_clear_autocmds { + vim.api.nvim_clear_autocmds { event = "WinLeave", pattern = "NvimTree_*", - group = a.nvim_create_augroup("NvimTree", { clear = false }), + group = vim.api.nvim_create_augroup("NvimTree", { clear = false }), } min_width = min_width - 2 end configure_buffer_overlay() - overlay_winnr = a.nvim_open_win(overlay_bufnr, true, { + overlay_winnr = vim.api.nvim_open_win(overlay_bufnr, true, { col = 1, row = 0, relative = "cursor", - width = math.max(min_width, a.nvim_win_get_width(view.get_winnr()) - #M.prefix - 2), + width = math.max(min_width, vim.api.nvim_win_get_width(view.get_winnr()) - #M.prefix - 2), height = 1, border = "none", style = "minimal", }) - a.nvim_buf_set_option(overlay_bufnr, "modifiable", true) - a.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { M.filter }) + vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true) + vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { M.filter }) vim.cmd "startinsert" - a.nvim_win_set_cursor(overlay_winnr, { 1, #M.filter + 1 }) + vim.api.nvim_win_set_cursor(overlay_winnr, { 1, #M.filter + 1 }) end function M.start_filtering() diff --git a/lua/nvim-tree/log.lua b/lua/nvim-tree/log.lua index 480dc63e80e..c307d7bc219 100644 --- a/lua/nvim-tree/log.lua +++ b/lua/nvim-tree/log.lua @@ -1,5 +1,3 @@ -local uv = vim.loop - local M = { config = nil, path = nil, @@ -29,7 +27,7 @@ function M.profile_start(fmt, ...) return end M.line("profile", "START " .. (fmt or "???"), ...) - return uv.hrtime() + return vim.loop.hrtime() end --- Write to log file via M.line @@ -39,7 +37,7 @@ function M.profile_end(start, fmt, ...) if not M.path or not M.config.types.profile and not M.config.types.all then return end - local millis = start and math.modf((uv.hrtime() - start) / 1000000) or -1 + local millis = start and math.modf((vim.loop.hrtime() - start) / 1000000) or -1 M.line("profile", "END " .. (fmt or "???") .. " " .. millis .. "ms", ...) end diff --git a/lua/nvim-tree/renderer/components/full-name.lua b/lua/nvim-tree/renderer/components/full-name.lua index 85320c97408..1a66460d978 100644 --- a/lua/nvim-tree/renderer/components/full-name.lua +++ b/lua/nvim-tree/renderer/components/full-name.lua @@ -1,30 +1,28 @@ local M = {} -local api = vim.api -local fn = vim.fn local utils = require "nvim-tree.utils" local function hide(win) if win then - if api.nvim_win_is_valid(win) then - api.nvim_win_close(win, true) + if vim.api.nvim_win_is_valid(win) then + vim.api.nvim_win_close(win, true) end end end -- reduce signcolumn/foldcolumn from window width local function effective_win_width() - local win_width = fn.winwidth(0) + local win_width = vim.fn.winwidth(0) -- return zero if the window cannot be found - local win_id = fn.win_getid() + local win_id = vim.fn.win_getid() if win_id == 0 then return win_width end -- if the window does not exist the result is an empty list - local win_info = fn.getwininfo(win_id) + local win_info = vim.fn.getwininfo(win_id) -- check if result table is empty if next(win_info) == nil then @@ -35,7 +33,7 @@ local function effective_win_width() end local function show() - local line_nr = api.nvim_win_get_cursor(0)[1] + local line_nr = vim.api.nvim_win_get_cursor(0)[1] if line_nr == 1 and require("nvim-tree.view").is_root_folder_visible() then return end @@ -47,36 +45,36 @@ local function show() return end - local line = fn.getline "." - local leftcol = fn.winsaveview().leftcol + local line = vim.fn.getline "." + local leftcol = vim.fn.winsaveview().leftcol -- hide full name if left column of node in nvim-tree win is not zero if leftcol ~= 0 then return end - local text_width = fn.strdisplaywidth(fn.substitute(line, "[^[:print:]]*$", "", "g")) + local text_width = vim.fn.strdisplaywidth(vim.fn.substitute(line, "[^[:print:]]*$", "", "g")) local win_width = effective_win_width() if text_width < win_width then return end - M.popup_win = api.nvim_open_win(api.nvim_create_buf(false, false), false, { + M.popup_win = vim.api.nvim_open_win(vim.api.nvim_create_buf(false, false), false, { relative = "win", - bufpos = { fn.line "." - 2, 0 }, + bufpos = { vim.fn.line "." - 2, 0 }, width = math.min(text_width, vim.o.columns - 2), height = 1, noautocmd = true, style = "minimal", }) - local ns_id = api.nvim_get_namespaces()["NvimTreeHighlights"] - local extmarks = api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = 1 }) - api.nvim_win_call(M.popup_win, function() - fn.setbufline("%", 1, line) + local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"] + local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = 1 }) + vim.api.nvim_win_call(M.popup_win, function() + vim.fn.setbufline("%", 1, line) for _, extmark in ipairs(extmarks) do local hl = extmark[4] - api.nvim_buf_add_highlight(0, ns_id, hl.hl_group, 0, extmark[3], hl.end_col) + vim.api.nvim_buf_add_highlight(0, ns_id, hl.hl_group, 0, extmark[3], hl.end_col) end vim.cmd [[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=hide ]] end) @@ -88,8 +86,8 @@ M.setup = function(opts) return end - local group = api.nvim_create_augroup("nvim_tree_floating_node", { clear = true }) - api.nvim_create_autocmd({ "BufLeave", "CursorMoved" }, { + local group = vim.api.nvim_create_augroup("nvim_tree_floating_node", { clear = true }) + vim.api.nvim_create_autocmd({ "BufLeave", "CursorMoved" }, { group = group, pattern = { "NvimTree_*" }, callback = function() @@ -99,7 +97,7 @@ M.setup = function(opts) end, }) - api.nvim_create_autocmd({ "CursorMoved" }, { + vim.api.nvim_create_autocmd({ "CursorMoved" }, { group = group, pattern = { "NvimTree_*" }, callback = function() diff --git a/lua/nvim-tree/renderer/init.lua b/lua/nvim-tree/renderer/init.lua index 1efe31d68c8..e31fcff004b 100644 --- a/lua/nvim-tree/renderer/init.lua +++ b/lua/nvim-tree/renderer/init.lua @@ -12,19 +12,17 @@ local Builder = require "nvim-tree.renderer.builder" local live_filter = require "nvim-tree.live-filter" local marks = require "nvim-tree.marks" -local api = vim.api - local M = { last_highlights = {}, } -local namespace_id = api.nvim_create_namespace "NvimTreeHighlights" +local namespace_id = vim.api.nvim_create_namespace "NvimTreeHighlights" local function _draw(bufnr, lines, hl, signs) - api.nvim_buf_set_option(bufnr, "modifiable", true) - api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) + vim.api.nvim_buf_set_option(bufnr, "modifiable", true) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) M.render_hl(bufnr, hl) - api.nvim_buf_set_option(bufnr, "modifiable", false) + vim.api.nvim_buf_set_option(bufnr, "modifiable", false) vim.fn.sign_unplace(git.SIGN_GROUP) for _, sign in pairs(signs) do vim.fn.sign_place(0, git.SIGN_GROUP, sign.sign, bufnr, { lnum = sign.lnum, priority = 1 }) @@ -32,12 +30,12 @@ local function _draw(bufnr, lines, hl, signs) end function M.render_hl(bufnr, hl) - if not bufnr or not api.nvim_buf_is_loaded(bufnr) then + if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then return end - api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1) + vim.api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1) for _, data in ipairs(hl or M.last_highlights) do - api.nvim_buf_add_highlight(bufnr, namespace_id, data[1], data[2], data[3], data[4]) + vim.api.nvim_buf_add_highlight(bufnr, namespace_id, data[1], data[2], data[3], data[4]) end end @@ -50,13 +48,13 @@ local picture_map = { function M.draw() local bufnr = view.get_bufnr() - if not core.get_explorer() or not bufnr or not api.nvim_buf_is_loaded(bufnr) then + if not core.get_explorer() or not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then return end local ps = log.profile_start "draw" - local cursor = api.nvim_win_get_cursor(view.get_winnr()) + local cursor = vim.api.nvim_win_get_cursor(view.get_winnr()) icon_component.reset_config() local lines, hl @@ -84,7 +82,7 @@ function M.draw() M.last_highlights = hl if cursor and #lines >= cursor[1] then - api.nvim_win_set_cursor(view.get_winnr(), cursor) + vim.api.nvim_win_set_cursor(view.get_winnr(), cursor) end if view.is_help_ui() then diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index 2946aa25378..badfcb3b69c 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -1,6 +1,3 @@ -local a = vim.api -local uv = vim.loop - local Iterator = require "nvim-tree.iterators.node-iterator" local M = { @@ -19,16 +16,16 @@ function M.str_find(haystack, needle) end function M.read_file(path) - local fd = uv.fs_open(path, "r", 438) + local fd = vim.loop.fs_open(path, "r", 438) if not fd then return "" end - local stat = uv.fs_fstat(fd) + local stat = vim.loop.fs_fstat(fd) if not stat then return "" end - local data = uv.fs_read(fd, stat.size, 0) - uv.fs_close(fd) + local data = vim.loop.fs_read(fd, stat.size, 0) + vim.loop.fs_close(fd) return data or "" end @@ -211,19 +208,19 @@ function M.is_wsl_windows_fs_exe(ext) end function M.rename_loaded_buffers(old_path, new_path) - for _, buf in pairs(a.nvim_list_bufs()) do - if a.nvim_buf_is_loaded(buf) then - local buf_name = a.nvim_buf_get_name(buf) + for _, buf in pairs(vim.api.nvim_list_bufs()) do + if vim.api.nvim_buf_is_loaded(buf) then + local buf_name = vim.api.nvim_buf_get_name(buf) local exact_match = buf_name == old_path local child_match = ( buf_name:sub(1, #old_path) == old_path and buf_name:sub(#old_path + 1, #old_path + 1) == path_separator ) if exact_match or child_match then - a.nvim_buf_set_name(buf, new_path .. buf_name:sub(#old_path + 1)) + vim.api.nvim_buf_set_name(buf, new_path .. buf_name:sub(#old_path + 1)) -- to avoid the 'overwrite existing file' error message on write for -- normal files - if a.nvim_buf_get_option(buf, "buftype") == "" then - a.nvim_buf_call(buf, function() + if vim.api.nvim_buf_get_option(buf, "buftype") == "" then + vim.api.nvim_buf_call(buf, function() vim.cmd "silent! write!" vim.cmd "edit" end) @@ -369,7 +366,7 @@ function M.debounce(context, timeout, callback) timer_stop_close(debouncer.timer) end - local timer = uv.new_timer() + local timer = vim.loop.new_timer() debouncer.timer = timer timer:start(timeout, 0, function() timer_stop_close(timer) @@ -457,7 +454,7 @@ function M.is_nvim_tree_buf(bufnr) bufnr = 0 end if vim.fn.bufexists(bufnr) then - local bufname = a.nvim_buf_get_name(bufnr) + local bufname = vim.api.nvim_buf_get_name(bufnr) if vim.fn.fnamemodify(bufname, ":t"):match "^NvimTree_[0-9]+$" then if vim.bo[bufnr].filetype == "NvimTree" then return true diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index fe95d4e15cb..00e6f498c91 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -1,5 +1,3 @@ -local a = vim.api - local M = {} local events = require "nvim-tree.events" @@ -77,9 +75,9 @@ local function matches_bufnr(bufnr) end local function wipe_rogue_buffer() - for _, bufnr in ipairs(a.nvim_list_bufs()) do + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do if not matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then - pcall(a.nvim_buf_delete, bufnr, { force = true }) + pcall(vim.api.nvim_buf_delete, bufnr, { force = true }) end end end @@ -87,9 +85,9 @@ end local function create_buffer(bufnr) wipe_rogue_buffer() - local tab = a.nvim_get_current_tabpage() - BUFNR_PER_TAB[tab] = bufnr or a.nvim_create_buf(false, false) - a.nvim_buf_set_name(M.get_bufnr(), "NvimTree_" .. tab) + local tab = vim.api.nvim_get_current_tabpage() + BUFNR_PER_TAB[tab] = bufnr or vim.api.nvim_create_buf(false, false) + vim.api.nvim_buf_set_name(M.get_bufnr(), "NvimTree_" .. tab) for option, value in pairs(BUFFER_OPTIONS) do vim.bo[M.get_bufnr()][option] = value @@ -122,7 +120,7 @@ local move_tbl = { -- setup_tabpage sets up the initial state of a tab local function setup_tabpage(tabpage) - local winnr = a.nvim_get_current_win() + local winnr = vim.api.nvim_get_current_win() M.View.tabpages[tabpage] = vim.tbl_extend("force", M.View.tabpages[tabpage] or tabinitial, { winnr = winnr }) end @@ -143,17 +141,17 @@ end local function open_window() if M.View.float.enable then - a.nvim_open_win(0, true, open_win_config()) + vim.api.nvim_open_win(0, true, open_win_config()) else - a.nvim_command "vsp" + vim.api.nvim_command "vsp" M.reposition_window() end - setup_tabpage(a.nvim_get_current_tabpage()) + setup_tabpage(vim.api.nvim_get_current_tabpage()) set_window_options_and_buffer() end local function is_buf_displayed(buf) - return a.nvim_buf_is_valid(buf) and vim.fn.buflisted(buf) == 1 + return vim.api.nvim_buf_is_valid(buf) and vim.fn.buflisted(buf) == 1 end local function get_alt_or_next_buf() @@ -162,7 +160,7 @@ local function get_alt_or_next_buf() return alt_buf end - for _, buf in ipairs(a.nvim_list_bufs()) do + for _, buf in ipairs(vim.api.nvim_list_bufs()) do if is_buf_displayed(buf) then return buf end @@ -170,7 +168,7 @@ local function get_alt_or_next_buf() end local function switch_buf_if_last_buf() - if #a.nvim_list_wins() == 1 then + if #vim.api.nvim_list_wins() == 1 then local buf = get_alt_or_next_buf() if buf then vim.cmd("sb" .. buf) @@ -182,8 +180,8 @@ end -- save_tab_state saves any state that should be preserved across redraws. local function save_tab_state() - local tabpage = a.nvim_get_current_tabpage() - M.View.cursors[tabpage] = a.nvim_win_get_cursor(M.get_winnr()) + local tabpage = vim.api.nvim_get_current_tabpage() + M.View.cursors[tabpage] = vim.api.nvim_win_get_cursor(M.get_winnr()) end function M.close() @@ -193,15 +191,15 @@ function M.close() save_tab_state() switch_buf_if_last_buf() local tree_win = M.get_winnr() - local current_win = a.nvim_get_current_win() - for _, win in pairs(a.nvim_list_wins()) do - if tree_win ~= win and a.nvim_win_get_config(win).relative == "" then + local current_win = vim.api.nvim_get_current_win() + for _, win in pairs(vim.api.nvim_list_wins()) do + if tree_win ~= win and vim.api.nvim_win_get_config(win).relative == "" then local prev_win = vim.fn.winnr "#" -- this tab only if tree_win == current_win and prev_win > 0 then - a.nvim_set_current_win(vim.fn.win_getid(prev_win)) + vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win)) end - if a.nvim_win_is_valid(tree_win) then - a.nvim_win_close(tree_win, true) + if vim.api.nvim_win_is_valid(tree_win) then + vim.api.nvim_win_close(tree_win, true) end events._dispatch_on_tree_close() return @@ -275,7 +273,7 @@ function M.resize(size) end local new_size = get_size() - a.nvim_win_set_width(M.get_winnr(), new_size) + vim.api.nvim_win_set_width(M.get_winnr(), new_size) events._dispatch_on_tree_resize(new_size) @@ -286,19 +284,19 @@ end function M.reposition_window() local move_to = move_tbl[M.View.side] - a.nvim_command("wincmd " .. move_to) + vim.api.nvim_command("wincmd " .. move_to) M.resize() end local function set_current_win() - local current_tab = a.nvim_get_current_tabpage() - M.View.tabpages[current_tab].winnr = a.nvim_get_current_win() + local current_tab = vim.api.nvim_get_current_tabpage() + M.View.tabpages[current_tab].winnr = vim.api.nvim_get_current_win() end function M.open_in_current_win(opts) opts = opts or { hijack_current_buf = true, resize = true } - create_buffer(opts.hijack_current_buf and a.nvim_get_current_buf()) - setup_tabpage(a.nvim_get_current_tabpage()) + create_buffer(opts.hijack_current_buf and vim.api.nvim_get_current_buf()) + setup_tabpage(vim.api.nvim_get_current_tabpage()) set_current_win() set_window_options_and_buffer() if opts.resize then @@ -308,7 +306,7 @@ function M.open_in_current_win(opts) end function M.abandon_current_window() - local tab = a.nvim_get_current_tabpage() + local tab = vim.api.nvim_get_current_tabpage() BUFNR_PER_TAB[tab] = nil M.View.tabpages[tab].winnr = nil end @@ -316,26 +314,26 @@ end function M.is_visible(opts) if opts and opts.any_tabpage then for _, v in pairs(M.View.tabpages) do - if v.winnr and a.nvim_win_is_valid(v.winnr) then + if v.winnr and vim.api.nvim_win_is_valid(v.winnr) then return true end end return false end - return M.get_winnr() ~= nil and a.nvim_win_is_valid(M.get_winnr()) + return M.get_winnr() ~= nil and vim.api.nvim_win_is_valid(M.get_winnr()) end function M.set_cursor(opts) if M.is_visible() then - pcall(a.nvim_win_set_cursor, M.get_winnr(), opts) + pcall(vim.api.nvim_win_set_cursor, M.get_winnr(), opts) end end function M.focus(winnr, open_if_closed) local wnr = winnr or M.get_winnr() - if a.nvim_win_get_tabpage(wnr or 0) ~= a.nvim_win_get_tabpage(0) then + if vim.api.nvim_win_get_tabpage(wnr or 0) ~= vim.api.nvim_win_get_tabpage(0) then M.close() M.open() wnr = M.get_winnr() @@ -343,12 +341,12 @@ function M.focus(winnr, open_if_closed) M.open() end - a.nvim_set_current_win(wnr) + vim.api.nvim_set_current_win(wnr) end --- Restores the state of a NvimTree window if it was initialized before. function M.restore_tab_state() - local tabpage = a.nvim_get_current_tabpage() + local tabpage = vim.api.nvim_get_current_tabpage() M.set_cursor(M.View.cursors[tabpage]) end @@ -356,7 +354,7 @@ end ---@param tabpage number: (optional) the number of the chosen tabpage. Defaults to current tabpage. ---@return number function M.get_winnr(tabpage) - tabpage = tabpage or a.nvim_get_current_tabpage() + tabpage = tabpage or vim.api.nvim_get_current_tabpage() local tabinfo = M.View.tabpages[tabpage] if tabinfo ~= nil then return tabinfo.winnr @@ -366,14 +364,14 @@ end --- Returns the current nvim tree bufnr ---@return number function M.get_bufnr() - return BUFNR_PER_TAB[a.nvim_get_current_tabpage()] + return BUFNR_PER_TAB[vim.api.nvim_get_current_tabpage()] end --- Checks if nvim-tree is displaying the help ui within the tabpage specified ---@param tabpage number: (optional) the number of the chosen tabpage. Defaults to current tabpage. ---@return number function M.is_help_ui(tabpage) - tabpage = tabpage or a.nvim_get_current_tabpage() + tabpage = tabpage or vim.api.nvim_get_current_tabpage() local tabinfo = M.View.tabpages[tabpage] if tabinfo ~= nil then return tabinfo.help @@ -381,12 +379,12 @@ function M.is_help_ui(tabpage) end function M.toggle_help(tabpage) - tabpage = tabpage or a.nvim_get_current_tabpage() + tabpage = tabpage or vim.api.nvim_get_current_tabpage() M.View.tabpages[tabpage].help = not M.View.tabpages[tabpage].help end function M.is_buf_valid(bufnr) - return bufnr and a.nvim_buf_is_valid(bufnr) and a.nvim_buf_is_loaded(bufnr) + return bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr) end function M._prevent_buffer_override() @@ -397,10 +395,10 @@ function M._prevent_buffer_override() -- because this event needs to be run on bufWipeout. -- Otherwise the curwin/curbuf would match the view buffer and the view window. vim.schedule(function() - local curwin = a.nvim_get_current_win() - local curwinconfig = a.nvim_win_get_config(curwin) - local curbuf = a.nvim_win_get_buf(curwin) - local bufname = a.nvim_buf_get_name(curbuf) + local curwin = vim.api.nvim_get_current_win() + local curwinconfig = vim.api.nvim_win_get_config(curwin) + local curbuf = vim.api.nvim_win_get_buf(curwin) + local bufname = vim.api.nvim_buf_get_name(curbuf) if not bufname:match "NvimTree" then for i, tabpage in ipairs(M.View.tabpages) do @@ -420,7 +418,7 @@ function M._prevent_buffer_override() vim.cmd "setlocal nowinfixheight" M.open { focus_tree = false } require("nvim-tree.renderer").draw() - pcall(a.nvim_win_close, curwin, { force = true }) + pcall(vim.api.nvim_win_close, curwin, { force = true }) -- to handle opening a file using :e when nvim-tree is on floating mode -- falling back to the current window instead of creating a new one diff --git a/lua/nvim-tree/watcher.lua b/lua/nvim-tree/watcher.lua index 5a2b1709733..972147dfbd1 100644 --- a/lua/nvim-tree/watcher.lua +++ b/lua/nvim-tree/watcher.lua @@ -1,4 +1,3 @@ -local uv = vim.loop local notify = require "nvim-tree.notify" local log = require "nvim-tree.log" @@ -45,7 +44,7 @@ function Event:start() local rc, _, name - self._fs_event, _, name = uv.new_fs_event() + self._fs_event, _, name = vim.loop.new_fs_event() if not self._fs_event then self._fs_event = nil notify.warn(string.format("Could not initialize an fs_event watcher for path %s : %s", self._path, name))