Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/luals-out/
/luals/
# backup vim files
*~
28 changes: 27 additions & 1 deletion doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
highlight_diagnostics = "none",
highlight_opened_files = "none",
highlight_modified = "none",
highlight_hidden = "none",
highlight_bookmarks = "none",
highlight_clipboard = "name",
indent_markers = {
Expand All @@ -454,6 +455,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
},
git_placement = "before",
modified_placement = "after",
hidden_placement = "after",
diagnostics_placement = "signcolumn",
bookmarks_placement = "signcolumn",
padding = " ",
Expand All @@ -464,6 +466,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
folder_arrow = true,
git = true,
modified = true,
hidden = false,
diagnostics = true,
bookmarks = true,
},
Expand All @@ -472,6 +475,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
symlink = "",
bookmark = "󰆤",
modified = "●",
hidden = "󰜌",
folder = {
arrow_closed = "",
arrow_open = "",
Expand Down Expand Up @@ -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

Highlight icons and/or names for hidden files (dotfiles) using the
`NvimTreeHiddenFileHL` highlight group.
Requires |nvim-tree.hidden.enable|
Value can be `"none"`, `"icon"`, `"name"` or `"all"`
Type: `string`, Default `"none"`

*nvim-tree.renderer.highlight_bookmarks*
Highlight bookmarked using the `NvimTreeBookmarkHL` group.
Value can be `"none"`, `"icon"`, `"name"` or `"all"`
Expand Down Expand Up @@ -989,6 +1000,12 @@ Icon order and sign column precedence:
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
Type: `string`, Default: `"after"`

*nvim-tree.renderer.icons.hidden_placement*
Place where the hidden (dotfile) icon will be rendered.
Can be `"after"` or `"before"` filename (after the file/folders icons)
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
Type: `string`, Default: `"after"`

*nvim-tree.renderer.icons.bookmarks_placement*
Place where the bookmarks icon will be rendered.
Can be `"after"` or `"before"` filename (after the file/folders icons)
Expand All @@ -1005,7 +1022,7 @@ Icon order and sign column precedence:

*nvim-tree.renderer.icons.show*
Configuration options for showing icon types.
Left to right order: file/folder, git, modified, diagnostics, bookmarked.
Left to right order: file/folder, git, modified, hidden, diagnostics, bookmarked.

*nvim-tree.renderer.icons.show.file*
Show an icon before the file name.
Expand All @@ -1030,6 +1047,11 @@ Icon order and sign column precedence:
Requires |modified.enable| `= true`
Type: `boolean`, Default: `true`

*nvim-tree.renderer.icons.show.hidden*
Show a hidden icon, see |renderer.icons.hidden_placement|
Requires |hidden.enable| `= true`
Type: `boolean`, Default: `true`

*nvim-tree.renderer.icons.show.diagnostics*
Show a diagnostics status icon, see |renderer.icons.diagnostics_placement|
Requires |diagnostics.enable| `= true`
Expand Down Expand Up @@ -1057,6 +1079,10 @@ Icon order and sign column precedence:
Icon to display for modified files.
Type: `string`, Default: `"●"`

*nvim-tree.renderer.icons.glyphs.hidden*
Icon to display for hidden files.
Type: `string`, Default: `"󰜌""`

*nvim-tree.renderer.icons.glyphs.folder*
Glyphs for directories.
Overridden by |nvim-tree.renderer.icons.web_devicons| if available.
Expand Down
6 changes: 6 additions & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
highlight_diagnostics = "none",
highlight_opened_files = "none",
highlight_modified = "none",
highlight_hidden = "none",
highlight_bookmarks = "none",
highlight_clipboard = "name",
indent_markers = {
Expand All @@ -418,6 +419,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
git_placement = "before",
modified_placement = "after",
hidden_placement = "after",
diagnostics_placement = "signcolumn",
bookmarks_placement = "signcolumn",
padding = " ",
Expand All @@ -428,6 +430,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
folder_arrow = true,
git = true,
modified = true,
hidden = false,
diagnostics = true,
bookmarks = true,
},
Expand All @@ -436,6 +439,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
symlink = "",
bookmark = "󰆤",
modified = "●",
hidden = "󰜌",
folder = {
arrow_closed = "",
arrow_open = "",
Expand Down Expand Up @@ -668,12 +672,14 @@ local ACCEPTED_STRINGS = {
highlight_git = { "none", "icon", "name", "all" },
highlight_opened_files = { "none", "icon", "name", "all" },
highlight_modified = { "none", "icon", "name", "all" },
highlight_hidden = { "none", "icon", "name", "all" },
highlight_bookmarks = { "none", "icon", "name", "all" },
highlight_diagnostics = { "none", "icon", "name", "all" },
highlight_clipboard = { "none", "icon", "name", "all" },
icons = {
git_placement = { "before", "after", "signcolumn" },
modified_placement = { "before", "after", "signcolumn" },
hidden_placement = { "before", "after", "signcolumn" },
diagnostics_placement = { "before", "after", "signcolumn" },
bookmarks_placement = { "before", "after", "signcolumn" },
},
Expand Down
5 changes: 5 additions & 0 deletions lua/nvim-tree/appearance/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ M.HIGHLIGHT_GROUPS = {
{ group = "NvimTreeModifiedFileHL", link = "NvimTreeModifiedIcon" },
{ group = "NvimTreeModifiedFolderHL", link = "NvimTreeModifiedFileHL" },

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


-- Opened
{ group = "NvimTreeOpenedHL", link = "Special" },

Expand Down
14 changes: 14 additions & 0 deletions lua/nvim-tree/explorer/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ function M.is_git_ignored(node)
return node and node.git_status ~= nil and node.git_status.file == "!!"
end

---@param node Node
---@return boolean
function M.is_dotfile(node)
if node == nil then
return false
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

return true
end
return false
end

---@param node Node
function M.node_destroy(node)
if not node then
Expand Down
1 change: 1 addition & 0 deletions lua/nvim-tree/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
---@field fs_stat uv.fs_stat.result|nil
---@field git_status GitStatus|nil
---@field hidden boolean
---@field is_dot boolean
---@field name string
---@field parent DirNode
---@field type string
Expand Down
2 changes: 2 additions & 0 deletions lua/nvim-tree/renderer/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local DecoratorCut = require "nvim-tree.renderer.decorator.cut"
local DecoratorDiagnostics = require "nvim-tree.renderer.decorator.diagnostics"
local DecoratorGit = require "nvim-tree.renderer.decorator.git"
local DecoratorModified = require "nvim-tree.renderer.decorator.modified"
local DecoratorHidden = require "nvim-tree.renderer.decorator.hidden"
local DecoratorOpened = require "nvim-tree.renderer.decorator.opened"

local pad = require "nvim-tree.renderer.components.padding"
Expand Down Expand Up @@ -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.

DecoratorOpened:new(opts),
DecoratorGit:new(opts),
}
Expand Down
60 changes: 60 additions & 0 deletions lua/nvim-tree/renderer/decorator/hidden.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
local is_dotfile = require("nvim-tree.explorer.node").is_dotfile
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT

local Decorator = require "nvim-tree.renderer.decorator"

---@class DecoratorHidden: Decorator
---@field icon HighlightedString|nil
local DecoratorHidden = Decorator:new()

---@param opts table
---@return DecoratorHidden
function DecoratorHidden:new(opts)
local o = Decorator.new(self, {
enabled = true,
hl_pos = HL_POSITION[opts.renderer.highlight_hidden] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.hidden_placement] or ICON_PLACEMENT.none,
})
---@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.

return o
end

if opts.renderer.icons.show.hidden then
o.icon = {
str = opts.renderer.icons.glyphs.hidden,
hl = { "NvimTreeHiddenIcon" },
}
o:define_sign(o.icon)
end

return o
end

---Hidden icon: hidden.enable, renderer.icons.show.hidden and node starts with `.` (dotfile).
---@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...

return { self.icon }
end
end

---Hidden highlight: hidden.enable, renderer.highlight_hidden and node starts with `.` (dotfile).
---@param node Node
---@return string|nil group
function DecoratorHidden:calculate_highlight(node)
if not self.enabled or self.hl_pos == HL_POSITION.none or not (is_dotfile(node)) then
return nil
end

if node.nodes then
return "NvimTreeHiddenFolderHL"
else
return "NvimTreeHiddenFileHL"
end
end

return DecoratorHidden