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,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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user