2021-06-28 04:11:33 +02:00
|
|
|
local M = {}
|
2021-10-10 21:07:41 +02:00
|
|
|
local Log = require "lvim.core.log"
|
2021-08-20 09:31:18 +02:00
|
|
|
|
2021-08-22 20:03:19 +02:00
|
|
|
function M.config()
|
2021-07-25 03:17:11 +02:00
|
|
|
lvim.builtin.nvimtree = {
|
2021-08-17 17:20:18 +02:00
|
|
|
active = true,
|
2021-08-22 20:03:19 +02:00
|
|
|
on_config_done = nil,
|
2021-09-26 08:07:06 +02:00
|
|
|
setup = {
|
2022-10-03 02:56:23 +02:00
|
|
|
auto_reload_on_write = false,
|
2023-01-07 16:03:03 +01:00
|
|
|
disable_netrw = false,
|
|
|
|
hijack_cursor = false,
|
|
|
|
hijack_netrw = true,
|
|
|
|
hijack_unnamed_buffer_when_opening = false,
|
|
|
|
sort_by = "name",
|
|
|
|
root_dirs = {},
|
|
|
|
prefer_startup_root = false,
|
|
|
|
sync_root_with_cwd = true,
|
|
|
|
reload_on_bufenter = false,
|
|
|
|
respect_buf_cwd = false,
|
2023-04-28 02:34:19 +02:00
|
|
|
on_attach = "default",
|
2023-01-07 16:03:03 +01:00
|
|
|
select_prompts = false,
|
2021-09-26 18:36:34 +02:00
|
|
|
view = {
|
2023-01-07 16:03:03 +01:00
|
|
|
adaptive_size = false,
|
2023-05-17 10:18:56 +02:00
|
|
|
centralize_selection = true,
|
2021-09-26 18:36:34 +02:00
|
|
|
width = 30,
|
2022-01-15 13:09:58 +01:00
|
|
|
hide_root_folder = false,
|
2021-09-26 18:36:34 +02:00
|
|
|
side = "left",
|
2023-01-07 16:03:03 +01:00
|
|
|
preserve_window_proportions = false,
|
|
|
|
number = false,
|
|
|
|
relativenumber = false,
|
|
|
|
signcolumn = "yes",
|
|
|
|
float = {
|
|
|
|
enable = false,
|
|
|
|
quit_on_focus_loss = true,
|
|
|
|
open_win_config = {
|
|
|
|
relative = "editor",
|
|
|
|
border = "rounded",
|
|
|
|
width = 30,
|
|
|
|
height = 30,
|
|
|
|
row = 1,
|
|
|
|
col = 1,
|
|
|
|
},
|
|
|
|
},
|
2021-09-26 18:36:34 +02:00
|
|
|
},
|
2022-04-28 23:36:13 +02:00
|
|
|
renderer = {
|
2023-01-07 16:03:03 +01:00
|
|
|
add_trailing = false,
|
|
|
|
group_empty = false,
|
|
|
|
highlight_git = true,
|
|
|
|
full_name = false,
|
|
|
|
highlight_opened_files = "none",
|
|
|
|
root_folder_label = ":t",
|
|
|
|
indent_width = 2,
|
2022-04-28 23:36:13 +02:00
|
|
|
indent_markers = {
|
|
|
|
enable = false,
|
2023-01-07 16:03:03 +01:00
|
|
|
inline_arrows = true,
|
2022-04-28 23:36:13 +02:00
|
|
|
icons = {
|
2022-07-31 17:00:55 +02:00
|
|
|
corner = "└",
|
|
|
|
edge = "│",
|
|
|
|
item = "│",
|
|
|
|
none = " ",
|
2022-04-28 23:36:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
icons = {
|
|
|
|
webdev_colors = lvim.use_icons,
|
2023-01-07 16:03:03 +01:00
|
|
|
git_placement = "before",
|
|
|
|
padding = " ",
|
|
|
|
symlink_arrow = " ➛ ",
|
2022-05-31 17:15:43 +02:00
|
|
|
show = {
|
|
|
|
file = lvim.use_icons,
|
2023-01-07 16:03:03 +01:00
|
|
|
folder = lvim.use_icons,
|
2022-05-31 17:15:43 +02:00
|
|
|
folder_arrow = lvim.use_icons,
|
2023-01-07 16:03:03 +01:00
|
|
|
git = lvim.use_icons,
|
2022-05-31 17:15:43 +02:00
|
|
|
},
|
|
|
|
glyphs = {
|
2022-10-03 05:48:23 +02:00
|
|
|
default = lvim.icons.ui.Text,
|
|
|
|
symlink = lvim.icons.ui.FileSymlink,
|
2023-01-07 16:03:03 +01:00
|
|
|
bookmark = lvim.icons.ui.BookMark,
|
2022-05-31 17:15:43 +02:00
|
|
|
folder = {
|
2023-01-07 16:03:03 +01:00
|
|
|
arrow_closed = lvim.icons.ui.TriangleShortArrowRight,
|
|
|
|
arrow_open = lvim.icons.ui.TriangleShortArrowDown,
|
2022-10-03 05:48:23 +02:00
|
|
|
default = lvim.icons.ui.Folder,
|
2023-01-07 16:03:03 +01:00
|
|
|
open = lvim.icons.ui.FolderOpen,
|
2022-10-03 05:48:23 +02:00
|
|
|
empty = lvim.icons.ui.EmptyFolder,
|
|
|
|
empty_open = lvim.icons.ui.EmptyFolderOpen,
|
|
|
|
symlink = lvim.icons.ui.FolderSymlink,
|
2023-01-07 16:03:03 +01:00
|
|
|
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,
|
2022-05-31 17:15:43 +02:00
|
|
|
},
|
|
|
|
},
|
2022-04-28 23:36:13 +02:00
|
|
|
},
|
2023-01-07 16:03:03 +01:00
|
|
|
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,
|
|
|
|
},
|
2022-04-28 23:36:13 +02:00
|
|
|
},
|
2021-11-29 09:12:13 +01:00
|
|
|
filters = {
|
|
|
|
dotfiles = false,
|
2023-01-07 16:03:03 +01:00
|
|
|
git_clean = false,
|
|
|
|
no_buffer = false,
|
2022-04-21 23:17:24 +02:00
|
|
|
custom = { "node_modules", "\\.cache" },
|
2022-04-28 23:36:13 +02:00
|
|
|
exclude = {},
|
2022-01-15 13:09:58 +01:00
|
|
|
},
|
2023-01-07 16:03:03 +01:00
|
|
|
filesystem_watchers = {
|
|
|
|
enable = true,
|
|
|
|
debounce_delay = 50,
|
|
|
|
ignore_dirs = {},
|
2021-11-29 09:12:13 +01:00
|
|
|
},
|
2023-01-07 16:03:03 +01:00
|
|
|
git = {
|
|
|
|
enable = true,
|
|
|
|
ignore = false,
|
|
|
|
show_on_dirs = true,
|
|
|
|
show_on_open_dirs = true,
|
|
|
|
timeout = 200,
|
2022-04-28 23:36:13 +02:00
|
|
|
},
|
2022-02-23 11:59:09 +01:00
|
|
|
actions = {
|
2022-04-28 23:36:13 +02:00
|
|
|
use_system_clipboard = true,
|
2022-02-23 11:59:09 +01:00
|
|
|
change_dir = {
|
2022-04-28 23:36:13 +02:00
|
|
|
enable = true,
|
2022-02-23 11:59:09 +01:00
|
|
|
global = false,
|
2022-04-28 23:36:13 +02:00
|
|
|
restrict_above_cwd = false,
|
2022-02-23 11:59:09 +01:00
|
|
|
},
|
2023-01-07 16:03:03 +01:00
|
|
|
expand_all = {
|
|
|
|
max_folder_discovery = 300,
|
|
|
|
exclude = {},
|
|
|
|
},
|
|
|
|
file_popup = {
|
|
|
|
open_win_config = {
|
|
|
|
col = 1,
|
|
|
|
row = 1,
|
|
|
|
relative = "cursor",
|
|
|
|
border = "shadow",
|
|
|
|
style = "minimal",
|
|
|
|
},
|
|
|
|
},
|
2022-02-23 11:59:09 +01:00
|
|
|
open_file = {
|
|
|
|
quit_on_open = false,
|
2022-04-28 23:36:13 +02:00
|
|
|
resize_window = false,
|
|
|
|
window_picker = {
|
|
|
|
enable = true,
|
2023-01-07 16:03:03 +01:00
|
|
|
picker = "default",
|
2022-04-28 23:36:13 +02:00
|
|
|
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
|
|
|
|
exclude = {
|
2023-01-10 21:18:17 +01:00
|
|
|
filetype = { "notify", "lazy", "qf", "diff", "fugitive", "fugitiveblame" },
|
2022-04-28 23:36:13 +02:00
|
|
|
buftype = { "nofile", "terminal", "help" },
|
|
|
|
},
|
|
|
|
},
|
2022-02-23 11:59:09 +01:00
|
|
|
},
|
2023-01-07 16:03:03 +01:00
|
|
|
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 = {},
|
2022-02-23 11:59:09 +01:00
|
|
|
},
|
2021-09-26 08:07:06 +02:00
|
|
|
},
|
2021-07-17 08:42:55 +02:00
|
|
|
}
|
|
|
|
end
|
2021-08-20 09:31:18 +02:00
|
|
|
|
2023-04-28 02:34:19 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
local function on_attach(bufnr)
|
|
|
|
local api = require "nvim-tree.api"
|
|
|
|
|
|
|
|
local function telescope_find_files(_)
|
|
|
|
require("lvim.core.nvimtree").start_telescope "find_files"
|
|
|
|
end
|
|
|
|
|
|
|
|
local function telescope_live_grep(_)
|
|
|
|
require("lvim.core.nvimtree").start_telescope "live_grep"
|
|
|
|
end
|
|
|
|
|
2023-04-28 11:20:01 +02:00
|
|
|
local function opts(desc)
|
|
|
|
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
|
|
|
|
end
|
|
|
|
|
2023-04-28 02:34:19 +02:00
|
|
|
api.config.mappings.default_on_attach(bufnr)
|
|
|
|
|
|
|
|
local useful_keys = {
|
2023-04-28 11:20:01 +02:00
|
|
|
["l"] = { api.node.open.edit, opts "Open" },
|
|
|
|
["o"] = { api.node.open.edit, opts "Open" },
|
|
|
|
["<CR>"] = { api.node.open.edit, opts "Open" },
|
|
|
|
["v"] = { api.node.open.vertical, opts "Open: Vertical Split" },
|
|
|
|
["h"] = { api.node.navigate.parent_close, opts "Close Directory" },
|
|
|
|
["C"] = { api.tree.change_root_to_node, opts "CD" },
|
|
|
|
["gtg"] = { telescope_live_grep, opts "Telescope Live Grep" },
|
|
|
|
["gtf"] = { telescope_find_files, opts "Telescope Find File" },
|
2023-04-28 02:34:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
require("lvim.keymappings").load_mode("n", useful_keys)
|
|
|
|
end
|
|
|
|
|
2021-08-22 20:03:19 +02:00
|
|
|
function M.setup()
|
2022-04-23 13:53:16 +02:00
|
|
|
local status_ok, nvim_tree = pcall(require, "nvim-tree")
|
2023-04-28 02:34:19 +02:00
|
|
|
|
2021-07-18 13:27:06 +02:00
|
|
|
if not status_ok then
|
2022-04-23 13:53:16 +02:00
|
|
|
Log:error "Failed to load nvim-tree"
|
2021-07-18 13:27:06 +02:00
|
|
|
return
|
|
|
|
end
|
2021-04-15 06:17:48 +02:00
|
|
|
|
2021-08-18 07:34:26 +02:00
|
|
|
-- Implicitly update nvim-tree when project module is active
|
|
|
|
if lvim.builtin.project.active then
|
2022-05-31 17:15:43 +02:00
|
|
|
lvim.builtin.nvimtree.setup.respect_buf_cwd = true
|
2021-10-10 09:59:01 +02:00
|
|
|
lvim.builtin.nvimtree.setup.update_cwd = true
|
2023-03-28 08:39:11 +02:00
|
|
|
lvim.builtin.nvimtree.setup.update_focused_file.enable = true
|
|
|
|
lvim.builtin.nvimtree.setup.update_focused_file.update_cwd = true
|
2022-02-23 11:59:09 +01:00
|
|
|
end
|
|
|
|
|
2021-12-03 18:57:43 +01:00
|
|
|
-- Add useful keymaps
|
2023-04-28 02:34:19 +02:00
|
|
|
if lvim.builtin.nvimtree.setup.on_attach == "default" then
|
|
|
|
lvim.builtin.nvimtree.setup.on_attach = on_attach
|
2021-08-03 07:43:57 +02:00
|
|
|
end
|
2021-08-03 06:54:57 +02:00
|
|
|
|
2022-04-23 13:53:16 +02:00
|
|
|
nvim_tree.setup(lvim.builtin.nvimtree.setup)
|
|
|
|
|
2022-01-15 13:09:58 +01:00
|
|
|
if lvim.builtin.nvimtree.on_config_done then
|
2022-04-23 13:53:16 +02:00
|
|
|
lvim.builtin.nvimtree.on_config_done(nvim_tree)
|
2021-08-03 18:10:54 +02:00
|
|
|
end
|
|
|
|
end
|
2021-08-20 09:31:18 +02:00
|
|
|
|
2021-06-28 04:11:33 +02:00
|
|
|
return M
|