Skip to content

Commit ff41e83

Browse files
authored
Merge branch 'master' into fix/windows-path-resolution
2 parents 876b734 + 1df1960 commit ff41e83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1274
-663
lines changed

doc/nvim-tree-lua.txt

Lines changed: 480 additions & 198 deletions
Large diffs are not rendered by default.

lua/nvim-tree.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ local DEFAULT_OPTS = { -- default-config-start
462462
filesystem_watchers = {
463463
enable = true,
464464
debounce_delay = 50,
465-
max_events = 100,
465+
max_events = 1000,
466466
ignore_dirs = {
467467
"/.ccls-cache",
468468
"/build",
@@ -816,7 +816,7 @@ function M.setup(conf)
816816
vim.g.NvimTreeSetup = 1
817817
vim.api.nvim_exec_autocmds("User", { pattern = "NvimTreeSetup" })
818818

819-
require("nvim-tree.api.impl.post")(api)
819+
require("nvim-tree.api.impl.post").hydrate(api)
820820
end
821821

822822
vim.g.NvimTreeRequired = 1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---@meta
2-
local nvim_tree = { api = { health = {} } }
2+
local nvim_tree = { api = { appearance = {} } }
33

44
---
55
---Open a new buffer displaying all nvim-tree highlight groups, their link chain and concrete definition.
66
---
77
---Similar to `:so $VIMRUNTIME/syntax/hitest.vim` as per |:highlight|
88
---
9-
function nvim_tree.api.health.hi_test() end
9+
function nvim_tree.api.appearance.hi_test() end
1010

11-
return nvim_tree.api.health
11+
return nvim_tree.api.appearance
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---@meta
2+
3+
---@brief
4+
---Highlighting and icons for nodes are provided by Decorators, see [nvim-tree-icons-highlighting] for an overview.
5+
---
6+
---Decorators are rendered in [nvim_tree.config.renderer] {decorators} order of additive precedence, with later decorators applying additively over earlier.
7+
---
8+
---You may provide your own in addition to the builtin decorators, see |nvim-tree-class-decorator-example|.
9+
---
10+
---Decorators may:
11+
---- Add icons
12+
---- Set a highlight group name for the name or icons
13+
---- Override node icon
14+
---
15+
---To register your decorator:
16+
---- Create a class that extends [nvim_tree.api.Decorator]
17+
---- Register it by adding the class to [nvim_tree.config.renderer] {decorators}
18+
---
19+
---Your decorator will be constructed and executed each time the tree is rendered.
20+
---
21+
---Your class must:
22+
---- [nvim_tree.Class:extend()] the interface [nvim_tree.api.Decorator]
23+
---- Provide a no-arguments constructor [nvim_tree.Class:new()] that sets the mandatory fields:
24+
--- - {enabled}
25+
--- - {highlight_range}
26+
--- - {icon_placement}
27+
---- Call [nvim_tree.api.Decorator:define_sign()] in your constructor when {icon_placement} is `"signcolumn"`
28+
---
29+
---Your class may:
30+
---- Implement methods to provide decorations:
31+
--- - [nvim_tree.api.Decorator:highlight_group()]
32+
--- - [nvim_tree.api.Decorator:icon_node()]
33+
--- - [nvim_tree.api.Decorator:icons()]
34+
35+
local nvim_tree = { api = {} }
36+
37+
local Class = require("nvim-tree.classic")
38+
39+
---
40+
---Text or glyphs with optional highlight group names to apply to it.
41+
---
42+
---@class nvim_tree.api.highlighted_string
43+
---
44+
---One or many glyphs/characters.
45+
---@field str string
46+
---
47+
---Highlight group names to apply in order. Empty table for no highlighting.
48+
---@field hl string[]
49+
50+
51+
---
52+
---Decorator interface
53+
---
54+
---@class nvim_tree.api.Decorator: nvim_tree.Class
55+
---
56+
---Enable this decorator.
57+
---@field enabled boolean
58+
---
59+
---What to highlight: [nvim_tree.config.renderer.highlight]
60+
---@field highlight_range nvim_tree.config.renderer.highlight
61+
---
62+
---Where to place the icons: [nvim_tree.config.renderer.icons.placement]
63+
---@field icon_placement "none"|nvim_tree.config.renderer.icons.placement
64+
---
65+
local Decorator = Class:extend()
66+
nvim_tree.api.Decorator = Decorator
67+
68+
---
69+
---Icon to override for the node.
70+
---
71+
---Abstract, optional to implement.
72+
---
73+
---@param node nvim_tree.api.Node
74+
---@return nvim_tree.api.highlighted_string? icon `nil` for no override
75+
function Decorator:icon_node(node) end
76+
77+
---
78+
---Icons to add to the node as per {icon_placement}
79+
---
80+
---Abstract, optional to implement.
81+
---
82+
---@param node nvim_tree.api.Node
83+
---@return nvim_tree.api.highlighted_string[]? icons `nil` or empty table for no icons. Only the first glyph of {str} is used when {icon_placement} is `"signcolumn"`
84+
function Decorator:icons(node) end
85+
86+
---
87+
---One highlight group that applies additively to the {node} name for {highlight_range}.
88+
---
89+
---Abstract, optional to implement.
90+
---
91+
---@param node nvim_tree.api.Node
92+
---@return string? highlight group name `nil` when no highlighting to apply to the node
93+
function Decorator:highlight_group(node) end
94+
95+
---
96+
---Defines a sign for an icon. This is mandatory and necessary only when {icon_placement} is `"signcolumn"`
97+
---
98+
---This must be called during your constructor for all icons that you will return from [nvim_tree.api.Decorator:icons()]
99+
---
100+
---@param icon nvim_tree.api.highlighted_string? does nothing if nil
101+
function Decorator:define_sign(icon) end
102+
103+
return nvim_tree.api.Decorator
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---@meta
2+
error("Cannot require a meta file")
3+
4+
---@brief
5+
---
6+
---A decorator class for nodes named "example", overriding all builtin decorators except for Cut.
7+
---- Highlights node name with `IncSearch`
8+
---- Creates two icons `"1"` and `"2"` placed after the node name, highlighted with `DiffAdd` and `DiffText`
9+
---- Replaces the node icon with `"N"`, highlighted with `Error `
10+
---
11+
---Create a class file `~/.config/nvim/lua/my-decorator.lua`
12+
---
13+
---Require and register it during |nvim-tree-setup|:
14+
---```lua
15+
---
16+
--- local MyDecorator = require("my-decorator")
17+
---
18+
--- require("nvim-tree").setup({
19+
--- renderer = {
20+
--- decorators = {
21+
--- "Git",
22+
--- "Open",
23+
--- "Hidden",
24+
--- "Modified",
25+
--- "Bookmark",
26+
--- "Diagnostics",
27+
--- "Copied",
28+
--- MyDecorator,
29+
--- "Cut",
30+
--- },
31+
--- },
32+
--- })
33+
---```
34+
---Contents of `my-decorator.lua`:
35+
---```lua
36+
---
37+
--- ---@class (exact) MyDecorator: nvim_tree.api.Decorator
38+
--- ---@field private my_icon1 nvim_tree.api.highlighted_string
39+
--- ---@field private my_icon2 nvim_tree.api.highlighted_string
40+
--- ---@field private my_icon_node nvim_tree.api.highlighted_string
41+
--- ---@field private my_highlight_group string
42+
--- local MyDecorator = require("nvim-tree.api").Decorator:extend()
43+
---
44+
--- ---Mandatory constructor :new() will be called once per tree render, with no arguments.
45+
--- function MyDecorator:new()
46+
--- self.enabled = true
47+
--- self.highlight_range = "name"
48+
--- self.icon_placement = "after"
49+
---
50+
--- -- create your icons and highlights once, applied to every node
51+
--- self.my_icon1 = { str = "1", hl = { "DiffAdd" } }
52+
--- self.my_icon2 = { str = "2", hl = { "DiffText" } }
53+
--- self.my_icon_node = { str = "N", hl = { "Error" } }
54+
--- self.my_highlight_group = "IncSearch"
55+
---
56+
--- -- Define the icon signs only once
57+
--- -- Only needed if you are using icon_placement = "signcolumn"
58+
--- -- self:define_sign(self.my_icon1)
59+
--- -- self:define_sign(self.my_icon2)
60+
--- end
61+
---
62+
--- ---Override node icon
63+
--- ---@param node nvim_tree.api.Node
64+
--- ---@return nvim_tree.api.highlighted_string? icon_node
65+
--- function MyDecorator:icon_node(node)
66+
--- if node.name == "example" then
67+
--- return self.my_icon_node
68+
--- else
69+
--- return nil
70+
--- end
71+
--- end
72+
---
73+
--- ---Return two icons for DecoratorIconPlacement "after"
74+
--- ---@param node nvim_tree.api.Node
75+
--- ---@return nvim_tree.api.highlighted_string[]? icons
76+
--- function MyDecorator:icons(node)
77+
--- if node.name == "example" then
78+
--- return { self.my_icon1, self.my_icon2, }
79+
--- else
80+
--- return nil
81+
--- end
82+
--- end
83+
---
84+
--- ---Exactly one highlight group for DecoratorHighlightRange "name"
85+
--- ---@param node nvim_tree.api.Node
86+
--- ---@return string? highlight_group
87+
--- function MyDecorator:highlight_group(node)
88+
--- if node.name == "example" then
89+
--- return self.my_highlight_group
90+
--- else
91+
--- return nil
92+
--- end
93+
--- end
94+
---
95+
--- return MyDecorator
96+
---```

lua/nvim-tree/_meta/api/deprecated.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ function nvim_tree.api.live_filter.clear() end
2727

2828
nvim_tree.api.diagnostics = {}
2929

30-
---@deprecated use `nvim_tree.api.health.hi_test()`
30+
---@deprecated use `nvim_tree.api.appearance.hi_test()`
3131
function nvim_tree.api.diagnostics.hi_test() end
3232

33+
nvim_tree.api.decorator = {}
34+
35+
---@class nvim_tree.api.decorator.UserDecorator: nvim_tree.api.Decorator
36+
---@deprecated use `nvim_tree.api.Decorator`
37+
nvim_tree.api.decorator.UserDecorator = nvim_tree.api.Decorator
38+
3339
return nvim_tree.api

lua/nvim-tree/_meta/api_decorator.lua

Lines changed: 0 additions & 59 deletions
This file was deleted.

lua/nvim-tree/_meta/classes.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
---@meta
22
error("Cannot require a meta file")
33

4-
5-
-- TODO #2688
6-
-- These node subclasses are not ready for public exposure as they are:
7-
-- - not classic classes
8-
-- - only used in a few locations: api.tree.get_nodes and UserDecorator
9-
104
---
115
---File
126
---

lua/nvim-tree/_meta/config/actions.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ error("Cannot require a meta file")
6060
---
6161
---{open_win_config} is passed to [nvim_open_win()], default:
6262
---```lua
63-
---{
64-
--- col = 1,
65-
--- row = 1,
66-
--- relative = "cursor",
67-
--- border = "shadow",
68-
--- style = "minimal",
69-
---}
63+
--- {
64+
--- col = 1,
65+
--- row = 1,
66+
--- relative = "cursor",
67+
--- border = "shadow",
68+
--- style = "minimal",
69+
--- }
7070
---```
7171
---You shouldn't define {width} and {height} values here. They will be overridden to fit the file_popup content.
7272
---@class nvim_tree.config.actions.file_popup

lua/nvim-tree/_meta/config/default.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
---
44
---```lua
55
---
6-
------@type nvim_tree.config
7-
---local config = {
8-
---default-config-injection-placeholder
9-
---}
6+
--- ---@type nvim_tree.config
7+
--- local config = {
8+
--- default-config-injection-placeholder
9+
--- }
1010
---```
11-
---

0 commit comments

Comments
 (0)