feat(#2948): tidy decorator args and complete documentation
This commit is contained in:
parent
cb351ae1de
commit
4bf4a85b9f
@ -52,14 +52,15 @@ CONTENTS *nvim-tree*
|
|||||||
8.2 Highlight: Overhaul |nvim-tree-highlight-overhaul|
|
8.2 Highlight: Overhaul |nvim-tree-highlight-overhaul|
|
||||||
9. Events |nvim-tree-events|
|
9. Events |nvim-tree-events|
|
||||||
10. Prompts |nvim-tree-prompts|
|
10. Prompts |nvim-tree-prompts|
|
||||||
11. OS Specific Restrictions |nvim-tree-os-specific|
|
11. Decorators |nvim-tree-decorators|
|
||||||
12. Netrw |nvim-tree-netrw|
|
12. OS Specific Restrictions |nvim-tree-os-specific|
|
||||||
13. Legacy |nvim-tree-legacy|
|
13. Netrw |nvim-tree-netrw|
|
||||||
13.1 Legacy: Opts |nvim-tree-legacy-opts|
|
14. Legacy |nvim-tree-legacy|
|
||||||
13.2 Legacy: Highlight |nvim-tree-legacy-highlight|
|
14.1 Legacy: Opts |nvim-tree-legacy-opts|
|
||||||
14. Index |nvim-tree-index|
|
14.2 Legacy: Highlight |nvim-tree-legacy-highlight|
|
||||||
14.1 Index: Opts |nvim-tree-index-opts|
|
15. Index |nvim-tree-index|
|
||||||
14.2 Index: API |nvim-tree-index-api|
|
15.1 Index: Opts |nvim-tree-index-opts|
|
||||||
|
15.2 Index: API |nvim-tree-index-api|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
1. INTRODUCTION *nvim-tree-introduction*
|
1. INTRODUCTION *nvim-tree-introduction*
|
||||||
@ -843,9 +844,6 @@ Use nvim-tree in a floating window.
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
5.3 OPTS: RENDERER *nvim-tree-opts-renderer*
|
5.3 OPTS: RENDERER *nvim-tree-opts-renderer*
|
||||||
|
|
||||||
Highlight precedence, additive, change via |nvim-tree.renderer.decorators|
|
|
||||||
git < opened < modified < bookmarked < diagnostics < copied < cut
|
|
||||||
|
|
||||||
*nvim-tree.renderer.add_trailing*
|
*nvim-tree.renderer.add_trailing*
|
||||||
Appends a trailing slash to folder names.
|
Appends a trailing slash to folder names.
|
||||||
Type: `boolean`, Default: `false`
|
Type: `boolean`, Default: `false`
|
||||||
@ -1013,9 +1011,6 @@ Configuration options for tree indent markers.
|
|||||||
*nvim-tree.renderer.icons*
|
*nvim-tree.renderer.icons*
|
||||||
Configuration options for icons.
|
Configuration options for icons.
|
||||||
|
|
||||||
Icon order and sign column precedence, change via |nvim-tree.renderer.decorators|
|
|
||||||
git < hidden < modified < bookmarked < diagnostics
|
|
||||||
|
|
||||||
`renderer.icons.*_placement` options may be:
|
`renderer.icons.*_placement` options may be:
|
||||||
- `"before"` : before file/folder, after the file/folders icons
|
- `"before"` : before file/folder, after the file/folders icons
|
||||||
- `"after"` : after file/folder
|
- `"after"` : after file/folder
|
||||||
@ -2772,7 +2767,90 @@ configurations for different types of prompts.
|
|||||||
send all bookmarked to trash during |nvim-tree-api.marks.bulk.trash()|
|
send all bookmarked to trash during |nvim-tree-api.marks.bulk.trash()|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
11. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific*
|
11. DECORATORS *nvim-tree-decorators*
|
||||||
|
|
||||||
|
Highlighting and icons for nodes are is provided by Decorators. You may provide
|
||||||
|
your own in addition to the builtin decorators.
|
||||||
|
|
||||||
|
Decorators may:
|
||||||
|
- Add icons
|
||||||
|
- Set highlight group for the name or icons
|
||||||
|
- Override node icon
|
||||||
|
|
||||||
|
Create your decorator class via `api.decorator.DecoratorUser:extend()` and add it
|
||||||
|
to |nvim-tree.renderer.decorators|
|
||||||
|
|
||||||
|
e.g. default decorators with an user decorator being overridden only by Cut: >lua
|
||||||
|
{
|
||||||
|
"Git",
|
||||||
|
"Opened",
|
||||||
|
"Hidden",
|
||||||
|
"Modified",
|
||||||
|
"Bookmarks",
|
||||||
|
"Diagnostics",
|
||||||
|
"Copied",
|
||||||
|
MyDecorator,
|
||||||
|
"Cut",
|
||||||
|
}
|
||||||
|
<
|
||||||
|
See `api_decorator.lua` for decorator class definition and full documentation.
|
||||||
|
|
||||||
|
Example decorator: >lua
|
||||||
|
|
||||||
|
---Create your decorator class
|
||||||
|
---@class (exact) MyDecorator: nvim_tree.api.decorator.DecoratorUser
|
||||||
|
---@field private my_icon nvim_tree.api.HighlightedString
|
||||||
|
local MyDecorator = require("nvim-tree.api").decorator.DecoratorUser:extend()
|
||||||
|
|
||||||
|
---Mandatory constructor :new() will be called once per tree render, with no arguments.
|
||||||
|
function MyDecorator:new()
|
||||||
|
self.enabled = true
|
||||||
|
self.highlight_range = "all"
|
||||||
|
self.icon_placement = "signcolumn"
|
||||||
|
|
||||||
|
-- create your icon once, for convenience
|
||||||
|
self.my_icon = { str = "I", hl = { "MyIcon" } }
|
||||||
|
|
||||||
|
-- Define the icon sign only once
|
||||||
|
-- Only needed if you are using icon_placement = "signcolumn"
|
||||||
|
self:define_sign(self.my_icon)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Override node icon
|
||||||
|
---@param node nvim_tree.api.Node
|
||||||
|
---@return nvim_tree.api.HighlightedString? icon_node
|
||||||
|
function MyDecorator:icon_node(node)
|
||||||
|
if node.name == "example" then
|
||||||
|
return self.my_icon
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Return one icon for DecoratorIconPlacement
|
||||||
|
---@param node nvim_tree.api.Node
|
||||||
|
---@return nvim_tree.api.HighlightedString[]? icons
|
||||||
|
function MyDecorator:icons(node)
|
||||||
|
if node.name == "example" then
|
||||||
|
return { self.my_icon }
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Exactly one highlight group for DecoratorHighlightRange
|
||||||
|
---@param node nvim_tree.api.Node
|
||||||
|
---@return string? highlight_group
|
||||||
|
function MyDecorator:highlight_group(node)
|
||||||
|
if node.name == "example" then
|
||||||
|
return "MyHighlight"
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
<
|
||||||
|
==============================================================================
|
||||||
|
12. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific*
|
||||||
|
|
||||||
Windows WSL and PowerShell
|
Windows WSL and PowerShell
|
||||||
- Trash is synchronized
|
- Trash is synchronized
|
||||||
@ -2784,7 +2862,7 @@ Windows WSL and PowerShell
|
|||||||
issues or disable this feature.
|
issues or disable this feature.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
12. NETRW *nvim-tree-netrw*
|
13. NETRW *nvim-tree-netrw*
|
||||||
|
|
||||||
|netrw| is a standard neovim plugin that is enabled by default. It provides,
|
|netrw| is a standard neovim plugin that is enabled by default. It provides,
|
||||||
amongst other functionality, a file/directory browser.
|
amongst other functionality, a file/directory browser.
|
||||||
@ -2805,14 +2883,14 @@ keep using |netrw| without its browser features please ensure:
|
|||||||
|nvim-tree.hijack_netrw| ` = true`
|
|nvim-tree.hijack_netrw| ` = true`
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
13. LEGACY *nvim-tree-legacy*
|
14. LEGACY *nvim-tree-legacy*
|
||||||
|
|
||||||
Breaking refactors have been made however the legacy versions will be silently
|
Breaking refactors have been made however the legacy versions will be silently
|
||||||
migrated and used.
|
migrated and used.
|
||||||
There are no plans to remove this migration.
|
There are no plans to remove this migration.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
13.1 LEGACY: OPTS *nvim-tree-legacy-opts*
|
14.1 LEGACY: OPTS *nvim-tree-legacy-opts*
|
||||||
|
|
||||||
Legacy options are translated to the current, making type and value changes as
|
Legacy options are translated to the current, making type and value changes as
|
||||||
needed.
|
needed.
|
||||||
@ -2830,7 +2908,7 @@ needed.
|
|||||||
`renderer.icons.webdev_colors` |nvim-tree.renderer.icons.web_devicons.file.color|
|
`renderer.icons.webdev_colors` |nvim-tree.renderer.icons.web_devicons.file.color|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
13.2 LEGACY: HIGHLIGHT *nvim-tree-legacy-highlight*
|
14.2 LEGACY: HIGHLIGHT *nvim-tree-legacy-highlight*
|
||||||
|
|
||||||
Legacy highlight group are still obeyed when they are defined and the current
|
Legacy highlight group are still obeyed when they are defined and the current
|
||||||
highlight group is not, hard linking as follows: >
|
highlight group is not, hard linking as follows: >
|
||||||
@ -2879,10 +2957,10 @@ highlight group is not, hard linking as follows: >
|
|||||||
NvimTreeLspDiagnosticsHintFolderText NvimTreeDiagnosticHintFolderHL
|
NvimTreeLspDiagnosticsHintFolderText NvimTreeDiagnosticHintFolderHL
|
||||||
<
|
<
|
||||||
==============================================================================
|
==============================================================================
|
||||||
14 INDEX *nvim-tree-index*
|
15 INDEX *nvim-tree-index*
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
14.1 INDEX: OPTS *nvim-tree-index-opts*
|
15.1 INDEX: OPTS *nvim-tree-index-opts*
|
||||||
|
|
||||||
|nvim-tree.actions.change_dir|
|
|nvim-tree.actions.change_dir|
|
||||||
|nvim-tree.actions.change_dir.enable|
|
|nvim-tree.actions.change_dir.enable|
|
||||||
@ -3051,7 +3129,7 @@ highlight group is not, hard linking as follows: >
|
|||||||
|nvim-tree.view.width.padding|
|
|nvim-tree.view.width.padding|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
14.2 INDEX: API *nvim-tree-index-api*
|
15.2 INDEX: API *nvim-tree-index-api*
|
||||||
|
|
||||||
|nvim-tree-api.commands.get()|
|
|nvim-tree-api.commands.get()|
|
||||||
|nvim-tree-api.config.mappings.default_on_attach()|
|
|nvim-tree-api.config.mappings.default_on_attach()|
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
---@meta
|
|
||||||
error("Cannot require a meta file")
|
|
||||||
|
|
||||||
--
|
|
||||||
--Internal convenience aliases for api types
|
|
||||||
--
|
|
||||||
|
|
||||||
--
|
|
||||||
--api.lua
|
|
||||||
--
|
|
||||||
|
|
||||||
---@alias HighlightedString nvim_tree.api.HighlightedString
|
|
||||||
|
|
||||||
--
|
|
||||||
--api_decorator.lua
|
|
||||||
--
|
|
||||||
|
|
||||||
---@alias DecoratorHighlightRange nvim_tree.api.decorator.HighlightRange
|
|
||||||
---@alias DecoratorIconPlacement nvim_tree.api.decorator.IconPlacement
|
|
||||||
@ -1,19 +1,7 @@
|
|||||||
---@meta
|
---@meta
|
||||||
error("Cannot require a meta file")
|
error("Cannot require a meta file")
|
||||||
|
|
||||||
local nvim_tree = { api = { decorator = { DecoratorUser = {} } } }
|
local nvim_tree = {}
|
||||||
|
|
||||||
---Custom decorator
|
|
||||||
---It may:
|
|
||||||
--- Add icons
|
|
||||||
--- Set highlight group for the name or icons
|
|
||||||
--- Override node icon
|
|
||||||
---Register it via :help nvim-tree.renderer.decorators
|
|
||||||
---Create class via require("nvim-tree.api").decorator.DecoratorUser:extend()
|
|
||||||
---Mandatory constructor :new() will be called once per tree render, with no arguments.
|
|
||||||
---Constructor must call:
|
|
||||||
--- :init
|
|
||||||
--- :define_sign when using "signcolumn" range
|
|
||||||
|
|
||||||
---Highlight group range as per nvim-tree.renderer.highlight_*
|
---Highlight group range as per nvim-tree.renderer.highlight_*
|
||||||
---@alias nvim_tree.api.decorator.HighlightRange "none" | "icon" | "name" | "all"
|
---@alias nvim_tree.api.decorator.HighlightRange "none" | "icon" | "name" | "all"
|
||||||
@ -24,27 +12,28 @@ local nvim_tree = { api = { decorator = { DecoratorUser = {} } } }
|
|||||||
---Names of builtin decorators or your decorator classes. Builtins are ordered lowest to highest priority.
|
---Names of builtin decorators or your decorator classes. Builtins are ordered lowest to highest priority.
|
||||||
---@alias nvim_tree.api.decorator.Name "Git" | "Opened" | "Hidden" | "Modified" | "Bookmarks" | "Diagnostics" | "Copied" | "Cut" | nvim_tree.api.decorator.DecoratorUser
|
---@alias nvim_tree.api.decorator.Name "Git" | "Opened" | "Hidden" | "Modified" | "Bookmarks" | "Diagnostics" | "Copied" | "Cut" | nvim_tree.api.decorator.DecoratorUser
|
||||||
|
|
||||||
---Your decorator will extend this class via require("nvim-tree.api").decorator.DecoratorUser:extend()
|
---Custom decorator, see :help nvim-tree-decorators
|
||||||
---
|
---
|
||||||
---@class (exact) nvim_tree.api.decorator.DecoratorUser
|
---@class (exact) nvim_tree.api.decorator.DecoratorUser
|
||||||
---@field protected enabled boolean
|
---@field protected enabled boolean
|
||||||
---@field protected highlight_range nvim_tree.api.decorator.HighlightRange
|
---@field protected highlight_range nvim_tree.api.decorator.HighlightRange
|
||||||
---@field protected icon_placement nvim_tree.api.decorator.IconPlacement
|
---@field protected icon_placement nvim_tree.api.decorator.IconPlacement
|
||||||
|
|
||||||
---Abstract: no-args constructor must be implemented.
|
---Abstract: no-args constructor must be implemented and will be called once per tree render.
|
||||||
|
---Must set all fields.
|
||||||
---
|
---
|
||||||
function nvim_tree.api.decorator.DecoratorUser:new() end
|
function nvim_tree.api.decorator.DecoratorUser:new() end
|
||||||
|
|
||||||
---Abstract: optionally implement to set the node's icon
|
---Abstract: optionally implement to set the node's icon
|
||||||
---
|
---
|
||||||
---@param node nvim_tree.api.Node
|
---@param node nvim_tree.api.Node
|
||||||
---@return HighlightedString? icon_node
|
---@return nvim_tree.api.HighlightedString? icon_node
|
||||||
function nvim_tree.api.decorator.DecoratorUser:icon_node(node) end
|
function nvim_tree.api.decorator.DecoratorUser:icon_node(node) end
|
||||||
|
|
||||||
---Abstract: optionally implement to provide icons and the highlight groups for your icon_placement.
|
---Abstract: optionally implement to provide icons and the highlight groups for your icon_placement.
|
||||||
---
|
---
|
||||||
---@param node nvim_tree.api.Node
|
---@param node nvim_tree.api.Node
|
||||||
---@return HighlightedString[]? icons
|
---@return nvim_tree.api.HighlightedString[]? icons
|
||||||
function nvim_tree.api.decorator.DecoratorUser:icons(node) end
|
function nvim_tree.api.decorator.DecoratorUser:icons(node) end
|
||||||
|
|
||||||
---Abstract: optionally implement to provide one highlight group to apply to your highlight_range.
|
---Abstract: optionally implement to provide one highlight group to apply to your highlight_range.
|
||||||
@ -53,81 +42,8 @@ function nvim_tree.api.decorator.DecoratorUser:icons(node) end
|
|||||||
---@return string? highlight_group
|
---@return string? highlight_group
|
||||||
function nvim_tree.api.decorator.DecoratorUser:highlight_group(node) end
|
function nvim_tree.api.decorator.DecoratorUser:highlight_group(node) end
|
||||||
|
|
||||||
---Must be called from your constructor.
|
|
||||||
---
|
|
||||||
---@class (exact) nvim_tree.api.decorator.InitArgs
|
|
||||||
---@field enabled boolean
|
|
||||||
---@field highlight_range nvim_tree.api.decorator.HighlightRange
|
|
||||||
---@field icon_placement nvim_tree.api.decorator.IconPlacement
|
|
||||||
---
|
|
||||||
---@protected
|
|
||||||
---@param args nvim_tree.api.decorator.InitArgs
|
|
||||||
function nvim_tree.api.decorator.DecoratorUser:init(args) end
|
|
||||||
|
|
||||||
---Define a sign. This should be called in the constructor.
|
---Define a sign. This should be called in the constructor.
|
||||||
---
|
---
|
||||||
---@protected
|
---@protected
|
||||||
---@param icon HighlightedString?
|
---@param icon nvim_tree.api.HighlightedString?
|
||||||
function nvim_tree.api.decorator.DecoratorUser:define_sign(icon) end
|
function nvim_tree.api.decorator.DecoratorUser:define_sign(icon) end
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Example Decorator
|
|
||||||
--
|
|
||||||
|
|
||||||
---@class (exact) MyDecorator: nvim_tree.api.decorator.DecoratorUser
|
|
||||||
---@field private my_icon nvim_tree.api.HighlightedString
|
|
||||||
local MyDecorator = require("nvim-tree.api").decorator.DecoratorUser:extend()
|
|
||||||
|
|
||||||
---Mandatory constructor :new() will be called once per tree render, with no arguments.
|
|
||||||
function MyDecorator:new()
|
|
||||||
---@type nvim_tree.api.decorator.InitArgs
|
|
||||||
local args = {
|
|
||||||
enabled = true,
|
|
||||||
highlight_range = "all",
|
|
||||||
icon_placement = "signcolumn",
|
|
||||||
}
|
|
||||||
|
|
||||||
-- init
|
|
||||||
self:init(args)
|
|
||||||
|
|
||||||
-- create your icon once, for convenience
|
|
||||||
self.my_icon = { str = "I", hl = { "MyIcon" } }
|
|
||||||
|
|
||||||
-- Define the icon sign only once
|
|
||||||
-- Only needed if you are using icon_placement = "signcolumn"
|
|
||||||
self:define_sign(self.my_icon)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Override node icon
|
|
||||||
---@param node nvim_tree.api.Node
|
|
||||||
---@return nvim_tree.api.HighlightedString? icon_node
|
|
||||||
function MyDecorator:icon_node(node)
|
|
||||||
if node.name == "example" then
|
|
||||||
return self.my_icon
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---Return one icon for DecoratorIconPlacement
|
|
||||||
---@param node nvim_tree.api.Node
|
|
||||||
---@return nvim_tree.api.HighlightedString[]? icons
|
|
||||||
function MyDecorator:icons(node)
|
|
||||||
if node.name == "example" then
|
|
||||||
return { self.my_icon }
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---Exactly one highlight group for DecoratorHighlightRange
|
|
||||||
---@param node nvim_tree.api.Node
|
|
||||||
---@return string? highlight_group
|
|
||||||
function MyDecorator:highlight_group(node)
|
|
||||||
if node.name == "example" then
|
|
||||||
return "MyHighlight"
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
@ -313,7 +313,7 @@ Api.commands.get = wrap(function()
|
|||||||
return require("nvim-tree.commands").get()
|
return require("nvim-tree.commands").get()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---User provided decorator. Extend this class via :extend()
|
---Create a decorator class by calling :extend()
|
||||||
---@type nvim_tree.api.decorator.DecoratorUser
|
---@type nvim_tree.api.decorator.DecoratorUser
|
||||||
Api.decorator.DecoratorUser = DecoratorUser --[[@as nvim_tree.api.decorator.DecoratorUser]]
|
Api.decorator.DecoratorUser = DecoratorUser --[[@as nvim_tree.api.decorator.DecoratorUser]]
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,8 @@ local DecoratorUser = require("nvim-tree.renderer.decorator.user")
|
|||||||
|
|
||||||
local pad = require("nvim-tree.renderer.components.padding")
|
local pad = require("nvim-tree.renderer.components.padding")
|
||||||
|
|
||||||
|
---@alias HighlightedString nvim_tree.api.HighlightedString
|
||||||
|
|
||||||
-- Builtin Decorators
|
-- Builtin Decorators
|
||||||
---@type table<nvim_tree.api.decorator.Name, Decorator>
|
---@type table<nvim_tree.api.decorator.Name, Decorator>
|
||||||
local BUILTIN_DECORATORS = {
|
local BUILTIN_DECORATORS = {
|
||||||
|
|||||||
@ -11,16 +11,11 @@ local DecoratorBookmarks = Decorator:extend()
|
|||||||
---@protected
|
---@protected
|
||||||
---@param args DecoratorArgs
|
---@param args DecoratorArgs
|
||||||
function DecoratorBookmarks:new(args)
|
function DecoratorBookmarks:new(args)
|
||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
|
|
||||||
---@type AbstractDecoratorArgs
|
self.enabled = true
|
||||||
local a = {
|
self.highlight_range = self.explorer.opts.renderer.highlight_bookmarks or "none"
|
||||||
enabled = true,
|
self.icon_placement = self.explorer.opts.renderer.icons.bookmarks_placement or "none"
|
||||||
highlight_range = self.explorer.opts.renderer.highlight_bookmarks or "none",
|
|
||||||
icon_placement = self.explorer.opts.renderer.icons.bookmarks_placement or "none",
|
|
||||||
}
|
|
||||||
|
|
||||||
DecoratorBookmarks.super.new(self, a)
|
|
||||||
|
|
||||||
if self.explorer.opts.renderer.icons.show.bookmarks then
|
if self.explorer.opts.renderer.icons.show.bookmarks then
|
||||||
self.icon = {
|
self.icon = {
|
||||||
|
|||||||
@ -10,16 +10,11 @@ local DecoratorCopied = Decorator:extend()
|
|||||||
---@protected
|
---@protected
|
||||||
---@param args DecoratorArgs
|
---@param args DecoratorArgs
|
||||||
function DecoratorCopied:new(args)
|
function DecoratorCopied:new(args)
|
||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
|
|
||||||
---@type AbstractDecoratorArgs
|
self.enabled = true
|
||||||
local a = {
|
self.highlight_range = self.explorer.opts.renderer.highlight_clipboard or "none"
|
||||||
enabled = true,
|
self.icon_placement = "none"
|
||||||
highlight_range = self.explorer.opts.renderer.highlight_clipboard or "none",
|
|
||||||
icon_placement = "none",
|
|
||||||
}
|
|
||||||
|
|
||||||
DecoratorCopied.super.new(self, a)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Copied highlight: renderer.highlight_clipboard and node is copied
|
---Copied highlight: renderer.highlight_clipboard and node is copied
|
||||||
|
|||||||
@ -10,16 +10,11 @@ local DecoratorCut = Decorator:extend()
|
|||||||
---@protected
|
---@protected
|
||||||
---@param args DecoratorArgs
|
---@param args DecoratorArgs
|
||||||
function DecoratorCut:new(args)
|
function DecoratorCut:new(args)
|
||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
|
|
||||||
---@type AbstractDecoratorArgs
|
self.enabled = true
|
||||||
local a = {
|
self.highlight_range = self.explorer.opts.renderer.highlight_clipboard or "none"
|
||||||
enabled = true,
|
self.icon_placement = "none"
|
||||||
highlight_range = self.explorer.opts.renderer.highlight_clipboard or "none",
|
|
||||||
icon_placement = "none",
|
|
||||||
}
|
|
||||||
|
|
||||||
DecoratorCut.super.new(self, a)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Cut highlight: renderer.highlight_clipboard and node is cut
|
---Cut highlight: renderer.highlight_clipboard and node is cut
|
||||||
|
|||||||
@ -41,20 +41,11 @@ local DecoratorDiagnostics = Decorator:extend()
|
|||||||
---@protected
|
---@protected
|
||||||
---@param args DecoratorArgs
|
---@param args DecoratorArgs
|
||||||
function DecoratorDiagnostics:new(args)
|
function DecoratorDiagnostics:new(args)
|
||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
|
|
||||||
---@type AbstractDecoratorArgs
|
self.enabled = true
|
||||||
local a = {
|
self.highlight_range = self.explorer.opts.renderer.highlight_diagnostics or "none"
|
||||||
enabled = true,
|
self.icon_placement = self.explorer.opts.renderer.icons.diagnostics_placement or "none"
|
||||||
highlight_range = self.explorer.opts.renderer.highlight_diagnostics or "none",
|
|
||||||
icon_placement = self.explorer.opts.renderer.icons.diagnostics_placement or "none",
|
|
||||||
}
|
|
||||||
|
|
||||||
DecoratorDiagnostics.super.new(self, a)
|
|
||||||
|
|
||||||
if not self.enabled then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.explorer.opts.renderer.icons.show.diagnostics then
|
if self.explorer.opts.renderer.icons.show.diagnostics then
|
||||||
self.diag_icons = {}
|
self.diag_icons = {}
|
||||||
@ -72,7 +63,7 @@ end
|
|||||||
---@param node Node
|
---@param node Node
|
||||||
---@return HighlightedString[]? icons
|
---@return HighlightedString[]? icons
|
||||||
function DecoratorDiagnostics:icons(node)
|
function DecoratorDiagnostics:icons(node)
|
||||||
if node and self.enabled and self.diag_icons then
|
if node and self.diag_icons then
|
||||||
local diag_status = diagnostics.get_diag_status(node)
|
local diag_status = diagnostics.get_diag_status(node)
|
||||||
local diag_value = diag_status and diag_status.value
|
local diag_value = diag_status and diag_status.value
|
||||||
|
|
||||||
@ -86,7 +77,7 @@ end
|
|||||||
---@param node Node
|
---@param node Node
|
||||||
---@return string? highlight_group
|
---@return string? highlight_group
|
||||||
function DecoratorDiagnostics:highlight_group(node)
|
function DecoratorDiagnostics:highlight_group(node)
|
||||||
if not node or not self.enabled or self.highlight_range == "none" then
|
if self.highlight_range == "none" then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -26,16 +26,11 @@ local DecoratorGit = Decorator:extend()
|
|||||||
---@protected
|
---@protected
|
||||||
---@param args DecoratorArgs
|
---@param args DecoratorArgs
|
||||||
function DecoratorGit:new(args)
|
function DecoratorGit:new(args)
|
||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
|
|
||||||
---@type AbstractDecoratorArgs
|
self.enabled = self.explorer.opts.git.enable
|
||||||
local a = {
|
self.highlight_range = self.explorer.opts.renderer.highlight_git or "none"
|
||||||
enabled = self.explorer.opts.git.enable,
|
self.icon_placement = self.explorer.opts.renderer.icons.git_placement or "none"
|
||||||
highlight_range = self.explorer.opts.renderer.highlight_git or "none",
|
|
||||||
icon_placement = self.explorer.opts.renderer.icons.git_placement or "none",
|
|
||||||
}
|
|
||||||
|
|
||||||
DecoratorGit.super.new(self, a)
|
|
||||||
|
|
||||||
if not self.enabled then
|
if not self.enabled then
|
||||||
return
|
return
|
||||||
@ -149,7 +144,7 @@ end
|
|||||||
---@param node Node
|
---@param node Node
|
||||||
---@return HighlightedString[]? icons
|
---@return HighlightedString[]? icons
|
||||||
function DecoratorGit:icons(node)
|
function DecoratorGit:icons(node)
|
||||||
if not node or not self.enabled or not self.icons_by_xy then
|
if not self.icons_by_xy then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -210,7 +205,7 @@ end
|
|||||||
---@param node Node
|
---@param node Node
|
||||||
---@return string? highlight_group
|
---@return string? highlight_group
|
||||||
function DecoratorGit:highlight_group(node)
|
function DecoratorGit:highlight_group(node)
|
||||||
if not node or not self.enabled or self.highlight_range == "none" then
|
if self.highlight_range == "none" then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -12,16 +12,11 @@ local DecoratorHidden = Decorator:extend()
|
|||||||
---@protected
|
---@protected
|
||||||
---@param args DecoratorArgs
|
---@param args DecoratorArgs
|
||||||
function DecoratorHidden:new(args)
|
function DecoratorHidden:new(args)
|
||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
|
|
||||||
---@type AbstractDecoratorArgs
|
self.enabled = true
|
||||||
local a = {
|
self.highlight_range = self.explorer.opts.renderer.highlight_hidden or "none"
|
||||||
enabled = true,
|
self.icon_placement = self.explorer.opts.renderer.icons.hidden_placement or "none"
|
||||||
highlight_range = self.explorer.opts.renderer.highlight_hidden or "none",
|
|
||||||
icon_placement = self.explorer.opts.renderer.icons.hidden_placement or "none",
|
|
||||||
}
|
|
||||||
|
|
||||||
DecoratorHidden.super.new(self, a)
|
|
||||||
|
|
||||||
if self.explorer.opts.renderer.icons.show.hidden then
|
if self.explorer.opts.renderer.icons.show.hidden then
|
||||||
self.icon = {
|
self.icon = {
|
||||||
@ -36,7 +31,7 @@ end
|
|||||||
---@param node Node
|
---@param node Node
|
||||||
---@return HighlightedString[]? icons
|
---@return HighlightedString[]? icons
|
||||||
function DecoratorHidden:icons(node)
|
function DecoratorHidden:icons(node)
|
||||||
if self.enabled and node:is_dotfile() then
|
if node:is_dotfile() then
|
||||||
return { self.icon }
|
return { self.icon }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -45,7 +40,7 @@ end
|
|||||||
---@param node Node
|
---@param node Node
|
||||||
---@return string? highlight_group
|
---@return string? highlight_group
|
||||||
function DecoratorHidden:highlight_group(node)
|
function DecoratorHidden:highlight_group(node)
|
||||||
if not self.enabled or self.highlight_range == "none" or not node:is_dotfile() then
|
if self.highlight_range == "none" or not node:is_dotfile() then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -3,29 +3,34 @@ local Class = require("nvim-tree.classic")
|
|||||||
---Abstract Decorator
|
---Abstract Decorator
|
||||||
---@class (exact) Decorator: Class
|
---@class (exact) Decorator: Class
|
||||||
---@field protected enabled boolean
|
---@field protected enabled boolean
|
||||||
---@field protected highlight_range DecoratorHighlightRange
|
---@field protected highlight_range nvim_tree.api.decorator.HighlightRange
|
||||||
---@field protected icon_placement DecoratorIconPlacement
|
---@field protected icon_placement nvim_tree.api.decorator.IconPlacement
|
||||||
local Decorator = Class:extend()
|
local Decorator = Class:extend()
|
||||||
|
|
||||||
---@class (exact) DecoratorArgs
|
---@class (exact) DecoratorArgs
|
||||||
---@field explorer Explorer
|
---@field explorer Explorer
|
||||||
|
|
||||||
---Abstract constructor
|
---Abstract icon override, optionally implemented
|
||||||
---@class (exact) AbstractDecoratorArgs
|
---@param node Node
|
||||||
---@field enabled boolean
|
---@return HighlightedString? icon_node
|
||||||
---@field highlight_range DecoratorHighlightRange
|
function Decorator:icon_node(node)
|
||||||
---@field icon_placement DecoratorIconPlacement
|
return self:nop(node)
|
||||||
---
|
end
|
||||||
|
|
||||||
|
---Abstract icons, optionally implemented
|
||||||
---@protected
|
---@protected
|
||||||
---@param args AbstractDecoratorArgs
|
---@param node Node
|
||||||
function Decorator:new(args)
|
---@return HighlightedString[]? icons
|
||||||
if args then
|
function Decorator:icons(node)
|
||||||
self.enabled = args.enabled
|
self:nop(node)
|
||||||
self.highlight_range = args.highlight_range
|
end
|
||||||
self.icon_placement = args.icon_placement
|
|
||||||
else
|
---Abstract highlight group, optionally implemented
|
||||||
self.enabled = false
|
---@protected
|
||||||
end
|
---@param node Node
|
||||||
|
---@return string? highlight_group
|
||||||
|
function Decorator:highlight_group(node)
|
||||||
|
self:nop(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Maybe highlight groups for icon and name
|
---Maybe highlight groups for icon and name
|
||||||
@ -96,29 +101,6 @@ function Decorator:icons_right_align(node)
|
|||||||
return self:icons(node)
|
return self:icons(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Maybe icon override, optionally implemented
|
|
||||||
---@param node Node
|
|
||||||
---@return HighlightedString? icon_node
|
|
||||||
function Decorator:icon_node(node)
|
|
||||||
return self:nop(node)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Maybe icons, optionally implemented
|
|
||||||
---@protected
|
|
||||||
---@param node Node
|
|
||||||
---@return HighlightedString[]? icons
|
|
||||||
function Decorator:icons(node)
|
|
||||||
self:nop(node)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Maybe highlight group, optionally implemented
|
|
||||||
---@protected
|
|
||||||
---@param node Node
|
|
||||||
---@return string? highlight_group
|
|
||||||
function Decorator:highlight_group(node)
|
|
||||||
self:nop(node)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Define a sign
|
---Define a sign
|
||||||
---@protected
|
---@protected
|
||||||
---@param icon HighlightedString?
|
---@param icon HighlightedString?
|
||||||
|
|||||||
@ -14,20 +14,11 @@ local DecoratorModified = Decorator:extend()
|
|||||||
---@protected
|
---@protected
|
||||||
---@param args DecoratorArgs
|
---@param args DecoratorArgs
|
||||||
function DecoratorModified:new(args)
|
function DecoratorModified:new(args)
|
||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
|
|
||||||
---@type AbstractDecoratorArgs
|
self.enabled = true
|
||||||
local a = {
|
self.highlight_range = self.explorer.opts.renderer.highlight_modified or "none"
|
||||||
enabled = true,
|
self.icon_placement = self.explorer.opts.renderer.icons.modified_placement or "none"
|
||||||
highlight_range = self.explorer.opts.renderer.highlight_modified or "none",
|
|
||||||
icon_placement = self.explorer.opts.renderer.icons.modified_placement or "none",
|
|
||||||
}
|
|
||||||
|
|
||||||
DecoratorModified.super.new(self, a)
|
|
||||||
|
|
||||||
if not self.enabled then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.explorer.opts.renderer.icons.show.modified then
|
if self.explorer.opts.renderer.icons.show.modified then
|
||||||
self.icon = {
|
self.icon = {
|
||||||
@ -42,7 +33,7 @@ end
|
|||||||
---@param node Node
|
---@param node Node
|
||||||
---@return HighlightedString[]? icons
|
---@return HighlightedString[]? icons
|
||||||
function DecoratorModified:icons(node)
|
function DecoratorModified:icons(node)
|
||||||
if self.enabled and buffers.is_modified(node) then
|
if buffers.is_modified(node) then
|
||||||
return { self.icon }
|
return { self.icon }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -51,7 +42,7 @@ end
|
|||||||
---@param node Node
|
---@param node Node
|
||||||
---@return string? highlight_group
|
---@return string? highlight_group
|
||||||
function DecoratorModified:highlight_group(node)
|
function DecoratorModified:highlight_group(node)
|
||||||
if not self.enabled or self.highlight_range == "none" or not buffers.is_modified(node) then
|
if self.highlight_range == "none" or not buffers.is_modified(node) then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -13,16 +13,11 @@ local DecoratorOpened = Decorator:extend()
|
|||||||
---@protected
|
---@protected
|
||||||
---@param args DecoratorArgs
|
---@param args DecoratorArgs
|
||||||
function DecoratorOpened:new(args)
|
function DecoratorOpened:new(args)
|
||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
|
|
||||||
---@type AbstractDecoratorArgs
|
self.enabled = true
|
||||||
local a = {
|
self.highlight_range = self.explorer.opts.renderer.highlight_opened_files or "none"
|
||||||
enabled = true,
|
self.icon_placement = "none"
|
||||||
highlight_range = self.explorer.opts.renderer.highlight_opened_files or "none",
|
|
||||||
icon_placement = "none",
|
|
||||||
}
|
|
||||||
|
|
||||||
DecoratorOpened.super.new(self, a)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Opened highlight: renderer.highlight_opened_files and node has an open buffer
|
---Opened highlight: renderer.highlight_opened_files and node has an open buffer
|
||||||
|
|||||||
@ -4,10 +4,4 @@ local Decorator = require("nvim-tree.renderer.decorator")
|
|||||||
---@class (exact) DecoratorUser: Decorator
|
---@class (exact) DecoratorUser: Decorator
|
||||||
local DecoratorUser = Decorator:extend()
|
local DecoratorUser = Decorator:extend()
|
||||||
|
|
||||||
---User calls this instead of new
|
|
||||||
---@param args nvim_tree.api.decorator.InitArgs
|
|
||||||
function DecoratorUser:init(args)
|
|
||||||
DecoratorUser.super.new(self, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
return DecoratorUser
|
return DecoratorUser
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user