|
@@ -17,7 +17,7 @@ function M.config()
|
|
|
sync_root_with_cwd = true,
|
|
|
reload_on_bufenter = false,
|
|
|
respect_buf_cwd = false,
|
|
|
- on_attach = "disable",
|
|
|
+ on_attach = "default",
|
|
|
remove_keymaps = false,
|
|
|
select_prompts = false,
|
|
|
view = {
|
|
@@ -30,10 +30,6 @@ function M.config()
|
|
|
number = false,
|
|
|
relativenumber = false,
|
|
|
signcolumn = "yes",
|
|
|
- mappings = {
|
|
|
- custom_only = false,
|
|
|
- list = {},
|
|
|
- },
|
|
|
float = {
|
|
|
enable = false,
|
|
|
quit_on_focus_loss = true,
|
|
@@ -226,20 +222,51 @@ function M.config()
|
|
|
}
|
|
|
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
|
|
|
+
|
|
|
+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
|
|
|
+
|
|
|
+ api.config.mappings.default_on_attach(bufnr)
|
|
|
+
|
|
|
+ local useful_keys = {
|
|
|
+ ["l"] = api.node.open.edit,
|
|
|
+ ["o"] = api.node.open.edit,
|
|
|
+ ["<CR>"] = api.node.open.edit,
|
|
|
+ ["v"] = api.node.open.vertical,
|
|
|
+ ["h"] = api.node.navigate.parent_close,
|
|
|
+ ["C"] = api.tree.change_root_to_node,
|
|
|
+ ["gtg"] = telescope_live_grep,
|
|
|
+ ["gtf"] = telescope_find_files,
|
|
|
+ }
|
|
|
+
|
|
|
+ require("lvim.keymappings").load_mode("n", useful_keys)
|
|
|
+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
|
|
@@ -248,24 +275,9 @@ function M.setup()
|
|
|
lvim.builtin.nvimtree.setup.update_focused_file.update_cwd = true
|
|
|
end
|
|
|
|
|
|
- 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
|
|
|
-
|
|
|
-- 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 },
|
|
|
- }
|
|
|
+ if lvim.builtin.nvimtree.setup.on_attach == "default" then
|
|
|
+ lvim.builtin.nvimtree.setup.on_attach = on_attach
|
|
|
end
|
|
|
|
|
|
nvim_tree.setup(lvim.builtin.nvimtree.setup)
|
|
@@ -275,14 +287,4 @@ function M.setup()
|
|
|
end
|
|
|
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
|