Skip to content

feat: add renderer.highlight_hidden, renderer.icons.show.hidden and renderer.icons.hidden_placement for dotfile icons/highlights #2840

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 5 commits into from
Jul 21, 2024

Conversation

evertonse
Copy link
Collaborator

@evertonse evertonse commented Jul 16, 2024

PR Description

This PR introduces the ability to highlight hidden files (dotfiles) by creating three new highlight groups:

  -- Hidden
  { group = "NvimTreeHiddenIcon", link = "NvimTreeSignColumn" },
  { group = "NvimTreeHiddenFileHL", link = "NvimTreeFileName" },
  { group = "NvimTreeHiddenFolderHL", link = "NvimTreeFolderName" },

It is ensured that if a file has a parent directory that is a dotfile, the file itself is also considered a dotfile. For example, all files within the .git or .github directories are regarded as dotfiles, as below:
image

Backward Compatibility

To ensure backward compatibility, by default:

  • Hidden files and folders highlight groups link to existing NvimTree highlights for files and folders.
  • The hidden icon will not display by default.
  • The name and icon of hidden files and folders will not be highlighted unless highlight_hidden is set to a value other than "none".
  • The show.hidden option is set to false by default.

Note: This change is not related to highlighting git-ignored files.

Example Setup

require('nvim-tree').setup {
  renderer = {
    highlight_hidden = 'name',
    icons = {
      web_devicons = {
        file = {
          enable = true,
          color = true,
        },
        folder = {
          enable = false,
          color = true,
        },
      },
      hidden_placement = 'before',
      show = {
        hidden = true,
      },
      glyphs = {
        hidden = '󰜌',
      },
    },
  },
}

Example Result (not generated by the above setup)

Below we show the highlights results produced by :Inspect command on a dotfile (hidden folder in this case).
image

…th icon and name (this not related to git highlights).

Better defaults

squashed

docs(hidden)

docs(hidden)

docs(hidden)
@alex-courtis
Copy link
Member

alex-courtis commented Jul 20, 2024

  -- Hidden
  { group = "NvimTreeHiddenIcon", link = "NvimTreeSignColumn" },
  { group = "NvimTreeHiddenFileHL", link = "NvimTreeFileName" },
  { group = "NvimTreeHiddenFolderHL", link = "NvimTreeFolderName" },

These defaults don't stand out very much; the user may think the feature is not working or misconfigured.

How about we use Conceal? It's distinct and not already used.

  -- Hidden
  { group = "NvimTreeHiddenIcon", link = "Conceal" },
  { group = "NvimTreeHiddenFileHL", link = "NvimTreeHiddenIcon" },
  { group = "NvimTreeHiddenFolderHL", link = "NvimTreeHiddenFileHL" },

@alex-courtis
Copy link
Member

Test cases:

highlight_hidden = "none",
highlight_hidden = "icon",
highlight_hidden = "name",
highlight_hidden = "all",
      hidden_placement = "signcolumn",
      show = {
        hidden = true,
      hidden_placement = "before",
      show = {
        hidden = true,
      hidden_placement = "after",
      show = {
        hidden = true,

@alex-courtis alex-courtis changed the title feat(hidden_highlight): Allow hidden files (dotfiles) to be highlighted, both icon and name. feat: add renderer.highlight_hidden, renderer.icons.show.hidden and renderer.icons.hidden_placement for dotfile icons/highlights Jul 20, 2024
Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - all working, just some polish needed.

@@ -904,6 +908,13 @@ Requires |nvim-tree.modified.enable|
Value can be `"none"`, `"icon"`, `"name"` or `"all"`
Type: `string`, Default `"none"`

*nvim-tree.renderer.highlight_hidden*
Copy link
Member

@alex-courtis alex-courtis Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please run make help-update to add the new entries to the indexes:

https://github.com/nvim-tree/nvim-tree.lua/actions/runs/9958922100/job/27689198158?pr=2840

@@ -442,6 +443,7 @@ function Builder.setup(opts)
DecoratorDiagnostics:new(opts),
DecoratorBookmarks:new(opts),
DecoratorModified:new(opts),
DecoratorHidden:new(opts),
Copy link
Member

@alex-courtis alex-courtis Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please update :help nvim-tree.renderer.icons with this order.

end
-- Inspect(node)
if node.is_dot or (node.name and (node.name:sub(1, 1) == ".")) or M.is_dotfile(node.parent) then
node.is_dot = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

---@param node Node
---@return HighlightedString[]|nil icons
function DecoratorHidden:calculate_icons(node)
if self.enabled and is_dotfile(node) then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.enabled and is_dotfile(node) then
if self.enabled and node:is_dotfile() then

You can then remove the require.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated in favor of all sugestions. However, I couldn't use is_dotfile as a method of node.
Instead I followed the same style of other decorators by 'requiring' into a variable called explorer_node and then using explorer_node.is_dotfile(node).
Besides that, everything else should be aligned with the change request.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, I couldn't use is_dotfile as a method of node. Instead I followed the same style of other decorators by 'requiring' into a variable called explorer_node and then using explorer_node.is_dotfile(node).

Right you are; node isn't yet a proper class. Apologies...

})
---@cast o DecoratorHidden

if not o.enabled then
Copy link
Member

@alex-courtis alex-courtis Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This will always be true, we can remove.

-- Hidden
{ group = "NvimTreeHiddenIcon", link = "NvimTreeSignColumn" },
{ group = "NvimTreeHiddenFileHL", link = "NvimTreeFileName" },
{ group = "NvimTreeHiddenFolderHL", link = "NvimTreeFolderName" },
Copy link
Member

@alex-courtis alex-courtis Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please add these to help nvim-tree-highlight-default

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, many thanks for your contribution!

20240721_155127

@alex-courtis alex-courtis merged commit 48a9290 into nvim-tree:master Jul 21, 2024
5 checks passed
@evertonse evertonse deleted the feat/hilight-dotfiles branch July 21, 2024 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants