chore: migrate to classic (#2991)
* add classic, migrating nodes classes
* add mixins to classic
* typechecked optargs constructors for nodes
* typechecked optargs constructors for watcher and event
* luacheck
* typechecked optargs constructors for GitRunner
* typechecked optargs constructors for Sorter
* typechecked optargs constructors for decorators, WIP
* typechecked optargs constructors for decorators, WIP
* typechecked optargs constructors for decorators
* remove class
* replace enums with named maps
* Renderer and Builder use classic, tidy opts
* LiveFilter uses classic, tidy opts
* Filter uses classic, tidy opts
* add FilterTypes named map
* move toggles into filters
* Marks uses classic, tidy opts
* Sorter uses classic, tidy opts
* Clipboard uses classic, tidy opts
* use supers for node methods
* HighlightDisplay uses classic
* protected :new
* Watcher tidy
* Revert "use supers for node methods"
This reverts commit 9fc7a866ec.
* Watcher tidy
* format
* format
* Filters private methods
* format
* Sorter type safety
* Sorter type safety
* Sorter type safety
* Sorter type safety
* Sorter type safety
* Sorter type safety
* tidy Runner
* tidy hi-test name
This commit is contained in:
committed by
GitHub
parent
610a1c189b
commit
3fc8de198c
@@ -1,35 +1,29 @@
|
||||
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 (exact) DecoratorBookmarks: Decorator
|
||||
---@field icon HighlightedString?
|
||||
local DecoratorBookmarks = Decorator:new()
|
||||
local DecoratorBookmarks = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorBookmarks
|
||||
function DecoratorBookmarks:create(opts, explorer)
|
||||
---@type DecoratorBookmarks
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_bookmarks] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[opts.renderer.icons.bookmarks_placement] or ICON_PLACEMENT.none,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorBookmarks
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorBookmarks
|
||||
|
||||
if opts.renderer.icons.show.bookmarks then
|
||||
o.icon = {
|
||||
str = opts.renderer.icons.glyphs.bookmark,
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorBookmarks:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_bookmarks or "none",
|
||||
icon_placement = args.explorer.opts.renderer.icons.bookmarks_placement or "none",
|
||||
})
|
||||
|
||||
if self.explorer.opts.renderer.icons.show.bookmarks then
|
||||
self.icon = {
|
||||
str = self.explorer.opts.renderer.icons.glyphs.bookmark,
|
||||
hl = { "NvimTreeBookmarkIcon" },
|
||||
}
|
||||
o:define_sign(o.icon)
|
||||
self:define_sign(self.icon)
|
||||
end
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Bookmark icon: renderer.icons.show.bookmarks and node is marked
|
||||
@@ -45,7 +39,7 @@ end
|
||||
---@param node Node
|
||||
---@return string|nil group
|
||||
function DecoratorBookmarks:calculate_highlight(node)
|
||||
if self.hl_pos ~= HL_POSITION.none and self.explorer.marks:get(node) then
|
||||
if self.range ~= "none" and self.explorer.marks:get(node) then
|
||||
return "NvimTreeBookmarkHL"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,34 +1,27 @@
|
||||
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 (exact) DecoratorCopied: Decorator
|
||||
---@field icon HighlightedString?
|
||||
local DecoratorCopied = Decorator:new()
|
||||
local DecoratorCopied = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorCopied
|
||||
function DecoratorCopied:create(opts, explorer)
|
||||
---@type DecoratorCopied
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT.none,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorCopied
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorCopied
|
||||
|
||||
return o
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorCopied:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_clipboard or "none",
|
||||
icon_placement = "none",
|
||||
})
|
||||
end
|
||||
|
||||
---Copied highlight: renderer.highlight_clipboard and node is copied
|
||||
---@param node Node
|
||||
---@return string|nil group
|
||||
function DecoratorCopied:calculate_highlight(node)
|
||||
if self.hl_pos ~= HL_POSITION.none and self.explorer.clipboard:is_copied(node) then
|
||||
if self.range ~= "none" and self.explorer.clipboard:is_copied(node) then
|
||||
return "NvimTreeCopiedHL"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,33 +1,27 @@
|
||||
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 (exact) DecoratorCut: Decorator
|
||||
local DecoratorCut = Decorator:new()
|
||||
local DecoratorCut = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorCut
|
||||
function DecoratorCut:create(opts, explorer)
|
||||
---@type DecoratorCut
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT.none,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorCut
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorCut
|
||||
|
||||
return o
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorCut:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_clipboard or "none",
|
||||
icon_placement = "none",
|
||||
})
|
||||
end
|
||||
|
||||
---Cut highlight: renderer.highlight_clipboard and node is cut
|
||||
---@param node Node
|
||||
---@return string|nil group
|
||||
function DecoratorCut:calculate_highlight(node)
|
||||
if self.hl_pos ~= HL_POSITION.none and self.explorer.clipboard:is_cut(node) then
|
||||
if self.range ~= "none" and self.explorer.clipboard:is_cut(node) then
|
||||
return "NvimTreeCutHL"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
local diagnostics = require("nvim-tree.diagnostics")
|
||||
|
||||
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")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
@@ -35,38 +32,35 @@ local ICON_KEYS = {
|
||||
|
||||
---@class (exact) DecoratorDiagnostics: Decorator
|
||||
---@field icons HighlightedString[]?
|
||||
local DecoratorDiagnostics = Decorator:new()
|
||||
local DecoratorDiagnostics = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorDiagnostics
|
||||
function DecoratorDiagnostics:create(opts, explorer)
|
||||
---@type DecoratorDiagnostics
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = opts.diagnostics.enable,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_diagnostics] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[opts.renderer.icons.diagnostics_placement] or ICON_PLACEMENT.none,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorDiagnostics
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorDiagnostics
|
||||
|
||||
if not o.enabled then
|
||||
return o
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorDiagnostics:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_diagnostics or "none",
|
||||
icon_placement = args.explorer.opts.renderer.icons.diagnostics_placement or "none",
|
||||
})
|
||||
|
||||
if not self.enabled then
|
||||
return
|
||||
end
|
||||
|
||||
if opts.renderer.icons.show.diagnostics then
|
||||
o.icons = {}
|
||||
if self.explorer.opts.renderer.icons.show.diagnostics then
|
||||
self.icons = {}
|
||||
for name, sev in pairs(ICON_KEYS) do
|
||||
o.icons[sev] = {
|
||||
str = opts.diagnostics.icons[name],
|
||||
self.icons[sev] = {
|
||||
str = self.explorer.opts.diagnostics.icons[name],
|
||||
hl = { HG_ICON[sev] },
|
||||
}
|
||||
o:define_sign(o.icons[sev])
|
||||
self:define_sign(self.icons[sev])
|
||||
end
|
||||
end
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Diagnostic icon: diagnostics.enable, renderer.icons.show.diagnostics and node has status
|
||||
@@ -87,7 +81,7 @@ end
|
||||
---@param node Node
|
||||
---@return string|nil group
|
||||
function DecoratorDiagnostics:calculate_highlight(node)
|
||||
if not node or not self.enabled or self.hl_pos == HL_POSITION.none then
|
||||
if not node or not self.enabled or self.range == "none" then
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
local notify = require("nvim-tree.notify")
|
||||
|
||||
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")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
@@ -20,52 +17,49 @@ local DirectoryNode = require("nvim-tree.node.directory")
|
||||
---@field folder_hl_by_xy table<GitXY, string>?
|
||||
---@field icons_by_status GitIconsByStatus?
|
||||
---@field icons_by_xy GitIconsByXY?
|
||||
local DecoratorGit = Decorator:new()
|
||||
local DecoratorGit = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorGit
|
||||
function DecoratorGit:create(opts, explorer)
|
||||
---@type DecoratorGit
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = opts.git.enable,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_git] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[opts.renderer.icons.git_placement] or ICON_PLACEMENT.none,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorGit
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorGit
|
||||
|
||||
if not o.enabled then
|
||||
return o
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorGit:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = args.explorer.opts.git.enable,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_git or "none",
|
||||
icon_placement = args.explorer.opts.renderer.icons.git_placement or "none",
|
||||
})
|
||||
|
||||
if not self.enabled then
|
||||
return
|
||||
end
|
||||
|
||||
if o.hl_pos ~= HL_POSITION.none then
|
||||
o:build_file_folder_hl_by_xy()
|
||||
if self.range ~= "none" then
|
||||
self:build_file_folder_hl_by_xy()
|
||||
end
|
||||
|
||||
if opts.renderer.icons.show.git then
|
||||
o:build_icons_by_status(opts.renderer.icons.glyphs.git)
|
||||
o:build_icons_by_xy(o.icons_by_status)
|
||||
if self.explorer.opts.renderer.icons.show.git then
|
||||
self:build_icons_by_status(self.explorer.opts.renderer.icons.glyphs.git)
|
||||
self:build_icons_by_xy(self.icons_by_status)
|
||||
|
||||
for _, icon in pairs(o.icons_by_status) do
|
||||
for _, icon in pairs(self.icons_by_status) do
|
||||
self:define_sign(icon)
|
||||
end
|
||||
end
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---@param glyphs GitGlyphsByStatus
|
||||
function DecoratorGit:build_icons_by_status(glyphs)
|
||||
self.icons_by_status = {}
|
||||
self.icons_by_status.staged = { str = glyphs.staged, hl = { "NvimTreeGitStagedIcon" }, ord = 1 }
|
||||
self.icons_by_status.unstaged = { str = glyphs.unstaged, hl = { "NvimTreeGitDirtyIcon" }, ord = 2 }
|
||||
self.icons_by_status.renamed = { str = glyphs.renamed, hl = { "NvimTreeGitRenamedIcon" }, ord = 3 }
|
||||
self.icons_by_status.deleted = { str = glyphs.deleted, hl = { "NvimTreeGitDeletedIcon" }, ord = 4 }
|
||||
self.icons_by_status.unmerged = { str = glyphs.unmerged, hl = { "NvimTreeGitMergeIcon" }, ord = 5 }
|
||||
self.icons_by_status = {}
|
||||
self.icons_by_status.staged = { str = glyphs.staged, hl = { "NvimTreeGitStagedIcon" }, ord = 1 }
|
||||
self.icons_by_status.unstaged = { str = glyphs.unstaged, hl = { "NvimTreeGitDirtyIcon" }, ord = 2 }
|
||||
self.icons_by_status.renamed = { str = glyphs.renamed, hl = { "NvimTreeGitRenamedIcon" }, ord = 3 }
|
||||
self.icons_by_status.deleted = { str = glyphs.deleted, hl = { "NvimTreeGitDeletedIcon" }, ord = 4 }
|
||||
self.icons_by_status.unmerged = { str = glyphs.unmerged, hl = { "NvimTreeGitMergeIcon" }, ord = 5 }
|
||||
self.icons_by_status.untracked = { str = glyphs.untracked, hl = { "NvimTreeGitNewIcon" }, ord = 6 }
|
||||
self.icons_by_status.ignored = { str = glyphs.ignored, hl = { "NvimTreeGitIgnoredIcon" }, ord = 7 }
|
||||
self.icons_by_status.ignored = { str = glyphs.ignored, hl = { "NvimTreeGitIgnoredIcon" }, ord = 7 }
|
||||
end
|
||||
|
||||
---@param icons GitIconsByXY
|
||||
@@ -102,7 +96,7 @@ function DecoratorGit:build_icons_by_xy(icons)
|
||||
["DD"] = { icons.deleted },
|
||||
["DU"] = { icons.deleted, icons.unmerged },
|
||||
["!!"] = { icons.ignored },
|
||||
dirty = { icons.unstaged },
|
||||
dirty = { icons.unstaged },
|
||||
}
|
||||
end
|
||||
|
||||
@@ -121,7 +115,7 @@ function DecoratorGit:build_file_folder_hl_by_xy()
|
||||
[" T"] = "NvimTreeGitFileDirtyHL",
|
||||
["MM"] = "NvimTreeGitFileDirtyHL",
|
||||
["AM"] = "NvimTreeGitFileDirtyHL",
|
||||
dirty = "NvimTreeGitFileDirtyHL",
|
||||
dirty = "NvimTreeGitFileDirtyHL",
|
||||
["A "] = "NvimTreeGitFileStagedHL",
|
||||
["??"] = "NvimTreeGitFileNewHL",
|
||||
["AU"] = "NvimTreeGitFileMergeHL",
|
||||
@@ -165,7 +159,7 @@ function DecoratorGit:calculate_icons(node)
|
||||
for _, s in pairs(git_xy) do
|
||||
local icons = self.icons_by_xy[s]
|
||||
if not icons then
|
||||
if self.hl_pos == HL_POSITION.none then
|
||||
if self.range == "none" then
|
||||
notify.warn(string.format("Unrecognized git state '%s'", git_xy))
|
||||
end
|
||||
return nil
|
||||
@@ -197,7 +191,7 @@ end
|
||||
---@param node Node
|
||||
---@return string|nil name
|
||||
function DecoratorGit:sign_name(node)
|
||||
if self.icon_placement ~= ICON_PLACEMENT.signcolumn then
|
||||
if self.icon_placement ~= "signcolumn" then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -211,7 +205,7 @@ end
|
||||
---@param node Node
|
||||
---@return string|nil group
|
||||
function DecoratorGit:calculate_highlight(node)
|
||||
if not node or not self.enabled or self.hl_pos == HL_POSITION.none then
|
||||
if not node or not self.enabled or self.range == "none" then
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
@@ -1,36 +1,30 @@
|
||||
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")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
---@class (exact) DecoratorHidden: Decorator
|
||||
---@field icon HighlightedString?
|
||||
local DecoratorHidden = Decorator:new()
|
||||
local DecoratorHidden = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorHidden
|
||||
function DecoratorHidden:create(opts, explorer)
|
||||
---@type DecoratorHidden
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
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,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorHidden
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorHidden
|
||||
|
||||
if opts.renderer.icons.show.hidden then
|
||||
o.icon = {
|
||||
str = opts.renderer.icons.glyphs.hidden,
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorHidden:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_hidden or "none",
|
||||
icon_placement = args.explorer.opts.renderer.icons.hidden_placement or "none",
|
||||
})
|
||||
|
||||
if self.explorer.opts.renderer.icons.show.hidden then
|
||||
self.icon = {
|
||||
str = self.explorer.opts.renderer.icons.glyphs.hidden,
|
||||
hl = { "NvimTreeHiddenIcon" },
|
||||
}
|
||||
o:define_sign(o.icon)
|
||||
self:define_sign(self.icon)
|
||||
end
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Hidden icon: renderer.icons.show.hidden and node starts with `.` (dotfile).
|
||||
@@ -46,7 +40,7 @@ end
|
||||
---@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 node:is_dotfile() then
|
||||
if not self.enabled or self.range == "none" or not node:is_dotfile() then
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
local Class = require("nvim-tree.class")
|
||||
local Class = require("nvim-tree.classic")
|
||||
|
||||
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
|
||||
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
|
||||
---@alias DecoratorRange "none" | "icon" | "name" | "all"
|
||||
---@alias DecoratorIconPlacement "none" | "before" | "after" | "signcolumn" | "right_align"
|
||||
|
||||
---Abstract Decorator
|
||||
---Uses the factory pattern to instantiate child instances.
|
||||
---@class (exact) Decorator: Class
|
||||
---@field protected explorer Explorer
|
||||
---@field protected enabled boolean
|
||||
---@field protected hl_pos HL_POSITION
|
||||
---@field protected icon_placement ICON_PLACEMENT
|
||||
local Decorator = Class:new()
|
||||
---@field protected range DecoratorRange
|
||||
---@field protected icon_placement DecoratorIconPlacement
|
||||
local Decorator = Class:extend()
|
||||
|
||||
---@class (exact) DecoratorArgs
|
||||
---@field explorer Explorer
|
||||
|
||||
---@class (exact) AbstractDecoratorArgs: DecoratorArgs
|
||||
---@field enabled boolean
|
||||
---@field hl_pos DecoratorRange
|
||||
---@field icon_placement DecoratorIconPlacement
|
||||
|
||||
---@protected
|
||||
---@param args AbstractDecoratorArgs
|
||||
function Decorator:new(args)
|
||||
self.explorer = args.explorer
|
||||
self.enabled = args.enabled
|
||||
self.range = args.hl_pos
|
||||
self.icon_placement = args.icon_placement
|
||||
end
|
||||
|
||||
---Maybe highlight groups
|
||||
---@param node Node
|
||||
@@ -19,13 +36,13 @@ local Decorator = Class:new()
|
||||
function Decorator:groups_icon_name(node)
|
||||
local icon_hl, name_hl
|
||||
|
||||
if self.enabled and self.hl_pos ~= HL_POSITION.none then
|
||||
if self.enabled and self.range ~= "none" then
|
||||
local hl = self:calculate_highlight(node)
|
||||
|
||||
if self.hl_pos == HL_POSITION.all or self.hl_pos == HL_POSITION.icon then
|
||||
if self.range == "all" or self.range == "icon" then
|
||||
icon_hl = hl
|
||||
end
|
||||
if self.hl_pos == HL_POSITION.all or self.hl_pos == HL_POSITION.name then
|
||||
if self.range == "all" or self.range == "name" then
|
||||
name_hl = hl
|
||||
end
|
||||
end
|
||||
@@ -37,7 +54,7 @@ end
|
||||
---@param node Node
|
||||
---@return string|nil name
|
||||
function Decorator:sign_name(node)
|
||||
if not self.enabled or self.icon_placement ~= ICON_PLACEMENT.signcolumn then
|
||||
if not self.enabled or self.icon_placement ~= "signcolumn" then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -47,33 +64,33 @@ function Decorator:sign_name(node)
|
||||
end
|
||||
end
|
||||
|
||||
---Icons when ICON_PLACEMENT.before
|
||||
---Icons when "before"
|
||||
---@param node Node
|
||||
---@return HighlightedString[]|nil icons
|
||||
function Decorator:icons_before(node)
|
||||
if not self.enabled or self.icon_placement ~= ICON_PLACEMENT.before then
|
||||
if not self.enabled or self.icon_placement ~= "before" then
|
||||
return
|
||||
end
|
||||
|
||||
return self:calculate_icons(node)
|
||||
end
|
||||
|
||||
---Icons when ICON_PLACEMENT.after
|
||||
---Icons when "after"
|
||||
---@param node Node
|
||||
---@return HighlightedString[]|nil icons
|
||||
function Decorator:icons_after(node)
|
||||
if not self.enabled or self.icon_placement ~= ICON_PLACEMENT.after then
|
||||
if not self.enabled or self.icon_placement ~= "after" then
|
||||
return
|
||||
end
|
||||
|
||||
return self:calculate_icons(node)
|
||||
end
|
||||
|
||||
---Icons when ICON_PLACEMENT.right_align
|
||||
---Icons when "right_align"
|
||||
---@param node Node
|
||||
---@return HighlightedString[]|nil icons
|
||||
function Decorator:icons_right_align(node)
|
||||
if not self.enabled or self.icon_placement ~= ICON_PLACEMENT.right_align then
|
||||
if not self.enabled or self.icon_placement ~= "right_align" then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -109,7 +126,7 @@ function Decorator:define_sign(icon)
|
||||
|
||||
-- don't use sign if not defined
|
||||
if #icon.str < 1 then
|
||||
self.icon_placement = ICON_PLACEMENT.none
|
||||
self.icon_placement = "none"
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -1,42 +1,36 @@
|
||||
local buffers = require("nvim-tree.buffers")
|
||||
|
||||
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")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
---@class (exact) DecoratorModified: Decorator
|
||||
---@field icon HighlightedString|nil
|
||||
local DecoratorModified = Decorator:new()
|
||||
---@field icon HighlightedString?
|
||||
local DecoratorModified = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorModified
|
||||
function DecoratorModified:create(opts, explorer)
|
||||
---@type DecoratorModified
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = opts.modified.enable,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_modified] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[opts.renderer.icons.modified_placement] or ICON_PLACEMENT.none,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorModified
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorModified
|
||||
|
||||
if not o.enabled then
|
||||
return o
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorModified:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_modified or "none",
|
||||
icon_placement = args.explorer.opts.renderer.icons.modified_placement or "none",
|
||||
})
|
||||
|
||||
if not self.enabled then
|
||||
return
|
||||
end
|
||||
|
||||
if opts.renderer.icons.show.modified then
|
||||
o.icon = {
|
||||
str = opts.renderer.icons.glyphs.modified,
|
||||
if self.explorer.opts.renderer.icons.show.modified then
|
||||
self.icon = {
|
||||
str = self.explorer.opts.renderer.icons.glyphs.modified,
|
||||
hl = { "NvimTreeModifiedIcon" },
|
||||
}
|
||||
o:define_sign(o.icon)
|
||||
self:define_sign(self.icon)
|
||||
end
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Modified icon: modified.enable, renderer.icons.show.modified and node is modified
|
||||
@@ -52,7 +46,7 @@ end
|
||||
---@param node Node
|
||||
---@return string|nil group
|
||||
function DecoratorModified:calculate_highlight(node)
|
||||
if not self.enabled or self.hl_pos == HL_POSITION.none or not buffers.is_modified(node) then
|
||||
if not self.enabled or self.range == "none" or not buffers.is_modified(node) then
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
@@ -1,36 +1,30 @@
|
||||
local buffers = require("nvim-tree.buffers")
|
||||
|
||||
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 (exact) DecoratorOpened: Decorator
|
||||
---@field icon HighlightedString|nil
|
||||
local DecoratorOpened = Decorator:new()
|
||||
local DecoratorOpened = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorOpened
|
||||
function DecoratorOpened:create(opts, explorer)
|
||||
---@type DecoratorOpened
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_opened_files] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT.none,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorOpened
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorOpened
|
||||
|
||||
return o
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorOpened:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_opened_files or "none",
|
||||
icon_placement = "none",
|
||||
})
|
||||
end
|
||||
|
||||
---Opened highlight: renderer.highlight_opened_files and node has an open buffer
|
||||
---@param node Node
|
||||
---@return string|nil group
|
||||
function DecoratorOpened:calculate_highlight(node)
|
||||
if self.hl_pos ~= HL_POSITION.none and buffers.is_opened(node) then
|
||||
if self.range ~= "none" and buffers.is_opened(node) then
|
||||
return "NvimTreeOpenedHL"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user