chore: add guards to prepare setup refactoring

This commit is contained in:
kiyan 2022-02-11 11:06:11 +01:00
parent 0708a1c551
commit 0f7da146bf
5 changed files with 10 additions and 4 deletions

View File

@ -183,6 +183,8 @@ local function update_base_dir_with_filepath(filepath, bufnr)
end
function M.find_file(with_open)
if not with_open and not TreeExplorer then return end
local bufname = vim.fn.bufname()
local bufnr = api.nvim_get_current_buf()
local filepath = vim.fn.fnamemodify(bufname, ':p')
@ -224,6 +226,7 @@ function M.on_leave()
end, 50)
end
-- TODO: rewrite this to take into account setup by open
function M.open_on_directory()
local should_proceed = _config.update_to_buf_dir.auto_open or view.win_open()
if not _config.update_to_buf_dir.enable or not should_proceed then

View File

@ -10,6 +10,8 @@ local M = {
}
function M.fn(name)
if not TreeExplorer then return end
local foldername = name == '..' and vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ':h') or name
local no_cwd_change = vim.fn.expand(foldername) == TreeExplorer.cwd
local new_tab = a.nvim_get_current_tabpage()

View File

@ -33,7 +33,7 @@ end
local event_running = false
function M.reload_explorer(callback)
if event_running or not TreeExplorer.cwd or vim.v.exiting ~= vim.NIL then
if event_running or not TreeExplorer or not TreeExplorer.cwd or vim.v.exiting ~= vim.NIL then
return
end
event_running = true
@ -52,7 +52,7 @@ function M.reload_explorer(callback)
end
function M.reload_git()
if not git.config.enable or event_running then
if not TreeExplorer or not git.config.enable or event_running then
return
end
event_running = true

View File

@ -47,6 +47,7 @@ local function get_node_at_line(line)
end
function M.get_node_at_cursor()
if not TreeExplorer then return end
local winnr = view.get_winnr()
local hide_root_folder = view.View.hide_root_folder
if not winnr then

View File

@ -371,7 +371,7 @@ end
local M = {}
function M.draw()
if not TreeExplorer or not api.nvim_buf_is_loaded(view.View.bufnr) then
if not TreeExplorer or not view.View.bufnr or not api.nvim_buf_is_loaded(view.View.bufnr) then
return
end
local cursor
@ -404,7 +404,7 @@ function M.draw()
end
function M.render_hl(bufnr)
if not api.nvim_buf_is_loaded(bufnr) then return end
if not bufnr or not api.nvim_buf_is_loaded(bufnr) then return end
api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1)
for _, data in ipairs(hl) do
api.nvim_buf_add_highlight(bufnr, namespace_id, data[1], data[2], data[3], data[4])