nvimtree.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. auto_reload_on_write = false,
  9. disable_netrw = false,
  10. hijack_cursor = false,
  11. hijack_netrw = true,
  12. hijack_unnamed_buffer_when_opening = false,
  13. sort_by = "name",
  14. root_dirs = {},
  15. prefer_startup_root = false,
  16. sync_root_with_cwd = true,
  17. reload_on_bufenter = false,
  18. respect_buf_cwd = false,
  19. on_attach = "disable",
  20. remove_keymaps = false,
  21. select_prompts = false,
  22. view = {
  23. adaptive_size = false,
  24. centralize_selection = false,
  25. width = 30,
  26. hide_root_folder = false,
  27. side = "left",
  28. preserve_window_proportions = false,
  29. number = false,
  30. relativenumber = false,
  31. signcolumn = "yes",
  32. mappings = {
  33. custom_only = false,
  34. list = {},
  35. },
  36. float = {
  37. enable = false,
  38. quit_on_focus_loss = true,
  39. open_win_config = {
  40. relative = "editor",
  41. border = "rounded",
  42. width = 30,
  43. height = 30,
  44. row = 1,
  45. col = 1,
  46. },
  47. },
  48. },
  49. renderer = {
  50. add_trailing = false,
  51. group_empty = false,
  52. highlight_git = true,
  53. full_name = false,
  54. highlight_opened_files = "none",
  55. root_folder_label = ":t",
  56. indent_width = 2,
  57. indent_markers = {
  58. enable = false,
  59. inline_arrows = true,
  60. icons = {
  61. corner = "└",
  62. edge = "│",
  63. item = "│",
  64. none = " ",
  65. },
  66. },
  67. icons = {
  68. webdev_colors = lvim.use_icons,
  69. git_placement = "before",
  70. padding = " ",
  71. symlink_arrow = " ➛ ",
  72. show = {
  73. file = lvim.use_icons,
  74. folder = lvim.use_icons,
  75. folder_arrow = lvim.use_icons,
  76. git = lvim.use_icons,
  77. },
  78. glyphs = {
  79. default = lvim.icons.ui.Text,
  80. symlink = lvim.icons.ui.FileSymlink,
  81. bookmark = lvim.icons.ui.BookMark,
  82. folder = {
  83. arrow_closed = lvim.icons.ui.TriangleShortArrowRight,
  84. arrow_open = lvim.icons.ui.TriangleShortArrowDown,
  85. default = lvim.icons.ui.Folder,
  86. open = lvim.icons.ui.FolderOpen,
  87. empty = lvim.icons.ui.EmptyFolder,
  88. empty_open = lvim.icons.ui.EmptyFolderOpen,
  89. symlink = lvim.icons.ui.FolderSymlink,
  90. symlink_open = lvim.icons.ui.FolderOpen,
  91. },
  92. git = {
  93. unstaged = lvim.icons.git.FileUnstaged,
  94. staged = lvim.icons.git.FileStaged,
  95. unmerged = lvim.icons.git.FileUnmerged,
  96. renamed = lvim.icons.git.FileRenamed,
  97. untracked = lvim.icons.git.FileUntracked,
  98. deleted = lvim.icons.git.FileDeleted,
  99. ignored = lvim.icons.git.FileIgnored,
  100. },
  101. },
  102. },
  103. special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
  104. symlink_destination = true,
  105. },
  106. hijack_directories = {
  107. enable = false,
  108. auto_open = true,
  109. },
  110. update_focused_file = {
  111. enable = true,
  112. debounce_delay = 15,
  113. update_root = true,
  114. ignore_list = {},
  115. },
  116. diagnostics = {
  117. enable = lvim.use_icons,
  118. show_on_dirs = false,
  119. show_on_open_dirs = true,
  120. debounce_delay = 50,
  121. severity = {
  122. min = vim.diagnostic.severity.HINT,
  123. max = vim.diagnostic.severity.ERROR,
  124. },
  125. icons = {
  126. hint = lvim.icons.diagnostics.BoldHint,
  127. info = lvim.icons.diagnostics.BoldInformation,
  128. warning = lvim.icons.diagnostics.BoldWarning,
  129. error = lvim.icons.diagnostics.BoldError,
  130. },
  131. },
  132. filters = {
  133. dotfiles = false,
  134. git_clean = false,
  135. no_buffer = false,
  136. custom = { "node_modules", "\\.cache" },
  137. exclude = {},
  138. },
  139. filesystem_watchers = {
  140. enable = true,
  141. debounce_delay = 50,
  142. ignore_dirs = {},
  143. },
  144. git = {
  145. enable = true,
  146. ignore = false,
  147. show_on_dirs = true,
  148. show_on_open_dirs = true,
  149. timeout = 200,
  150. },
  151. actions = {
  152. use_system_clipboard = true,
  153. change_dir = {
  154. enable = true,
  155. global = false,
  156. restrict_above_cwd = false,
  157. },
  158. expand_all = {
  159. max_folder_discovery = 300,
  160. exclude = {},
  161. },
  162. file_popup = {
  163. open_win_config = {
  164. col = 1,
  165. row = 1,
  166. relative = "cursor",
  167. border = "shadow",
  168. style = "minimal",
  169. },
  170. },
  171. open_file = {
  172. quit_on_open = false,
  173. resize_window = false,
  174. window_picker = {
  175. enable = true,
  176. picker = "default",
  177. chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
  178. exclude = {
  179. filetype = { "notify", "lazy", "qf", "diff", "fugitive", "fugitiveblame" },
  180. buftype = { "nofile", "terminal", "help" },
  181. },
  182. },
  183. },
  184. remove_file = {
  185. close_window = true,
  186. },
  187. },
  188. trash = {
  189. cmd = "trash",
  190. require_confirm = true,
  191. },
  192. live_filter = {
  193. prefix = "[FILTER]: ",
  194. always_show_folders = true,
  195. },
  196. tab = {
  197. sync = {
  198. open = false,
  199. close = false,
  200. ignore = {},
  201. },
  202. },
  203. notify = {
  204. threshold = vim.log.levels.INFO,
  205. },
  206. log = {
  207. enable = false,
  208. truncate = false,
  209. types = {
  210. all = false,
  211. config = false,
  212. copy_paste = false,
  213. dev = false,
  214. diagnostics = false,
  215. git = false,
  216. profile = false,
  217. watcher = false,
  218. },
  219. },
  220. system_open = {
  221. cmd = nil,
  222. args = {},
  223. },
  224. },
  225. }
  226. end
  227. function M.setup()
  228. local status_ok, nvim_tree = pcall(require, "nvim-tree")
  229. if not status_ok then
  230. Log:error "Failed to load nvim-tree"
  231. return
  232. end
  233. if lvim.builtin.nvimtree._setup_called then
  234. Log:debug "ignoring repeated setup call for nvim-tree, see kyazdani42/nvim-tree.lua#1308"
  235. return
  236. end
  237. lvim.builtin.nvimtree._setup_called = true
  238. -- Implicitly update nvim-tree when project module is active
  239. if lvim.builtin.project.active then
  240. lvim.builtin.nvimtree.setup.respect_buf_cwd = true
  241. lvim.builtin.nvimtree.setup.update_cwd = true
  242. lvim.builtin.nvimtree.setup.update_focused_file.enable = true
  243. lvim.builtin.nvimtree.setup.update_focused_file.update_cwd = true
  244. end
  245. local function telescope_find_files(_)
  246. require("lvim.core.nvimtree").start_telescope "find_files"
  247. end
  248. local function telescope_live_grep(_)
  249. require("lvim.core.nvimtree").start_telescope "live_grep"
  250. end
  251. -- Add useful keymaps
  252. if #lvim.builtin.nvimtree.setup.view.mappings.list == 0 then
  253. lvim.builtin.nvimtree.setup.view.mappings.list = {
  254. { key = { "l", "<CR>", "o" }, action = "edit", mode = "n" },
  255. { key = "h", action = "close_node" },
  256. { key = "v", action = "vsplit" },
  257. { key = "C", action = "cd" },
  258. { key = "gtf", action = "telescope_find_files", action_cb = telescope_find_files },
  259. { key = "gtg", action = "telescope_live_grep", action_cb = telescope_live_grep },
  260. }
  261. end
  262. nvim_tree.setup(lvim.builtin.nvimtree.setup)
  263. if lvim.builtin.nvimtree.on_config_done then
  264. lvim.builtin.nvimtree.on_config_done(nvim_tree)
  265. end
  266. end
  267. function M.start_telescope(telescope_mode)
  268. local node = require("nvim-tree.lib").get_node_at_cursor()
  269. local abspath = node.link_to or node.absolute_path
  270. local is_folder = node.open ~= nil
  271. local basedir = is_folder and abspath or vim.fn.fnamemodify(abspath, ":h")
  272. require("telescope.builtin")[telescope_mode] {
  273. cwd = basedir,
  274. }
  275. end
  276. return M