Refacto: rewrite everything

- The tree is created with libuv functions, which makes it blazingly fast.
- The tree may now be faster than any other vim trees, it can handle directories with thousands of files without any latency at all (tested on 40K files, works flawlessly).
- More solid logic for opening and closing the tree.
- tree state is remembered (closing / opening a folder keeps opened subdirectories open)
- detection of multiple git projects in the tree
- more icon support
- smart rendering
- smart updates
- ms windows support
- gx replacement function running xdg-open on linux, open on macos
This commit is contained in:
kiyan42
2020-05-19 19:46:45 +02:00
parent afc86a9623
commit e0bfcb4a6f
18 changed files with 1169 additions and 1029 deletions

View File

@@ -1,57 +1,50 @@
local api = vim.api
local M = {}
local function get(var, fallback)
if api.nvim_call_function('exists', { var }) == 1 then
return api.nvim_get_var(var)
else
return fallback
function M.get_icon_state()
local show_icons = vim.g.lua_tree_show_icons or { git = 1, folders = 1, files = 1 }
local icons = {
default = nil,
git_icons = {
unstaged = "",
staged = "",
unmerged = "",
renamed = "",
untracked = ""
}
}
local user_icons = vim.g.lua_tree_icons
if user_icons then
if user_icons.default then
icons.default = user_icons.default
end
for key, val in pairs(user_icons.git) do
if icons.git_icons[key] then
icons.git_icons[key] = val
end
end
end
end
local function get_color_from_hl(hl_name, fallback)
local id = api.nvim_get_hl_id_by_name(hl_name)
if not id then return fallback end
local hl = api.nvim_get_hl_by_id(id, true)
if not hl or not hl.foreground then return fallback end
return hl.foreground
end
local HAS_DEV_ICONS = api.nvim_call_function('exists', { "*WebDevIconsGetFileTypeSymbol" }) == 1
local show_icons = get('lua_tree_show_icons', { git = 1, folders = 1, files = 1 })
M.SHOW_FILE_ICON = HAS_DEV_ICONS and show_icons.files == 1
M.SHOW_FOLDER_ICON = show_icons.folders == 1
M.SHOW_GIT_ICON = show_icons.git == 1
function M.get_colors()
return {
red = get('terminal_color_1', get_color_from_hl('Keyword', 'Red')),
green = get('terminal_color_2', get_color_from_hl('Character', 'Green')),
yellow = get('terminal_color_3', get_color_from_hl('PreProc', 'Yellow')),
blue = get('terminal_color_4', get_color_from_hl('Include', 'Blue')),
purple = get('terminal_color_5', get_color_from_hl('Define', 'Purple')),
cyan = get('terminal_color_6', get_color_from_hl('Conditional', 'Cyan')),
orange = get('terminal_color_11', get_color_from_hl('Number', 'Orange')),
dark_red = get('terminal_color_9', get_color_from_hl('Keyword', 'DarkRed')),
show_file_icon = show_icons.files == 1 and vim.g.nvim_web_devicons == 1,
show_folder_icon = show_icons.folders == 1,
show_git_icon = show_icons.git == 1,
icons = icons
}
end
local keybindings = get('lua_tree_bindings', {});
M.bindings = {
edit = keybindings.edit or '<CR>',
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
edit_split = keybindings.edit_split or '<C-x>',
edit_tab = keybindings.edit_tab or '<C-t>',
cd = keybindings.cd or '.',
create = keybindings.create or 'a',
remove = keybindings.remove or 'd',
rename = keybindings.rename or 'r',
}
function M.get_bindings()
local keybindings = vim.g.lua_tree_bindings or {}
return {
edit = keybindings.edit or '<CR>',
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
edit_split = keybindings.edit_split or '<C-x>',
edit_tab = keybindings.edit_tab or '<C-t>',
cd = keybindings.cd or '<C-]>',
create = keybindings.create or 'a',
remove = keybindings.remove or 'd',
rename = keybindings.rename or 'r',
}
end
return M