summaryrefslogtreecommitdiff
path: root/lua/lvim/builtin/nvimtree.lua
diff options
context:
space:
mode:
authorLostNeophyte <[email protected]>2023-02-18 08:55:05 +0100
committerLostNeophyte <[email protected]>2023-02-18 08:55:05 +0100
commit8f70ecd882cf44567ddbffb469373501492938f9 (patch)
tree1498fd1de08c1aec46fa628701e1b5e9a47c4e3b /lua/lvim/builtin/nvimtree.lua
parent3144585515000a1c3064c6129ded74f662598de1 (diff)
refactor(builtins): move builtins to lvim/builtinrefactor/builtins
Diffstat (limited to 'lua/lvim/builtin/nvimtree.lua')
-rw-r--r--lua/lvim/builtin/nvimtree.lua285
1 files changed, 285 insertions, 0 deletions
diff --git a/lua/lvim/builtin/nvimtree.lua b/lua/lvim/builtin/nvimtree.lua
new file mode 100644
index 00000000..bf76407c
--- /dev/null
+++ b/lua/lvim/builtin/nvimtree.lua
@@ -0,0 +1,285 @@
+local M = {}
+local Log = require "lvim.core.log"
+
+function M.config()
+ lvim.builtin.nvimtree = {
+ active = true,
+ setup = {
+ auto_reload_on_write = false,
+ disable_netrw = false,
+ hijack_cursor = false,
+ hijack_netrw = true,
+ hijack_unnamed_buffer_when_opening = false,
+ ignore_buffer_on_setup = false,
+ sort_by = "name",
+ root_dirs = {},
+ prefer_startup_root = false,
+ sync_root_with_cwd = true,
+ reload_on_bufenter = false,
+ respect_buf_cwd = false,
+ on_attach = "disable",
+ remove_keymaps = false,
+ select_prompts = false,
+ view = {
+ adaptive_size = false,
+ centralize_selection = false,
+ width = 30,
+ hide_root_folder = false,
+ side = "left",
+ preserve_window_proportions = false,
+ number = false,
+ relativenumber = false,
+ signcolumn = "yes",
+ mappings = {
+ custom_only = false,
+ list = {},
+ },
+ float = {
+ enable = false,
+ quit_on_focus_loss = true,
+ open_win_config = {
+ relative = "editor",
+ border = "rounded",
+ width = 30,
+ height = 30,
+ row = 1,
+ col = 1,
+ },
+ },
+ },
+ renderer = {
+ add_trailing = false,
+ group_empty = false,
+ highlight_git = true,
+ full_name = false,
+ highlight_opened_files = "none",
+ root_folder_label = ":t",
+ indent_width = 2,
+ indent_markers = {
+ enable = false,
+ inline_arrows = true,
+ icons = {
+ corner = "â””",
+ edge = "│",
+ item = "│",
+ none = " ",
+ },
+ },
+ icons = {
+ webdev_colors = lvim.use_icons,
+ git_placement = "before",
+ padding = " ",
+ symlink_arrow = " âž› ",
+ show = {
+ file = lvim.use_icons,
+ folder = lvim.use_icons,
+ folder_arrow = lvim.use_icons,
+ git = lvim.use_icons,
+ },
+ glyphs = {
+ default = lvim.icons.ui.Text,
+ symlink = lvim.icons.ui.FileSymlink,
+ bookmark = lvim.icons.ui.BookMark,
+ folder = {
+ arrow_closed = lvim.icons.ui.TriangleShortArrowRight,
+ arrow_open = lvim.icons.ui.TriangleShortArrowDown,
+ default = lvim.icons.ui.Folder,
+ open = lvim.icons.ui.FolderOpen,
+ empty = lvim.icons.ui.EmptyFolder,
+ empty_open = lvim.icons.ui.EmptyFolderOpen,
+ symlink = lvim.icons.ui.FolderSymlink,
+ symlink_open = lvim.icons.ui.FolderOpen,
+ },
+ git = {
+ unstaged = lvim.icons.git.FileUnstaged,
+ staged = lvim.icons.git.FileStaged,
+ unmerged = lvim.icons.git.FileUnmerged,
+ renamed = lvim.icons.git.FileRenamed,
+ untracked = lvim.icons.git.FileUntracked,
+ deleted = lvim.icons.git.FileDeleted,
+ ignored = lvim.icons.git.FileIgnored,
+ },
+ },
+ },
+ special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
+ symlink_destination = true,
+ },
+ hijack_directories = {
+ enable = false,
+ auto_open = true,
+ },
+ update_focused_file = {
+ enable = true,
+ debounce_delay = 15,
+ update_root = true,
+ ignore_list = {},
+ },
+ diagnostics = {
+ enable = lvim.use_icons,
+ show_on_dirs = false,
+ show_on_open_dirs = true,
+ debounce_delay = 50,
+ severity = {
+ min = vim.diagnostic.severity.HINT,
+ max = vim.diagnostic.severity.ERROR,
+ },
+ icons = {
+ hint = lvim.icons.diagnostics.BoldHint,
+ info = lvim.icons.diagnostics.BoldInformation,
+ warning = lvim.icons.diagnostics.BoldWarning,
+ error = lvim.icons.diagnostics.BoldError,
+ },
+ },
+ filters = {
+ dotfiles = false,
+ git_clean = false,
+ no_buffer = false,
+ custom = { "node_modules", "\\.cache" },
+ exclude = {},
+ },
+ filesystem_watchers = {
+ enable = true,
+ debounce_delay = 50,
+ ignore_dirs = {},
+ },
+ git = {
+ enable = true,
+ ignore = false,
+ show_on_dirs = true,
+ show_on_open_dirs = true,
+ timeout = 200,
+ },
+ actions = {
+ use_system_clipboard = true,
+ change_dir = {
+ enable = true,
+ global = false,
+ restrict_above_cwd = false,
+ },
+ expand_all = {
+ max_folder_discovery = 300,
+ exclude = {},
+ },
+ file_popup = {
+ open_win_config = {
+ col = 1,
+ row = 1,
+ relative = "cursor",
+ border = "shadow",
+ style = "minimal",
+ },
+ },
+ open_file = {
+ quit_on_open = false,
+ resize_window = false,
+ window_picker = {
+ enable = true,
+ picker = "default",
+ chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
+ exclude = {
+ filetype = { "notify", "lazy", "qf", "diff", "fugitive", "fugitiveblame" },
+ buftype = { "nofile", "terminal", "help" },
+ },
+ },
+ },
+ remove_file = {
+ close_window = true,
+ },
+ },
+ trash = {
+ cmd = "trash",
+ require_confirm = true,
+ },
+ live_filter = {
+ prefix = "[FILTER]: ",
+ always_show_folders = true,
+ },
+ tab = {
+ sync = {
+ open = false,
+ close = false,
+ ignore = {},
+ },
+ },
+ notify = {
+ threshold = vim.log.levels.INFO,
+ },
+ log = {
+ enable = false,
+ truncate = false,
+ types = {
+ all = false,
+ config = false,
+ copy_paste = false,
+ dev = false,
+ diagnostics = false,
+ git = false,
+ profile = false,
+ watcher = false,
+ },
+ },
+ system_open = {
+ cmd = nil,
+ args = {},
+ },
+ },
+ }
+end
+
+function M.setup()
+ local status_ok, nvim_tree = pcall(require, "nvim-tree")
+ if not status_ok then
+ Log:error "Failed to load nvim-tree"
+ return
+ end
+
+ if lvim.builtin.nvimtree._setup_called then
+ Log:debug "ignoring repeated setup call for nvim-tree, see kyazdani42/nvim-tree.lua#1308"
+ return
+ end
+
+ lvim.builtin.nvimtree._setup_called = true
+
+ -- Implicitly update nvim-tree when project module is active
+ if lvim.builtin.project.active then
+ lvim.builtin.nvimtree.setup.respect_buf_cwd = true
+ lvim.builtin.nvimtree.setup.update_cwd = true
+ lvim.builtin.nvimtree.setup.update_focused_file = { enable = true, update_cwd = true }
+ end
+
+ local function telescope_find_files(_)
+ require("lvim.core.builtin.nvimtree").start_telescope "find_files"
+ end
+
+ local function telescope_live_grep(_)
+ require("lvim.core.builtin.nvimtree").start_telescope "live_grep"
+ end
+
+ -- Add useful keymaps
+ if #lvim.builtin.nvimtree.setup.view.mappings.list == 0 then
+ lvim.builtin.nvimtree.setup.view.mappings.list = {
+ { key = { "l", "<CR>", "o" }, action = "edit", mode = "n" },
+ { key = "h", action = "close_node" },
+ { key = "v", action = "vsplit" },
+ { key = "C", action = "cd" },
+ { key = "gtf", action = "telescope_find_files", action_cb = telescope_find_files },
+ { key = "gtg", action = "telescope_live_grep", action_cb = telescope_live_grep },
+ }
+ end
+
+ nvim_tree.setup(lvim.builtin.nvimtree.setup)
+
+ return nvim_tree
+end
+
+function M.start_telescope(telescope_mode)
+ local node = require("nvim-tree.lib").get_node_at_cursor()
+ local abspath = node.link_to or node.absolute_path
+ local is_folder = node.open ~= nil
+ local basedir = is_folder and abspath or vim.fn.fnamemodify(abspath, ":h")
+ require("telescope.builtin")[telescope_mode] {
+ cwd = basedir,
+ }
+end
+
+return M