LunarVim/lua/core/nvimtree.lua

142 lines
3.5 KiB
Lua
Raw Normal View History

2021-06-28 04:11:33 +02:00
local M = {}
local Log = require "core.log"
function M.config()
lvim.builtin.nvimtree = {
active = true,
on_config_done = nil,
setup = {
open_on_setup = false,
auto_close = true,
open_on_tab = false,
update_focused_file = {
enable = true,
},
diagnostics = {
enable = true,
icons = {
hint = "",
info = "",
warning = "",
error = "",
},
},
view = {
width = 30,
side = "left",
auto_resize = false,
mappings = {
custom_only = false,
},
},
},
show_icons = {
git = true,
folders = true,
files = true,
folder_arrows = true,
tree_width = 30,
},
ignore = { ".git", "node_modules", ".cache" },
quit_on_open = false,
hide_dotfiles = true,
git_hl = true,
root_folder_modifier = ":t",
allow_resize = true,
auto_ignore_ft = { "startify", "dashboard" },
icons = {
default = "",
symlink = "",
git = {
unstaged = "",
staged = "S",
unmerged = "",
renamed = "",
deleted = "",
untracked = "U",
ignored = "",
},
folder = {
default = "",
open = "",
empty = "",
empty_open = "",
symlink = "",
},
},
}
end
function M.setup()
2021-07-18 13:27:06 +02:00
local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config")
if not status_ok then
Log:error "Failed to load nvim-tree.config"
2021-07-18 13:27:06 +02:00
return
end
2021-07-05 03:14:01 +02:00
local g = vim.g
2021-04-15 06:17:48 +02:00
for opt, val in pairs(lvim.builtin.nvimtree) do
g["nvim_tree_" .. opt] = val
end
-- Implicitly update nvim-tree when project module is active
if lvim.builtin.project.active then
lvim.builtin.nvimtree.respect_buf_cwd = true
lvim.builtin.nvimtree.setup.update_cwd = true
lvim.builtin.nvimtree.setup.disable_netrw = false
lvim.builtin.nvimtree.setup.hijack_netrw = false
vim.g.netrw_banner = false
end
2021-07-07 02:42:29 +02:00
local tree_cb = nvim_tree_config.nvim_tree_callback
if not lvim.builtin.nvimtree.setup.view.mappings.list then
lvim.builtin.nvimtree.setup.view.mappings.list = {
{ key = { "l", "<CR>", "o" }, cb = tree_cb "edit" },
{ key = "h", cb = tree_cb "close_node" },
{ key = "v", cb = tree_cb "vsplit" },
}
end
lvim.builtin.which_key.mappings["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" }
local tree_view = require "nvim-tree.view"
-- Add nvim_tree open callback
local open = tree_view.open
tree_view.open = function()
M.on_open()
open()
end
vim.cmd "au WinClosed * lua require('core.nvimtree').on_close()"
if lvim.builtin.nvimtree.on_config_done then
lvim.builtin.nvimtree.on_config_done(nvim_tree_config)
end
require("nvim-tree").setup(lvim.builtin.nvimtree.setup)
end
function M.on_open()
2021-09-26 19:41:44 +02:00
if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.setup.view.side == "left" then
require("bufferline.state").set_offset(lvim.builtin.nvimtree.setup.view.width + 1, "")
2021-07-18 13:27:06 +02:00
end
end
function M.on_close()
local buf = tonumber(vim.fn.expand "<abuf>")
local ft = vim.api.nvim_buf_get_option(buf, "filetype")
if ft == "NvimTree" and package.loaded["bufferline.state"] then
require("bufferline.state").set_offset(0)
2021-07-05 03:14:01 +02:00
end
2021-06-30 00:55:01 +02:00
end
function M.change_tree_dir(dir)
local lib_status_ok, lib = pcall(require, "nvim-tree.lib")
if lib_status_ok then
lib.change_dir(dir)
end
end
2021-06-28 04:11:33 +02:00
return M