replace enums with named maps
This commit is contained in:
parent
5d7e5434f3
commit
9af0dc487d
@ -1,24 +1,5 @@
|
||||
local M = {}
|
||||
|
||||
---Setup options for "highlight_*"
|
||||
---@enum HL_POSITION
|
||||
M.HL_POSITION = {
|
||||
none = 0,
|
||||
icon = 1,
|
||||
name = 2,
|
||||
all = 4,
|
||||
}
|
||||
|
||||
---Setup options for "*_placement"
|
||||
---@enum ICON_PLACEMENT
|
||||
M.ICON_PLACEMENT = {
|
||||
none = 0,
|
||||
signcolumn = 1,
|
||||
before = 2,
|
||||
after = 3,
|
||||
right_align = 4,
|
||||
}
|
||||
|
||||
---Reason for filter in filter.lua
|
||||
---@enum FILTER_REASON
|
||||
M.FILTER_REASON = {
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
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
|
||||
@ -16,8 +13,8 @@ function DecoratorBookmarks:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_bookmarks] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[args.explorer.opts.renderer.icons.bookmarks_placement] or ICON_PLACEMENT.none,
|
||||
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
|
||||
@ -42,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,6 +1,3 @@
|
||||
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
|
||||
@ -15,8 +12,8 @@ function DecoratorCopied:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_clipboard] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT.none,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_clipboard or "none",
|
||||
icon_placement = "none",
|
||||
})
|
||||
end
|
||||
|
||||
@ -24,7 +21,7 @@ end
|
||||
---@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,6 +1,3 @@
|
||||
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
|
||||
@ -15,8 +12,8 @@ function DecoratorCut:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_clipboard] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT.none,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_clipboard or "none",
|
||||
icon_placement = "none",
|
||||
})
|
||||
end
|
||||
|
||||
@ -24,7 +21,7 @@ end
|
||||
---@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")
|
||||
|
||||
@ -46,8 +43,8 @@ function DecoratorDiagnostics:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_diagnostics] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[args.explorer.opts.renderer.icons.diagnostics_placement] or ICON_PLACEMENT.none,
|
||||
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
|
||||
@ -84,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")
|
||||
|
||||
@ -31,15 +28,15 @@ function DecoratorGit:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = args.explorer.opts.git.enable,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_git] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[args.explorer.opts.renderer.icons.git_placement] or ICON_PLACEMENT.none,
|
||||
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 self.hl_pos ~= HL_POSITION.none then
|
||||
if self.range ~= "none" then
|
||||
self:build_file_folder_hl_by_xy()
|
||||
end
|
||||
|
||||
@ -162,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
|
||||
@ -194,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
|
||||
|
||||
@ -208,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,6 +1,3 @@
|
||||
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")
|
||||
|
||||
@ -17,8 +14,8 @@ function DecoratorHidden:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_hidden] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[args.explorer.opts.renderer.icons.hidden_placement] or ICON_PLACEMENT.none,
|
||||
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
|
||||
@ -43,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,15 +1,15 @@
|
||||
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
|
||||
---@field protected range DecoratorRange
|
||||
---@field protected icon_placement DecoratorIconPlacement
|
||||
local Decorator = Class:extend()
|
||||
|
||||
---@class (exact) DecoratorArgs
|
||||
@ -17,15 +17,15 @@ local Decorator = Class:extend()
|
||||
|
||||
---@class (exact) AbstractDecoratorArgs: DecoratorArgs
|
||||
---@field enabled boolean
|
||||
---@field hl_pos HL_POSITION
|
||||
---@field icon_placement ICON_PLACEMENT
|
||||
---@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.hl_pos = args.hl_pos
|
||||
self.range = args.hl_pos
|
||||
self.icon_placement = args.icon_placement
|
||||
end
|
||||
|
||||
@ -36,13 +36,13 @@ end
|
||||
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
|
||||
@ -54,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
|
||||
|
||||
@ -64,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
|
||||
|
||||
@ -126,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,8 +1,5 @@
|
||||
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")
|
||||
|
||||
@ -19,8 +16,8 @@ function DecoratorModified:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_modified] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[args.explorer.opts.renderer.icons.modified_placement] or ICON_PLACEMENT.none,
|
||||
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
|
||||
@ -49,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,8 +1,5 @@
|
||||
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
|
||||
@ -18,8 +15,8 @@ function DecoratorOpened:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_opened_files] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT.none,
|
||||
hl_pos = args.explorer.opts.renderer.highlight_opened_files or "none",
|
||||
icon_placement = "none",
|
||||
})
|
||||
end
|
||||
|
||||
@ -27,7 +24,7 @@ end
|
||||
---@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
|
||||
|
||||
@ -152,7 +152,6 @@ local function set_window_options_and_buffer()
|
||||
pcall(vim.api.nvim_command, "buffer " .. M.get_bufnr())
|
||||
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
|
||||
local eventignore = vim.api.nvim_get_option_value("eventignore", {})
|
||||
vim.api.nvim_set_option_value("eventignore", "all", {})
|
||||
|
||||
@ -161,9 +160,7 @@ local function set_window_options_and_buffer()
|
||||
end
|
||||
|
||||
vim.api.nvim_set_option_value("eventignore", eventignore, {})
|
||||
|
||||
else
|
||||
|
||||
local eventignore = vim.api.nvim_get_option("eventignore") ---@diagnostic disable-line: deprecated
|
||||
vim.api.nvim_set_option("eventignore", "all") ---@diagnostic disable-line: deprecated
|
||||
|
||||
@ -172,7 +169,6 @@ local function set_window_options_and_buffer()
|
||||
end
|
||||
|
||||
vim.api.nvim_set_option("eventignore", eventignore) ---@diagnostic disable-line: deprecated
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user