Skip to content

Commit 5ba3e6b

Browse files
committed
feat/chore: rewrite git with job and some other fixes
1 parent a6c1d45 commit 5ba3e6b

File tree

14 files changed

+432
-341
lines changed

14 files changed

+432
-341
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Install with [packer](https://github.com/wbthomason/packer.nvim):
2323
```lua
2424
use {
2525
'kyazdani42/nvim-tree.lua',
26-
requires = 'kyazdani42/nvim-web-devicons',
26+
requires = {
27+
'kyazdani42/nvim-web-devicons', -- optional, for file icon
28+
},
2729
config = function() require'nvim-tree'.setup {} end
2830
}
2931
```
@@ -72,6 +74,11 @@ require'nvim-tree'.setup {
7274
dotfiles = false,
7375
custom = {}
7476
},
77+
git = {
78+
enable = true,
79+
ignore = true,
80+
timeout = 500,
81+
},
7582
view = {
7683
width = 30,
7784
height = 30,
@@ -89,7 +96,6 @@ require'nvim-tree'.setup {
8996
These additional options must be set **BEFORE** calling `require'nvim-tree'` or calling setup.
9097
They are being migrated to the setup function bit by bit, check [this issue](https://github.com/kyazdani42/nvim-tree.lua/issues/674) if you encounter any problems related to configs not working after update.
9198
```vim
92-
let g:nvim_tree_gitignore = 1 "0 by default
9399
let g:nvim_tree_quit_on_open = 1 "0 by default, closes the tree when you open a file
94100
let g:nvim_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open
95101
let g:nvim_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons).

doc/nvim-tree-lua.txt

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ function.
101101
cmd = nil,
102102
args = {}
103103
},
104+
git = {
105+
enable = true,
106+
ignore = true,
107+
},
104108
view = {
105109
width = 30,
106110
height = 30,
@@ -231,6 +235,31 @@ Here is a list of the options available in the setup call:
231235
- `NvimTreeLspDiagnosticsInformation`
232236
- `NvimTreeLspDiagnosticsHint`
233237

238+
*nvim-tree.git*
239+
- |git|: git integration with icons and colors
240+
241+
- |git.enable|: enable / disable the feature
242+
type: `boolean`
243+
default: `true`
244+
245+
- |git.ignore|: ignore files based on `.gitignore`.
246+
will add `ignored=matching` to the integration when `true`. Otherwise will
247+
add `ignored=no` to the integration which can lead to better performance.
248+
249+
- |git.timeout|: kills the git process after some time if it takes too long
250+
type: `number`
251+
default: `400` (ms)
252+
253+
You will still need to configure `g:nvim_tree_show_icons.git` or
254+
`g:nvim_tree_git_hl` to be able to see things in the tree. This will be
255+
changed in the future versions.
256+
257+
The configurable timeout will kill the current process and so disable the
258+
git integration for the project that takes too long.
259+
The git integration is blocking, so if your timeout is too long (like not in
260+
milliseconds but a few seconds), it will not render anything until the git
261+
process returned the data.
262+
234263
*nvim-tree.view*
235264
- |view|: window / buffer setup
236265

@@ -296,16 +325,6 @@ width of the window, can be *width_in_columns* or *'width_in_percent%'*
296325
where the window will open (default to 'left')
297326
- 'left' or 'right'
298327

299-
|g:nvim_tree_gitignore| *g:nvim_tree_gitignore*
300-
301-
Determines whether to include in g:nvim_tree_ignore
302-
files ignored by git.
303-
304-
Must be:
305-
0: not ignored
306-
1: ignored files from `git ls-files --others --ignored --exclude-standard --directory`
307-
308-
>
309328
|g:nvim_tree_show_icons| *g:nvim_tree_show_icons*
310329

311330
Dictionary, if your terminal or font doesn't support certain unicode

lua/nvim-tree.lua

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,6 @@ function M.on_keypress(mode)
179179
end
180180
end
181181

182-
function M.refresh()
183-
lib.refresh_tree()
184-
end
185-
186182
function M.print_clipboard()
187183
fs.print_clipboard()
188184
end
@@ -227,7 +223,7 @@ function M.on_enter(opts)
227223
M.hijack_current_window()
228224
end
229225

230-
lib.init(should_open, should_open)
226+
lib.init(should_open)
231227
end
232228

233229
local function is_file_readable(fname)
@@ -242,7 +238,7 @@ local function update_base_dir_with_filepath(filepath, bufnr)
242238

243239
local ft = api.nvim_buf_get_option(bufnr, 'filetype') or ""
244240
for _, value in pairs(_config.update_focused_file.ignore_list) do
245-
if vim.fn.stridx(filepath, value) ~= -1 or vim.fn.stridx(ft, value) ~= -1 then
241+
if utils.str_find(filepath, value) or utils.str_find(ft, value) then
246242
return
247243
end
248244
end
@@ -359,7 +355,7 @@ local function setup_vim_commands()
359355
command! NvimTreeClose lua require'nvim-tree'.close()
360356
command! NvimTreeToggle lua require'nvim-tree'.toggle(false)
361357
command! NvimTreeFocus lua require'nvim-tree'.focus()
362-
command! NvimTreeRefresh lua require'nvim-tree'.refresh()
358+
command! NvimTreeRefresh lua require'nvim-tree.lib'.refresh_tree()
363359
command! NvimTreeClipboard lua require'nvim-tree'.print_clipboard()
364360
command! NvimTreeFindFile lua require'nvim-tree'.find_file(true)
365361
command! NvimTreeFindFileToggle lua require'nvim-tree'.toggle(true)
@@ -381,8 +377,8 @@ local function setup_autocommands(opts)
381377
""" reset highlights when colorscheme is changed
382378
au ColorScheme * lua require'nvim-tree'.reset_highlight()
383379
384-
au BufWritePost * lua require'nvim-tree'.refresh()
385-
au User FugitiveChanged,NeogitStatusRefreshed lua require'nvim-tree'.refresh()
380+
au BufWritePost * lua require'nvim-tree.lib'.refresh_tree()
381+
au User FugitiveChanged,NeogitStatusRefreshed lua require'nvim-tree.lib'.reload_git()
386382
]]
387383

388384
if opts.auto_close then
@@ -400,6 +396,7 @@ local function setup_autocommands(opts)
400396
if opts.update_focused_file.enable then
401397
vim.cmd "au BufEnter * lua require'nvim-tree'.find_file(false)"
402398
end
399+
vim.cmd "au BufUnload NvimTree lua require'nvim-tree.view'.View.tabpages = {}"
403400

404401
vim.cmd "augroup end"
405402
end
@@ -439,6 +436,11 @@ local DEFAULT_OPTS = {
439436
filters = {
440437
dotfiles = false,
441438
custom_filter = {}
439+
},
440+
git = {
441+
enable = true,
442+
ignore = true,
443+
timeout = 400,
442444
}
443445
}
444446

@@ -469,6 +471,7 @@ function M.setup(conf)
469471
require'nvim-tree.view'.setup(opts.view or {})
470472
require'nvim-tree.diagnostics'.setup(opts)
471473
require'nvim-tree.populate'.setup(opts)
474+
require'nvim-tree.git'.setup(opts)
472475

473476
setup_autocommands(opts)
474477
setup_vim_commands()

lua/nvim-tree/config.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ function M.get_icon_state()
5858
}
5959
end
6060

61-
function M.use_git()
62-
return M.get_icon_state().show_git_icon
63-
or vim.g.nvim_tree_git_hl == 1
64-
or vim.g.nvim_tree_gitignore == 1
65-
end
66-
6761
function M.nvim_tree_callback(callback_name)
6862
return string.format(":lua require'nvim-tree'.on_keypress('%s')<CR>", callback_name)
6963
end

lua/nvim-tree/fs.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ local function create_file(file)
3434
else
3535
luv.fs_close(fd)
3636
events._dispatch_file_created(file)
37-
lib.refresh_tree(true)
37+
lib.refresh_tree()
3838
focus_file(file)
3939
end
4040
end))
@@ -98,7 +98,7 @@ function M.create(node)
9898
end
9999
api.nvim_out_write(ans..' was properly created\n')
100100
events._dispatch_folder_created(ans)
101-
lib.refresh_tree(true)
101+
lib.refresh_tree()
102102
focus_file(ans)
103103
end
104104

@@ -239,7 +239,7 @@ local function do_paste(node, action_type, action_fn)
239239
end
240240

241241
clipboard[action_type] = {}
242-
return lib.refresh_tree(true)
242+
return lib.refresh_tree()
243243
end
244244

245245
local function add_to_clipboard(node, clip)
@@ -276,7 +276,7 @@ function M.remove(node)
276276
events._dispatch_file_removed(node.absolute_path)
277277
clear_buffer(node.absolute_path)
278278
end
279-
lib.refresh_tree(true)
279+
lib.refresh_tree()
280280
end
281281
end
282282

@@ -298,7 +298,7 @@ function M.rename(with_sub)
298298
api.nvim_out_write(node.absolute_path..''..new_name..'\n')
299299
rename_loaded_buffers(node.absolute_path, new_name)
300300
events._dispatch_node_renamed(abs_path, new_name)
301-
lib.refresh_tree(true)
301+
lib.refresh_tree()
302302
end
303303
end
304304

lua/nvim-tree/git.lua

Lines changed: 0 additions & 168 deletions
This file was deleted.

0 commit comments

Comments
 (0)