Skip to content

Commit cbd6fa2

Browse files
committed
docs(#3088): revert api.git refactor, provide deprecated api meta
1 parent d8558bb commit cbd6fa2

File tree

8 files changed

+89
-23
lines changed

8 files changed

+89
-23
lines changed

doc/nvim-tree-lua.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,6 @@ continue to be available.
10171017

10181018
`api.diagnostics.hi_test` |nvim_tree.api.health.hi_test()|
10191019

1020-
`api.git.reload` |nvim_tree.api.tree.reload_git()|
1021-
10221020
`api.live_filter.start` |nvim_tree.api.filter.live.start()|
10231021
`api.live_filter.clear` |nvim_tree.api.filter.live.clear()|
10241022

@@ -2371,6 +2369,7 @@ The API is separated into multiple modules:
23712369
|nvim-tree-api-events|
23722370
|nvim-tree-api-filter|
23732371
|nvim-tree-api-fs|
2372+
|nvim-tree-api-git|
23742373
|nvim-tree-api-health|
23752374
|nvim-tree-api-map|
23762375
|nvim-tree-api-marks|
@@ -2602,6 +2601,14 @@ trash({node}) *nvim_tree.api.fs.trash()*
26022601
{node} (`nvim_tree.api.Node?`)
26032602

26042603

2604+
==============================================================================
2605+
API: git *nvim-tree-api-git*
2606+
2607+
*nvim_tree.api._git.nvim_tree.api.git.reload()*
2608+
nvim_tree.api.git.reload()
2609+
Update the git status of the entire tree.
2610+
2611+
26052612
==============================================================================
26062613
API: health *nvim-tree-api-health*
26072614

@@ -3131,9 +3138,6 @@ open({opts}) *nvim_tree.api.tree.open()*
31313138
reload() *nvim_tree.api.tree.reload()*
31323139
Refresh the tree. Does nothing if closed.
31333140

3134-
reload_git() *nvim_tree.api.tree.reload_git()*
3135-
Update the git status of the entire tree.
3136-
31373141
resize({opts}) *nvim_tree.api.tree.resize()*
31383142
Resize the tree, persisting the new size. Resets to
31393143
|nvim_tree.config.view| {width} when no {opts} provided.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---@meta
2+
local nvim_tree = { api = { git = { } } }
3+
4+
---
5+
---Update the git status of the entire tree.
6+
---
7+
function nvim_tree.api.git.reload() end
8+
9+
return nvim_tree.api.config

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,4 @@ function nvim_tree.api.tree.winid(opts) end
228228
---[tab-ID] 0 or nil for current.
229229
---@field tabpage? integer
230230

231-
---
232-
---Update the git status of the entire tree.
233-
---
234-
function nvim_tree.api.tree.reload_git() end
235-
236231
return nvim_tree.api.tree

lua/nvim-tree/api.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local api = {}
1111
---- [nvim-tree-api-events]
1212
---- [nvim-tree-api-filter]
1313
---- [nvim-tree-api-fs]
14+
---- [nvim-tree-api-git]
1415
---- [nvim-tree-api-health]
1516
---- [nvim-tree-api-map]
1617
---- [nvim-tree-api-marks]
@@ -69,6 +70,7 @@ local api = {}
6970
---@field dir? table<"direct" | "indirect", nvim_tree.git.XY[]> direct inclusive-or indirect status
7071

7172

73+
-- TODO #3088 add nvim_tree.api class
7274

7375
--
7476
-- Load the (empty) meta definitions
@@ -77,13 +79,20 @@ api.commands = require("nvim-tree._meta.api.commands")
7779
api.events = require("nvim-tree._meta.api.events")
7880
api.filter = require("nvim-tree._meta.api.filter")
7981
api.fs = require("nvim-tree._meta.api.fs")
82+
api.git = require("nvim-tree._meta.api._git")
8083
api.health = require("nvim-tree._meta.api.health")
8184
api.map = require("nvim-tree._meta.api.map")
8285
api.marks = require("nvim-tree._meta.api.marks")
8386
api.node = require("nvim-tree._meta.api.node")
8487
api.tree = require("nvim-tree._meta.api.tree")
8588

8689

90+
---
91+
---@nodoc
92+
---Legacy meta definitions
93+
---
94+
api = require("nvim-tree.legacy").api_meta(api)
95+
8796

8897
--
8998
-- Map before-setup implementations, most throw an error notification "nvim-tree setup not called".

lua/nvim-tree/api/impl/post.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,5 @@ return function(api)
258258
hydrate_post(api)
259259

260260
-- (Re)hydrate any legacy by mapping to function set above
261-
require("nvim-tree.legacy").map_api(api)
261+
require("nvim-tree.legacy").api_map(api)
262262
end

lua/nvim-tree/api/impl/pre.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ local function hydrate_error(t)
3030
end
3131

3232
---Hydrate implementations that may be called pre setup
33-
---@param api table
3433
local function hydrate_pre(api)
3534
--
3635
-- Essential
@@ -66,7 +65,6 @@ local function hydrate_pre(api)
6665
end
6766

6867
---Hydrate api
69-
---@param api table
7068
return function(api)
7169
-- Default: error
7270
hydrate_error(api)
@@ -75,5 +73,5 @@ return function(api)
7573
hydrate_pre(api)
7674

7775
-- Hydrate any legacy by mapping to function set above
78-
require("nvim-tree.legacy").map_api(api)
76+
require("nvim-tree.legacy").api_map(api)
7977
end

lua/nvim-tree/legacy.lua

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,14 @@ end
163163
--API
164164
--
165165

166-
---Create new api entries pointing legacy functions to current
167-
---@param api table
168-
function M.map_api(api)
166+
---Silently create new api entries pointing legacy functions to current
167+
function M.api_map(api)
169168
api.config = api.config or {}
170169
api.config.mappings = api.config.mappings or {}
171170
api.config.mappings.get_keymap = api.map.keymap.current
172171
api.config.mappings.get_keymap_default = api.map.keymap.default
173172
api.config.mappings.default_on_attach = api.map.on_attach.default
174173

175-
api.git = api.git or {}
176-
api.git.reload = api.tree.reload_git
177-
178174
api.live_filter = api.live_filter or {}
179175
api.live_filter.start = api.filter.live.start
180176
api.live_filter.clear = api.filter.live.clear
@@ -192,4 +188,54 @@ function M.map_api(api)
192188
api.diagnostics.hi_test = api.health.hi_test
193189
end
194190

191+
---Add meta definitions for deprecated API
192+
function M.api_meta(api)
193+
---@deprecated nvim_tree.api.filter.toggle
194+
function api.tree.toggle_enable_filters() end
195+
196+
---@deprecated nvim_tree.api.filter.git.ignored.toggle
197+
function api.tree.toggle_gitignore_filter() end
198+
199+
---@deprecated nvim_tree.api.filter.git.clean.toggle
200+
function api.tree.toggle_git_clean_filter() end
201+
202+
---@deprecated nvim_tree.api.filter.no_buffer.toggle
203+
function api.tree.toggle_no_buffer_filter() end
204+
205+
---@deprecated nvim_tree.api.filter.custom.toggle
206+
function api.tree.toggle_custom_filter() end
207+
208+
---@deprecated nvim_tree.api.filter.dotfiles.toggle
209+
function api.tree.toggle_hidden_filter() end
210+
211+
---@deprecated nvim_tree.api.filter.no_bookmark.toggle
212+
function api.tree.toggle_no_bookmark_filter() end
213+
214+
api.config = { mappings = {} }
215+
216+
---@deprecated nvim_tree.api.map.keymap.current
217+
function api.config.mappings.get_keymap() end
218+
219+
---@deprecated nvim_tree.api.map.keymap.default
220+
function api.config.mappings.get_keymap_default() end
221+
222+
---@deprecated nvim_tree.api.map.on_attach.default
223+
function api.config.mappings.default_on_attach(_) end
224+
225+
api.live_filter = {}
226+
227+
---@deprecated nvim_tree.api.filter.live.start
228+
function api.live_filter.start() end
229+
230+
---@deprecated nvim_tree.api.filter.live.clear
231+
function api.live_filter.clear() end
232+
233+
api.diagnostics = {}
234+
235+
---@deprecated nvim_tree.api.health.hi_test
236+
function api.diagnostics.hi_test() end
237+
238+
return api
239+
end
240+
195241
return M

scripts/gen_vimdoc_config.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ local srcs = {
4444
{ helptag = "nvim-tree-api-events", section = "API: events", path = "./lua/nvim_tree/_meta/api/events.lua", },
4545
{ helptag = "nvim-tree-api-filter", section = "API: filter", path = "./lua/nvim_tree/_meta/api/filter.lua", },
4646
{ helptag = "nvim-tree-api-fs", section = "API: fs", path = "./lua/nvim_tree/_meta/api/fs.lua", },
47+
-- TODO #3088 come up with a solution to avoid filename clashes
48+
{ helptag = "nvim-tree-api-git", section = "API: git", path = "./lua/nvim_tree/_meta/api/_git.lua", },
4749
{ helptag = "nvim-tree-api-health", section = "API: health", path = "./lua/nvim_tree/_meta/api/health.lua", },
4850
{ helptag = "nvim-tree-api-map", section = "API: map", path = "./lua/nvim_tree/_meta/api/map.lua", },
4951
{ helptag = "nvim-tree-api-marks", section = "API: marks", path = "./lua/nvim_tree/_meta/api/marks.lua", },
@@ -101,10 +103,13 @@ local config = {
101103

102104
-- remove the API prefix from the left aligned function name
103105
-- this will cascade into fn_helptag_fmt, which will apply the module prefix anyway
106+
107+
-- TODO #3088 come up with a solution to avoid filename clashes
108+
---@diagnostic disable-next-line: unused-local
104109
local name, replaced = fun.name:gsub("^" .. module .. "%.", "", 1)
105-
if (replaced ~= 1) then
106-
error(string.format("function name does not start with module: %s", vim.inspect(fun)))
107-
end
110+
-- if (replaced ~= 1) then
111+
-- error(string.format("function name does not start with module: %s", vim.inspect(fun)))
112+
-- end
108113

109114
print(string.format("fn_xform name: %s -> %s", fun.name, name))
110115

0 commit comments

Comments
 (0)