Skip to content

Commit b406334

Browse files
committed
feat/chore: rewrite git with job and some other fixes
1 parent 6cadd3a commit b406334

14 files changed

+433
-339
lines changed

Diff for: README.md

+14-2
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
```
@@ -89,6 +91,17 @@ require'nvim-tree'.setup {
8991
args = {}
9092
},
9193

94+
-- git integration (:help nvim-tree.git)
95+
git = {
96+
-- enable the module
97+
enable = true,
98+
-- enable gitignore filtering on files
99+
ignore = true,
100+
-- kill the git job after this timeout in `ms`
101+
timeout = 500,
102+
},
103+
104+
-- window/buffer configurations (:help nvim-tree.view)
92105
view = {
93106
-- width of the window, can be either a number (columns) or a string in `%`, for left or right side placement
94107
width = 30,
@@ -111,7 +124,6 @@ require'nvim-tree'.setup {
111124

112125
```vim
113126
let g:nvim_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default
114-
let g:nvim_tree_gitignore = 1 "0 by default
115127
let g:nvim_tree_quit_on_open = 1 "0 by default, closes the tree when you open a file
116128
let g:nvim_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open
117129
let g:nvim_tree_hide_dotfiles = 1 "0 by default, this option hides files and folders starting with a dot `.`

Diff for: doc/nvim-tree-lua.txt

+30-10
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,
@@ -227,6 +231,31 @@ Here is a list of the options available in the setup call:
227231
- `NvimTreeLspDiagnosticsInformation`
228232
- `NvimTreeLspDiagnosticsHint`
229233

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

@@ -281,17 +310,8 @@ An array of strings that the tree won't load and display.
281310
useful to hide large data/cache folders.
282311
>
283312
example: let g:nvim_tree_ignore = [ '.git', 'node_modules' ]
313+
<
284314

285-
|g:nvim_tree_gitignore| *g:nvim_tree_gitignore*
286-
287-
Determines whether to include in g:nvim_tree_ignore
288-
files ignored by git.
289-
290-
Must be:
291-
0: not ignored
292-
1: ignored files from `git ls-files --others --ignored --exclude-standard --directory`
293-
294-
>
295315
|g:nvim_tree_show_icons| *g:nvim_tree_show_icons*
296316

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

Diff for: lua/nvim-tree.lua

+12-9
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
@@ -358,7 +354,7 @@ local function setup_vim_commands()
358354
command! NvimTreeClose lua require'nvim-tree'.close()
359355
command! NvimTreeToggle lua require'nvim-tree'.toggle(false)
360356
command! NvimTreeFocus lua require'nvim-tree'.focus()
361-
command! NvimTreeRefresh lua require'nvim-tree'.refresh()
357+
command! NvimTreeRefresh lua require'nvim-tree.lib'.refresh_tree()
362358
command! NvimTreeClipboard lua require'nvim-tree'.print_clipboard()
363359
command! NvimTreeFindFile lua require'nvim-tree'.find_file(true)
364360
command! NvimTreeFindFileToggle lua require'nvim-tree'.toggle(true)
@@ -380,8 +376,8 @@ local function setup_autocommands(opts)
380376
""" reset highlights when colorscheme is changed
381377
au ColorScheme * lua require'nvim-tree'.reset_highlight()
382378
383-
au BufWritePost * lua require'nvim-tree'.refresh()
384-
au User FugitiveChanged,NeogitStatusRefreshed lua require'nvim-tree'.refresh()
379+
au BufWritePost * lua require'nvim-tree.lib'.refresh_tree()
380+
au User FugitiveChanged,NeogitStatusRefreshed lua require'nvim-tree.lib'.reload_git()
385381
]]
386382

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

403400
vim.cmd "augroup end"
404401
end
@@ -434,6 +431,11 @@ local DEFAULT_OPTS = {
434431
error = "",
435432
}
436433
},
434+
git = {
435+
enable = true,
436+
ignore = true,
437+
timeout = 400,
438+
}
437439
}
438440

439441
function M.setup(conf)
@@ -462,6 +464,7 @@ function M.setup(conf)
462464
require'nvim-tree.colors'.setup()
463465
require'nvim-tree.view'.setup(opts.view or {})
464466
require'nvim-tree.diagnostics'.setup(opts)
467+
require'nvim-tree.git'.setup(opts)
465468

466469
setup_autocommands(opts)
467470
setup_vim_commands()

Diff for: lua/nvim-tree/config.lua

-6
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

Diff for: lua/nvim-tree/fs.lua

+5-5
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

0 commit comments

Comments
 (0)