Skip to content

Commit 6c04bf3

Browse files
committed
Rewrite: rewrite the whole api
- The tree is created asynchronously - More solid logic for opening and closing the tree - smart rendering - smart updates
1 parent e1fbabf commit 6c04bf3

File tree

15 files changed

+888
-1008
lines changed

15 files changed

+888
-1008
lines changed

lua/lib/colors.lua

Lines changed: 209 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
local api = vim.api
2-
local get_colors = require 'lib/config'.get_colors
3-
4-
local colors = get_colors()
52

63
local M = {}
74

8-
local function create_hl()
5+
local function get_color_from_hl(hl_name, fallback)
6+
local id = vim.api.nvim_get_hl_id_by_name(hl_name)
7+
if not id then return fallback end
8+
9+
local hl = vim.api.nvim_get_hl_by_id(id, true)
10+
if not hl or not hl.foreground then return fallback end
11+
12+
return hl.foreground
13+
end
14+
15+
local function get_colors()
16+
return {
17+
red = vim.g.terminal_color_1 or get_color_from_hl('Keyword', 'Red'),
18+
green = vim.g.terminal_color_2 or get_color_from_hl('Character', 'Green'),
19+
yellow = vim.g.terminal_color_3 or get_color_from_hl('PreProc', 'Yellow'),
20+
blue = vim.g.terminal_color_4 or get_color_from_hl('Include', 'Blue'),
21+
purple = vim.g.terminal_color_5 or get_color_from_hl('Define', 'Purple'),
22+
cyan = vim.g.terminal_color_6 or get_color_from_hl('Conditional', 'Cyan'),
23+
dark_red = vim.g.terminal_color_9 or get_color_from_hl('Keyword', 'DarkRed'),
24+
orange = vim.g.terminal_color_11 or get_color_from_hl('Number', 'Orange'),
25+
}
26+
end
27+
28+
local function get_hl_groups()
29+
local colors = get_colors()
30+
931
return {
1032
Symlink = { gui = 'bold', fg = colors.cyan },
1133
FolderName = { gui = 'bold', fg = colors.blue },
@@ -22,6 +44,7 @@ local function create_hl()
2244
JsonIcon = { fg = colors.yellow },
2345

2446
LuaIcon = { fg = '#42a5f5' },
47+
GoIcon = { fg = '#7Fd5EA' },
2548
PythonIcon = { fg = colors.green },
2649
ShellIcon = { fg = colors.green },
2750
JavascriptIcon = { fg = colors.yellow },
@@ -40,25 +63,195 @@ local function create_hl()
4063
}
4164
end
4265

43-
local HIGHLIGHTS = create_hl()
66+
M.hl_groups = {
67+
['LICENSE'] = 'LicenseIcon';
68+
['license'] = 'LicenseIcon';
69+
['vim'] = 'VimIcon';
70+
['.vimrc'] = 'VimIcon';
71+
['c'] = 'CIcon';
72+
['cpp'] = 'CIcon';
73+
['python'] = 'PythonIcon';
74+
['lua'] = 'LuaIcon';
75+
['rs'] = 'RustIcon';
76+
['sh'] = 'ShellIcon';
77+
['csh'] = 'ShellIcon';
78+
['zsh'] = 'ShellIcon';
79+
['bash'] = 'ShellIcon';
80+
['md'] = 'MarkdownIcon';
81+
['json'] = 'JsonIcon';
82+
['toml'] = 'TomlIcon';
83+
['go'] = 'GoIcon';
84+
['yaml'] = 'YamlIcon';
85+
['yml'] = 'YamlIcon';
86+
['conf'] = 'GitignoreIcon';
87+
['javascript'] = 'JavascriptIcon';
88+
['typescript'] = 'TypescriptIcon';
89+
['jsx'] = 'ReactIcon';
90+
['tsx'] = 'ReactIcon';
91+
['htm'] = 'HtmlIcon';
92+
['html'] = 'HtmlIcon';
93+
['slim'] = 'HtmlIcon';
94+
['haml'] = 'HtmlIcon';
95+
['ejs'] = 'HtmlIcon';
4496

45-
local LINKS = {
46-
Normal = 'Normal',
47-
EndOfBuffer = 'EndOfBuffer',
48-
CursorLine = 'CursorLine',
49-
VertSplit = 'VertSplit',
50-
CursorColumn = 'CursorColumn'
97+
['Gemfile$'] = 'RubyIcon';
98+
['Vagrantfile$'] = 'VagrantIcon';
99+
-- ['styl'] = '';
100+
-- ['sass'] = '';
101+
-- ['scss'] = '';
102+
--
103+
-- ['css'] = '';
104+
-- ['less'] = '';
105+
-- ['md'] = '';
106+
-- ['mdx'] = '';
107+
-- ['markdown'] = '';
108+
-- ['rmd'] = '';
109+
-- ['json'] = '';
110+
-- ['webmanifest'] = '';
111+
-- ['js'] = '';
112+
-- ['mjs'] = '';
113+
-- ['jsx'] = '';
114+
-- ['rb'] = '';
115+
-- ['gemspec'] = '';
116+
-- ['rake'] = '';
117+
-- ['php'] = '';
118+
-- ['py'] = '';
119+
-- ['pyc'] = '';
120+
-- ['pyo'] = '';
121+
-- ['pyd'] = '';
122+
-- ['coffee'] = '';
123+
-- ['mustache'] = '';
124+
-- ['hbs'] = '';
125+
-- ['conf'] = '';
126+
-- ['ini'] = '';
127+
-- ['yml'] = '';
128+
-- ['yaml'] = '';
129+
-- ['toml'] = '';
130+
-- ['bat'] = '';
131+
-- ['jpg'] = '';
132+
-- ['jpeg'] = '';
133+
-- ['bmp'] = '';
134+
-- ['png'] = '';
135+
-- ['webp'] = '';
136+
-- ['gif'] = '';
137+
-- ['ico'] = '';
138+
-- ['twig'] = '';
139+
-- ['cpp'] = '';
140+
-- ['c++'] = '';
141+
-- ['cxx'] = '';
142+
-- ['cc'] = '';
143+
-- ['cp'] = '';
144+
-- ['c'] = '';
145+
-- ['cs'] = '';
146+
-- ['h'] = '';
147+
-- ['hh'] = '';
148+
-- ['hpp'] = '';
149+
-- ['hxx'] = '';
150+
-- ['hs'] = '';
151+
-- ['lhs'] = '';
152+
-- ['lua'] = '';
153+
-- ['java'] = '';
154+
-- ['sh'] = '';
155+
-- ['fish'] = '';
156+
-- ['bash'] = '';
157+
-- ['zsh'] = '';
158+
-- ['ksh'] = '';
159+
-- ['csh'] = '';
160+
-- ['awk'] = '';
161+
-- ['ps1'] = '';
162+
-- ['ml'] = 'λ';
163+
-- ['mli'] = 'λ';
164+
-- ['diff'] = '';
165+
-- ['db'] = '';
166+
-- ['sql'] = '';
167+
-- ['dump'] = '';
168+
-- ['clj'] = '';
169+
-- ['cljc'] = '';
170+
-- ['cljs'] = '';
171+
-- ['edn'] = '';
172+
-- ['scala'] = '';
173+
-- ['go'] = '';
174+
-- ['dart'] = '';
175+
-- ['xul'] = '';
176+
-- ['sln'] = '';
177+
-- ['suo'] = '';
178+
-- ['pl'] = '';
179+
-- ['pm'] = '';
180+
-- ['t'] = '';
181+
-- ['rss'] = '';
182+
-- ['f#'] = '';
183+
-- ['fsscript'] = '';
184+
-- ['fsx'] = '';
185+
-- ['fs'] = '';
186+
-- ['fsi'] = '';
187+
-- ['rs'] = '';
188+
-- ['rlib'] = '';
189+
-- ['d'] = '';
190+
-- ['erl'] = '';
191+
-- ['hrl'] = '';
192+
-- ['ex'] = '';
193+
-- ['exs'] = '';
194+
-- ['eex'] = '';
195+
-- ['leex'] = '';
196+
-- ['vim'] = '';
197+
-- ['ai'] = '';
198+
-- ['psd'] = '';
199+
-- ['psb'] = '';
200+
-- ['ts'] = '';
201+
-- ['jl'] = '';
202+
-- ['pp'] = '';
203+
-- ['vue'] = '﵂';
204+
-- ['elm'] = '';
205+
-- ['swift'] = '';
206+
-- ['xcplayground'] = '';
207+
-- ['tex'] = 'ﭨ';
208+
-- ['r'] = 'ﳒ';
209+
-- ['rproj'] = '鉶';
210+
-- ['mix.lock'] = '';
211+
-- ['dropbox'] = '';
212+
-- ['.ds_store'] = '';
213+
-- ['.gitconfig'] = '';
214+
-- ['.gitignore'] = '';
215+
-- ['.gitlab-ci.yml'] = '';
216+
-- ['.bashrc'] = '';
217+
-- ['.zshrc'] = '';
218+
-- ['.vimrc'] = '';
219+
-- ['.gvimrc'] = '';
220+
-- ['_vimrc'] = '';
221+
-- ['_gvimrc'] = '';
222+
-- ['.bashprofile'] = '';
223+
-- ['favicon.ico'] = '';
224+
-- ['license'] = '';
225+
-- ['LICENSE'] = '';
226+
-- ['node_modules'] = '';
227+
-- ['procfile'] = '';
228+
-- ['dockerfile'] = '';
229+
-- ['docker-compose.yml'] = '';
230+
-- ['rakefile'] = '';
231+
-- ['config.ru'] = '';
232+
-- ['makefile'] = '';
233+
-- ['cmakelists.txt'] = '';
51234
}
52235

53-
function M.init_colors()
54-
colors = get_colors()
55-
HIGHLIGHTS = create_hl()
56-
for k, d in pairs(HIGHLIGHTS) do
236+
local function get_links()
237+
return {
238+
Normal = 'Normal',
239+
EndOfBuffer = 'EndOfBuffer',
240+
CursorLine = 'CursorLine',
241+
VertSplit = 'VertSplit',
242+
CursorColumn = 'CursorColumn'
243+
}
244+
end
245+
246+
function M.setup()
247+
local higlight_groups = get_hl_groups()
248+
for k, d in pairs(higlight_groups) do
57249
local gui = d.gui or 'NONE'
58250
api.nvim_command('hi def LuaTree'..k..' gui='..gui..' guifg='..d.fg)
59251
end
60252

61-
for k, d in pairs(LINKS) do
253+
local links = get_links()
254+
for k, d in pairs(links) do
62255
api.nvim_command('hi def link LuaTree'..k..' '..d)
63256
end
64257
end

lua/lib/config.lua

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,27 @@
1-
local api = vim.api
2-
31
local M = {}
42

5-
local function get(var, fallback)
6-
if api.nvim_call_function('exists', { var }) == 1 then
7-
return api.nvim_get_var(var)
8-
else
9-
return fallback
10-
end
11-
end
12-
13-
local function get_color_from_hl(hl_name, fallback)
14-
local id = api.nvim_get_hl_id_by_name(hl_name)
15-
if not id then return fallback end
3+
function M.get_icon_state()
4+
local show_icons = vim.g.lua_tree_show_icons or { git = 1, folders = 1, files = 1 }
165

17-
local hl = api.nvim_get_hl_by_id(id, true)
18-
if not hl or not hl.foreground then return fallback end
19-
20-
return hl.foreground
6+
return {
7+
show_file_icon = show_icons.files == 1,
8+
show_folder_icon = show_icons.folders == 1,
9+
show_git_icon = show_icons.git == 1
10+
}
2111
end
2212

23-
local HAS_DEV_ICONS = api.nvim_call_function('exists', { "*WebDevIconsGetFileTypeSymbol" }) == 1
24-
25-
local show_icons = get('lua_tree_show_icons', { git = 1, folders = 1, files = 1 })
26-
27-
M.SHOW_FILE_ICON = HAS_DEV_ICONS and show_icons.files == 1
28-
M.SHOW_FOLDER_ICON = show_icons.folders == 1
29-
M.SHOW_GIT_ICON = show_icons.git == 1
30-
31-
function M.get_colors()
13+
function M.get_bindings()
14+
local keybindings = vim.g.lua_tree_bindings or {}
3215
return {
33-
red = get('terminal_color_1', get_color_from_hl('Keyword', 'Red')),
34-
green = get('terminal_color_2', get_color_from_hl('Character', 'Green')),
35-
yellow = get('terminal_color_3', get_color_from_hl('PreProc', 'Yellow')),
36-
blue = get('terminal_color_4', get_color_from_hl('Include', 'Blue')),
37-
purple = get('terminal_color_5', get_color_from_hl('Define', 'Purple')),
38-
cyan = get('terminal_color_6', get_color_from_hl('Conditional', 'Cyan')),
39-
orange = get('terminal_color_11', get_color_from_hl('Number', 'Orange')),
40-
dark_red = get('terminal_color_9', get_color_from_hl('Keyword', 'DarkRed')),
16+
edit = keybindings.edit or '<CR>',
17+
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
18+
edit_split = keybindings.edit_split or '<C-x>',
19+
edit_tab = keybindings.edit_tab or '<C-t>',
20+
cd = keybindings.cd or '<C-]>',
21+
create = keybindings.create or 'a',
22+
remove = keybindings.remove or 'd',
23+
rename = keybindings.rename or 'r',
4124
}
4225
end
4326

44-
local keybindings = get('lua_tree_bindings', {});
45-
46-
M.bindings = {
47-
edit = keybindings.edit or '<CR>',
48-
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
49-
edit_split = keybindings.edit_split or '<C-x>',
50-
edit_tab = keybindings.edit_tab or '<C-t>',
51-
cd = keybindings.cd or '.',
52-
create = keybindings.create or 'a',
53-
remove = keybindings.remove or 'd',
54-
rename = keybindings.rename or 'r',
55-
}
56-
5727
return M

0 commit comments

Comments
 (0)