Skip to content

Commit 0f7da14

Browse files
committed
chore: add guards to prepare setup refactoring
1 parent 0708a1c commit 0f7da14

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

lua/nvim-tree.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ local function update_base_dir_with_filepath(filepath, bufnr)
183183
end
184184

185185
function M.find_file(with_open)
186+
if not with_open and not TreeExplorer then return end
187+
186188
local bufname = vim.fn.bufname()
187189
local bufnr = api.nvim_get_current_buf()
188190
local filepath = vim.fn.fnamemodify(bufname, ':p')
@@ -224,6 +226,7 @@ function M.on_leave()
224226
end, 50)
225227
end
226228

229+
-- TODO: rewrite this to take into account setup by open
227230
function M.open_on_directory()
228231
local should_proceed = _config.update_to_buf_dir.auto_open or view.win_open()
229232
if not _config.update_to_buf_dir.enable or not should_proceed then

lua/nvim-tree/actions/change-dir.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ local M = {
1010
}
1111

1212
function M.fn(name)
13+
if not TreeExplorer then return end
14+
1315
local foldername = name == '..' and vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ':h') or name
1416
local no_cwd_change = vim.fn.expand(foldername) == TreeExplorer.cwd
1517
local new_tab = a.nvim_get_current_tabpage()

lua/nvim-tree/actions/reloaders.lua

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

3434
local event_running = false
3535
function M.reload_explorer(callback)
36-
if event_running or not TreeExplorer.cwd or vim.v.exiting ~= vim.NIL then
36+
if event_running or not TreeExplorer or not TreeExplorer.cwd or vim.v.exiting ~= vim.NIL then
3737
return
3838
end
3939
event_running = true
@@ -52,7 +52,7 @@ function M.reload_explorer(callback)
5252
end
5353

5454
function M.reload_git()
55-
if not git.config.enable or event_running then
55+
if not TreeExplorer or not git.config.enable or event_running then
5656
return
5757
end
5858
event_running = true

lua/nvim-tree/lib.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ local function get_node_at_line(line)
4747
end
4848

4949
function M.get_node_at_cursor()
50+
if not TreeExplorer then return end
5051
local winnr = view.get_winnr()
5152
local hide_root_folder = view.View.hide_root_folder
5253
if not winnr then

lua/nvim-tree/renderer/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ end
371371
local M = {}
372372

373373
function M.draw()
374-
if not TreeExplorer or not api.nvim_buf_is_loaded(view.View.bufnr) then
374+
if not TreeExplorer or not view.View.bufnr or not api.nvim_buf_is_loaded(view.View.bufnr) then
375375
return
376376
end
377377
local cursor
@@ -404,7 +404,7 @@ function M.draw()
404404
end
405405

406406
function M.render_hl(bufnr)
407-
if not api.nvim_buf_is_loaded(bufnr) then return end
407+
if not bufnr or not api.nvim_buf_is_loaded(bufnr) then return end
408408
api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1)
409409
for _, data in ipairs(hl) do
410410
api.nvim_buf_add_highlight(bufnr, namespace_id, data[1], data[2], data[3], data[4])

0 commit comments

Comments
 (0)