nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to highlight items that is ignored by git with `git.ignore` set to `false`?

kutsan opened this issue · comments

local nvim_tree = require('nvim-tree')
nvim_tree.setup({
  git = {
    ignore = false
  }
})

With git.ignore set to false, as far as I know there is no now way to set highlights for items that is ignored by git. Previously, I had known if certain item is ignored by looking at its highlight.

Before

image

HEAD

image

Also seeing the same issue! Would love a way to just highlight git ignored files.

Reverting the newest commits I was able to track when this stop working, it was after the commit 6662b60.

Before that the highlights was working as expected.

Debugging the functions in renderer/init.lua a little bit, I saw that for a lot of files/folders, the property node.git_status was nil (incorrectly), so the renderer util functions can't figure out the right highlighting. The problem is probably in the process of parsing the results of the git call into the git_status value of the entry node.

Digging a little more I found a hardcoded filter right here in the setup of populate.lua

function M.setup(opts)
  M.config = {
    filter_ignored = true,
    filter_dotfiles = opts.filters.dotfiles,
  }

I was able to restore the old (desirable) behavior by setting the flag filter_ignored to false and removing this new config git = { ignore = false } from the personal config table.

commented

i guess you could set ignore = true for git, and just run require'nvim-tree.lib'.toggle_ignored() on startup ?
I think i should make a configuration option for this, seems like i forgot to add that.

i guess you could set ignore = true for git, and just run require'nvim-tree.lib'.toggle_ignored() on startup ?

This also works exactly like the workaround I described, however both methods have the undesirable side effect of ignoring all other filters you may have in the filters table of the setup config.

The best I could get for now was to overwrite the function should_ignore_git (in the file populate.lua) to always return false. This way, the ignored files are included in the git command line call and the state !! is populated correctly, and the renderer/init.lua can setup the right highlight. Changing just the function should_ignore_git also does not mess with other filter you may have defined (restoring the old desirable behavior).

I believe the main issue here is that when we set the git = { ignore = false } in the setup table, the git command called to get the states of the files does not include the gitignored files, so they never get a valid git status. I get the possible performance gains with this method, but I think we should come up with some way to indicate the desired behavior in the setup table.

Could you guys test this PR? #847

Could you guys test this PR? #847

@saviocmc I did and it's working fine for me.

How do I actually get the gitignored files/directories to get a different highlight like in the screenshot above? I currently only see a circle in front of them indicating that they are gitignored, which I assume is what the highlight group NvimTreeGitignoreIcon controls.

To enable highlight based on git status you have to set the nvim_tree_git_hl flag in vim global scope (it is disable by default).

If you use vimscript to configure vim, you can set it with: let g:nvim_tree_git_hl = 1
If you use lua, you can do: vim.g.nvim_tree_git_hl = 1

Either one of the lines above must be added before calling the plugin setup function.

You can change the default highlight by linking the default ones to the ones you want to use, like:
highlight! link NvimTreeGitIgnored MyHighlight

The circle icon you mentioned is the default icon for git ignored files and you can replace it (or remove it) by defining the nvim_tree_icons global variable. Type the command :help nvim_tree_icons to see how.

@saviocmc Thanks that worked!

Is it just for me that this stopped working for again?

commented

works on my end. Are you sure nvim_tree_git_hl is set before the require"nvim-tree..." ?

Edit: Oh I have to set vim.g.nvim_tree_git_hl even before I do require()! I thought I just had to do it before I call setup(). That's my bad then, it works for me again now, thank you!

Original comment

Notice in my screenshot how the gitignored files and directories (packages/, sessions/, spell/ and http) have the same highlighting as all other files.

nvim-tree

Here's a minimal setup that I'm using.

call plug#begin('~/.config/nvim/packages/')
Plug 'kyazdani42/nvim-tree.lua'
call plug#end()

lua << EOF
local nvim_tree = require('nvim-tree')

vim.g.nvim_tree_git_hl = 1
nvim_tree.setup {
  git = {
    ignore = false,
  },
}