Skip to content

feat: rewrite git management with sqlite #682

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

Closed
wants to merge 12 commits into from
Closed
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
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Install with [vim-plug](https://github.com/junegunn/vim-plug):
```vim
" requires
Plug 'kyazdani42/nvim-web-devicons' " for file icons
Plug 'tami5/sqlite.lua' " for git integration
Plug 'kyazdani42/nvim-tree.lua'
```

Expand All @@ -23,7 +24,10 @@ 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
'tami5/sqlite.lua', -- optional, for git integration
},
config = function() require'nvim-tree'.setup {} end
}
```
Expand Down Expand Up @@ -89,6 +93,17 @@ require'nvim-tree'.setup {
args = {}
},

-- git integration (:help nvim-tree.git)
git = {
-- enable the module
enable = true,
-- enable gitignore filtering on files
ignore = true,
-- kills the git integration after this if it takes too long to complete
timeout = 5000,
},

-- window/buffer configurations (:help nvim-tree.view)
view = {
-- width of the window, can be either a number (columns) or a string in `%`, for left or right side placement
width = 30,
Expand All @@ -111,7 +126,6 @@ require'nvim-tree'.setup {

```vim
let g:nvim_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default
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_hide_dotfiles = 1 "0 by default, this option hides files and folders starting with a dot `.`
Expand Down
43 changes: 33 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 @@ -227,6 +231,34 @@ 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: `5000` (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 git integration is based on `tami5/sqlite.lua`, and is asynchronous in
order to avoid blocking the UI when parsing big amounts of statuses.
The database is opened on startup and destroyed when neovim exits.
Multiple instances of neovim will spawn multiple databases to avoid
collisions.

The configurable timeout will kill the current process and
the git integration if its taking too long.

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

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

|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
21 changes: 12 additions & 9 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ function M.on_keypress(mode)
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 @@ -358,7 +354,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 @@ -380,8 +376,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 @@ -399,6 +395,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 @@ -434,6 +431,11 @@ local DEFAULT_OPTS = {
error = "",
}
},
git = {
enable = true,
ignore = true,
timeout = 400,
}
}

function M.setup(conf)
Expand Down Expand Up @@ -462,6 +464,7 @@ function M.setup(conf)
require'nvim-tree.colors'.setup()
require'nvim-tree.view'.setup(opts.view or {})
require'nvim-tree.diagnostics'.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
10 changes: 5 additions & 5 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 Down Expand Up @@ -239,7 +239,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 +276,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 @@ -298,7 +298,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