Skip to content

feat/chore: rewrite git with job and some other fixes #743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Install with [packer](https://github.com/wbthomason/packer.nvim):
```lua
use {
'kyazdani42/nvim-tree.lua',
requires = 'kyazdani42/nvim-web-devicons',
requires = {
'kyazdani42/nvim-web-devicons', -- optional, for file icon
},
config = function() require'nvim-tree'.setup {} end
}
```
Expand Down Expand Up @@ -72,6 +74,11 @@ require'nvim-tree'.setup {
dotfiles = false,
custom = {}
},
git = {
enable = true,
ignore = true,
timeout = 500,
},
view = {
width = 30,
height = 30,
Expand All @@ -89,7 +96,6 @@ require'nvim-tree'.setup {
These additional options must be set **BEFORE** calling `require'nvim-tree'` or calling setup.
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.
```vim
let g:nvim_tree_gitignore = 1 "0 by default
let g:nvim_tree_quit_on_open = 1 "0 by default, closes the tree when you open a file
let g:nvim_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open
let g:nvim_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons).
Expand Down
39 changes: 29 additions & 10 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ function.
cmd = nil,
args = {}
},
git = {
enable = true,
ignore = true,
},
view = {
width = 30,
height = 30,
Expand Down Expand Up @@ -231,6 +235,31 @@ Here is a list of the options available in the setup call:
- `NvimTreeLspDiagnosticsInformation`
- `NvimTreeLspDiagnosticsHint`

*nvim-tree.git*
- |git|: git integration with icons and colors

- |git.enable|: enable / disable the feature
type: `boolean`
default: `true`

- |git.ignore|: ignore files based on `.gitignore`.
will add `ignored=matching` to the integration when `true`. Otherwise will
add `ignored=no` to the integration which can lead to better performance.

- |git.timeout|: kills the git process after some time if it takes too long
type: `number`
default: `400` (ms)

You will still need to configure `g:nvim_tree_show_icons.git` or
`g:nvim_tree_git_hl` to be able to see things in the tree. This will be
changed in the future versions.

The configurable timeout will kill the current process and so disable the
git integration for the project that takes too long.
The git integration is blocking, so if your timeout is too long (like not in
milliseconds but a few seconds), it will not render anything until the git
process returned the data.

*nvim-tree.view*
- |view|: window / buffer setup

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

|g:nvim_tree_gitignore| *g:nvim_tree_gitignore*

Determines whether to include in g:nvim_tree_ignore
files ignored by git.

Must be:
0: not ignored
1: ignored files from `git ls-files --others --ignored --exclude-standard --directory`

>
|g:nvim_tree_show_icons| *g:nvim_tree_show_icons*

Dictionary, if your terminal or font doesn't support certain unicode
Expand Down
29 changes: 16 additions & 13 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ local keypress_funcs = {
elseif _config.is_unix then
_config.system_open.cmd = 'xdg-open'
else
require'nvim-tree.utils'.echo_warning("Cannot open file with system application. Unrecognized platform.")
require'nvim-tree.utils'.warn("Cannot open file with system application. Unrecognized platform.")
return
end
end
Expand Down Expand Up @@ -173,16 +173,12 @@ function M.on_keypress(mode)
if node.link_to and not node.entries then
lib.open_file(mode, node.link_to)
elseif node.entries ~= nil then
lib.unroll_dir(node)
lib.expand_or_collapse(node)
else
lib.open_file(mode, node.absolute_path)
end
end

function M.refresh()
lib.refresh_tree()
end

function M.print_clipboard()
fs.print_clipboard()
end
Expand Down Expand Up @@ -227,7 +223,7 @@ function M.on_enter(opts)
M.hijack_current_window()
end

lib.init(should_open, should_open)
lib.init(should_open)
end

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

local ft = api.nvim_buf_get_option(bufnr, 'filetype') or ""
for _, value in pairs(_config.update_focused_file.ignore_list) do
if vim.fn.stridx(filepath, value) ~= -1 or vim.fn.stridx(ft, value) ~= -1 then
if utils.str_find(filepath, value) or utils.str_find(ft, value) then
return
end
end
Expand Down Expand Up @@ -359,7 +355,7 @@ local function setup_vim_commands()
command! NvimTreeClose lua require'nvim-tree'.close()
command! NvimTreeToggle lua require'nvim-tree'.toggle(false)
command! NvimTreeFocus lua require'nvim-tree'.focus()
command! NvimTreeRefresh lua require'nvim-tree'.refresh()
command! NvimTreeRefresh lua require'nvim-tree.lib'.refresh_tree()
command! NvimTreeClipboard lua require'nvim-tree'.print_clipboard()
command! NvimTreeFindFile lua require'nvim-tree'.find_file(true)
command! NvimTreeFindFileToggle lua require'nvim-tree'.toggle(true)
Expand All @@ -381,8 +377,8 @@ local function setup_autocommands(opts)
""" reset highlights when colorscheme is changed
au ColorScheme * lua require'nvim-tree'.reset_highlight()

au BufWritePost * lua require'nvim-tree'.refresh()
au User FugitiveChanged,NeogitStatusRefreshed lua require'nvim-tree'.refresh()
au BufWritePost * lua require'nvim-tree.lib'.refresh_tree()
au User FugitiveChanged,NeogitStatusRefreshed lua require'nvim-tree.lib'.reload_git()
]]

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

vim.cmd "augroup end"
end
Expand Down Expand Up @@ -439,6 +436,11 @@ local DEFAULT_OPTS = {
filters = {
dotfiles = false,
custom_filter = {}
},
git = {
enable = true,
ignore = true,
timeout = 400,
}
}

Expand All @@ -452,7 +454,7 @@ function M.setup(conf)
_config.open_on_setup = opts.open_on_setup
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup
if type(opts.update_to_buf_dir) == "boolean" then
utils.echo_warning("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir")
utils.warn("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir")
_config.update_to_buf_dir = {
enable = opts.update_to_buf_dir,
auto_open = opts.update_to_buf_dir,
Expand All @@ -462,13 +464,14 @@ function M.setup(conf)
end

if opts.lsp_diagnostics ~= nil then
utils.echo_warning("setup.lsp_diagnostics has been removed, see :help nvim-tree.diagnostics")
utils.warn("setup.lsp_diagnostics has been removed, see :help nvim-tree.diagnostics")
end

require'nvim-tree.colors'.setup()
require'nvim-tree.view'.setup(opts.view or {})
require'nvim-tree.diagnostics'.setup(opts)
require'nvim-tree.populate'.setup(opts)
require'nvim-tree.git'.setup(opts)

setup_autocommands(opts)
setup_vim_commands()
Expand Down
6 changes: 0 additions & 6 deletions lua/nvim-tree/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ function M.get_icon_state()
}
end

function M.use_git()
return M.get_icon_state().show_git_icon
or vim.g.nvim_tree_git_hl == 1
or vim.g.nvim_tree_gitignore == 1
end

function M.nvim_tree_callback(callback_name)
return string.format(":lua require'nvim-tree'.on_keypress('%s')<CR>", callback_name)
end
Expand Down
21 changes: 15 additions & 6 deletions lua/nvim-tree/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ local function create_file(file)
else
luv.fs_close(fd)
events._dispatch_file_created(file)
lib.refresh_tree(true)
lib.refresh_tree()
focus_file(file)
end
end))
Expand Down Expand Up @@ -98,7 +98,7 @@ function M.create(node)
end
api.nvim_out_write(ans..' was properly created\n')
events._dispatch_folder_created(ans)
lib.refresh_tree(true)
lib.refresh_tree()
focus_file(ans)
end

Expand All @@ -113,6 +113,9 @@ local function clear_buffer(absolute_path)
api.nvim_set_current_win(winnr)
end
vim.api.nvim_buf_delete(buf.bufnr, {})
if buf.windows[1] then
vim.api.nvim_win_close(buf.windows[1], true)
end
return
end
end
Expand Down Expand Up @@ -239,7 +242,7 @@ local function do_paste(node, action_type, action_fn)
end

clipboard[action_type] = {}
return lib.refresh_tree(true)
return lib.refresh_tree()
end

local function add_to_clipboard(node, clip)
Expand Down Expand Up @@ -276,7 +279,7 @@ function M.remove(node)
events._dispatch_file_removed(node.absolute_path)
clear_buffer(node.absolute_path)
end
lib.refresh_tree(true)
lib.refresh_tree()
end
end

Expand All @@ -289,7 +292,13 @@ function M.rename(with_sub)
local abs_path = with_sub and node.absolute_path:sub(0, namelen * (-1) -1) or node.absolute_path
local new_name = vim.fn.input("Rename " ..node.name.. " to ", abs_path)
utils.clear_prompt()
if not new_name or #new_name == 0 then return end
if not new_name or #new_name == 0 then
return
end
if luv.fs_access(new_name, 'R') then
utils.warn("Cannot rename: file already exists")
return
end

local success = luv.fs_rename(node.absolute_path, new_name)
if not success then
Expand All @@ -298,7 +307,7 @@ function M.rename(with_sub)
api.nvim_out_write(node.absolute_path..' ➜ '..new_name..'\n')
rename_loaded_buffers(node.absolute_path, new_name)
events._dispatch_node_renamed(abs_path, new_name)
lib.refresh_tree(true)
lib.refresh_tree()
end
end

Expand Down
Loading