nvimtree.lua 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. local M = {}
  2. local Log = require "lvim.core.log"
  3. function M.config()
  4. lvim.builtin.nvimtree = {
  5. active = true,
  6. on_config_done = nil,
  7. setup = {
  8. experimental = {},
  9. auto_reload_on_write = false,
  10. disable_netrw = false,
  11. hijack_cursor = false,
  12. hijack_netrw = true,
  13. hijack_unnamed_buffer_when_opening = false,
  14. sort = {
  15. sorter = "name",
  16. folders_first = true,
  17. files_first = false,
  18. },
  19. root_dirs = {},
  20. prefer_startup_root = false,
  21. sync_root_with_cwd = true,
  22. reload_on_bufenter = false,
  23. respect_buf_cwd = false,
  24. on_attach = "default",
  25. select_prompts = false,
  26. view = {
  27. adaptive_size = false,
  28. centralize_selection = true,
  29. width = 30,
  30. cursorline = true,
  31. debounce_delay = 15,
  32. side = "left",
  33. preserve_window_proportions = false,
  34. number = false,
  35. relativenumber = false,
  36. signcolumn = "yes",
  37. float = {
  38. enable = false,
  39. quit_on_focus_loss = true,
  40. open_win_config = {
  41. relative = "editor",
  42. border = "rounded",
  43. width = 30,
  44. height = 30,
  45. row = 1,
  46. col = 1,
  47. },
  48. },
  49. },
  50. renderer = {
  51. add_trailing = false,
  52. group_empty = false,
  53. highlight_git = "name",
  54. highlight_opened_files = "none",
  55. root_folder_label = ":t",
  56. full_name = false,
  57. indent_width = 2,
  58. special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
  59. symlink_destination = true,
  60. highlight_diagnostics = "none",
  61. highlight_modified = "none",
  62. highlight_bookmarks = "none",
  63. highlight_clipboard = "name",
  64. indent_markers = {
  65. enable = false,
  66. inline_arrows = true,
  67. icons = {
  68. corner = "└",
  69. edge = "│",
  70. item = "│",
  71. bottom = "─",
  72. none = " ",
  73. },
  74. },
  75. icons = {
  76. webdev_colors = lvim.use_icons,
  77. web_devicons = {
  78. file = {
  79. enable = lvim.use_icons,
  80. color = lvim.use_icons,
  81. },
  82. folder = {
  83. enable = false,
  84. color = lvim.use_icons,
  85. },
  86. },
  87. git_placement = "before",
  88. padding = " ",
  89. symlink_arrow = " ➛ ",
  90. modified_placement = "after",
  91. diagnostics_placement = "signcolumn",
  92. bookmarks_placement = "signcolumn",
  93. show = {
  94. file = lvim.use_icons,
  95. folder = lvim.use_icons,
  96. folder_arrow = lvim.use_icons,
  97. git = lvim.use_icons,
  98. modified = lvim.use_icons,
  99. diagnostics = lvim.use_icons,
  100. bookmarks = lvim.use_icons,
  101. },
  102. glyphs = {
  103. default = lvim.icons.ui.Text,
  104. symlink = lvim.icons.ui.FileSymlink,
  105. bookmark = lvim.icons.ui.BookMark,
  106. modified = lvim.icons.ui.Circle,
  107. folder = {
  108. arrow_closed = lvim.icons.ui.TriangleShortArrowRight,
  109. arrow_open = lvim.icons.ui.TriangleShortArrowDown,
  110. default = lvim.icons.ui.Folder,
  111. open = lvim.icons.ui.FolderOpen,
  112. empty = lvim.icons.ui.EmptyFolder,
  113. empty_open = lvim.icons.ui.EmptyFolderOpen,
  114. symlink = lvim.icons.ui.FolderSymlink,
  115. symlink_open = lvim.icons.ui.FolderOpen,
  116. },
  117. git = {
  118. unstaged = lvim.icons.git.FileUnstaged,
  119. staged = lvim.icons.git.FileStaged,
  120. unmerged = lvim.icons.git.FileUnmerged,
  121. renamed = lvim.icons.git.FileRenamed,
  122. untracked = lvim.icons.git.FileUntracked,
  123. deleted = lvim.icons.git.FileDeleted,
  124. ignored = lvim.icons.git.FileIgnored,
  125. },
  126. },
  127. },
  128. },
  129. hijack_directories = {
  130. enable = false,
  131. auto_open = true,
  132. },
  133. update_focused_file = {
  134. enable = true,
  135. update_root = {
  136. enable = true,
  137. ignore_list = {},
  138. },
  139. exclude = false,
  140. },
  141. diagnostics = {
  142. enable = lvim.use_icons,
  143. show_on_dirs = false,
  144. show_on_open_dirs = true,
  145. debounce_delay = 50,
  146. severity = {
  147. min = vim.diagnostic.severity.HINT,
  148. max = vim.diagnostic.severity.ERROR,
  149. },
  150. icons = {
  151. hint = lvim.icons.diagnostics.BoldHint,
  152. info = lvim.icons.diagnostics.BoldInformation,
  153. warning = lvim.icons.diagnostics.BoldWarning,
  154. error = lvim.icons.diagnostics.BoldError,
  155. },
  156. },
  157. filters = {
  158. enable = true,
  159. dotfiles = false,
  160. git_clean = false,
  161. git_ignored = false,
  162. no_bookmark = false,
  163. no_buffer = false,
  164. custom = { "node_modules", "\\.cache" },
  165. exclude = {},
  166. },
  167. filesystem_watchers = {
  168. enable = true,
  169. debounce_delay = 50,
  170. ignore_dirs = {},
  171. },
  172. git = {
  173. enable = true,
  174. show_on_dirs = true,
  175. show_on_open_dirs = true,
  176. disable_for_dirs = {},
  177. timeout = 400,
  178. cygwin_support = false,
  179. },
  180. actions = {
  181. use_system_clipboard = true,
  182. change_dir = {
  183. enable = true,
  184. global = false,
  185. restrict_above_cwd = false,
  186. },
  187. expand_all = {
  188. max_folder_discovery = 300,
  189. exclude = {},
  190. },
  191. file_popup = {
  192. open_win_config = {
  193. col = 1,
  194. row = 1,
  195. relative = "cursor",
  196. border = "shadow",
  197. style = "minimal",
  198. },
  199. },
  200. open_file = {
  201. quit_on_open = false,
  202. eject = true,
  203. resize_window = false,
  204. window_picker = {
  205. enable = true,
  206. picker = "default",
  207. chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
  208. exclude = {
  209. filetype = { "notify", "lazy", "qf", "diff", "fugitive", "fugitiveblame" },
  210. buftype = { "nofile", "terminal", "help" },
  211. },
  212. },
  213. },
  214. remove_file = {
  215. close_window = true,
  216. },
  217. },
  218. trash = {
  219. cmd = "gio trash",
  220. },
  221. live_filter = {
  222. prefix = "[FILTER]: ",
  223. always_show_folders = true,
  224. },
  225. tab = {
  226. sync = {
  227. open = false,
  228. close = false,
  229. ignore = {},
  230. },
  231. },
  232. notify = {
  233. threshold = vim.log.levels.INFO,
  234. absolute_path = true,
  235. },
  236. ui = {
  237. confirm = {
  238. remove = true,
  239. trash = true,
  240. default_yes = false,
  241. },
  242. },
  243. modified = {
  244. enable = false,
  245. show_on_dirs = true,
  246. show_on_open_dirs = true,
  247. },
  248. help = {
  249. sort_by = "key",
  250. },
  251. log = {
  252. enable = false,
  253. truncate = false,
  254. types = {
  255. all = false,
  256. config = false,
  257. copy_paste = false,
  258. dev = false,
  259. diagnostics = false,
  260. git = false,
  261. profile = false,
  262. watcher = false,
  263. },
  264. },
  265. system_open = {
  266. cmd = nil,
  267. args = {},
  268. },
  269. },
  270. }
  271. end
  272. function M.start_telescope(telescope_mode)
  273. local node = require("nvim-tree.lib").get_node_at_cursor()
  274. local abspath = node.link_to or node.absolute_path
  275. local is_folder = node.open ~= nil
  276. local basedir = is_folder and abspath or vim.fn.fnamemodify(abspath, ":h")
  277. require("telescope.builtin")[telescope_mode] {
  278. cwd = basedir,
  279. }
  280. end
  281. local function on_attach(bufnr)
  282. local api = require "nvim-tree.api"
  283. local function telescope_find_files(_)
  284. require("lvim.core.nvimtree").start_telescope "find_files"
  285. end
  286. local function telescope_live_grep(_)
  287. require("lvim.core.nvimtree").start_telescope "live_grep"
  288. end
  289. local function opts(desc)
  290. return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
  291. end
  292. api.config.mappings.default_on_attach(bufnr)
  293. local useful_keys = {
  294. ["l"] = { api.node.open.edit, opts "Open" },
  295. ["o"] = { api.node.open.edit, opts "Open" },
  296. ["<CR>"] = { api.node.open.edit, opts "Open" },
  297. ["v"] = { api.node.open.vertical, opts "Open: Vertical Split" },
  298. ["h"] = { api.node.navigate.parent_close, opts "Close Directory" },
  299. ["C"] = { api.tree.change_root_to_node, opts "CD" },
  300. ["gtg"] = { telescope_live_grep, opts "Telescope Live Grep" },
  301. ["gtf"] = { telescope_find_files, opts "Telescope Find File" },
  302. }
  303. require("lvim.keymappings").load_mode("n", useful_keys)
  304. end
  305. function M.setup()
  306. local status_ok, nvim_tree = pcall(require, "nvim-tree")
  307. if not status_ok then
  308. Log:error "Failed to load nvim-tree"
  309. return
  310. end
  311. -- Implicitly update nvim-tree when project module is active
  312. if lvim.builtin.project.active then
  313. lvim.builtin.nvimtree.setup.respect_buf_cwd = true
  314. lvim.builtin.nvimtree.setup.update_cwd = true
  315. lvim.builtin.nvimtree.setup.update_focused_file.enable = true
  316. lvim.builtin.nvimtree.setup.update_focused_file.update_cwd = true
  317. end
  318. -- Add useful keymaps
  319. if lvim.builtin.nvimtree.setup.on_attach == "default" then
  320. lvim.builtin.nvimtree.setup.on_attach = on_attach
  321. end
  322. nvim_tree.setup(lvim.builtin.nvimtree.setup)
  323. if lvim.builtin.nvimtree.on_config_done then
  324. lvim.builtin.nvimtree.on_config_done(nvim_tree)
  325. end
  326. end
  327. return M