|
6 | 6 | ---@field helptag string must be globally unique |
7 | 7 | ---@field section string arbitrary |
8 | 8 | ---@field path string relative to root |
9 | | ----@field file_name? string generated from path |
10 | | ----@field name? string override generated name |
11 | | ----@field append_only? boolean follows previous section |
12 | 9 |
|
13 | | ----Help txt is deleted from first tag down and generated content is appended. |
14 | | ----@type Src[] |
15 | | -local srcs = { |
16 | | - { helptag = "nvim-tree-config", section = "Config", path = "./lua/nvim_tree/_meta/config.lua", }, |
17 | | - { helptag = "nvim-tree-config-sort", section = "Config: sort", path = "./lua/nvim_tree/_meta/config/sort.lua", }, |
18 | | - { helptag = "nvim-tree-config-view", section = "Config: view", path = "./lua/nvim_tree/_meta/config/view.lua", }, |
19 | | - { helptag = "nvim-tree-config-renderer", section = "Config: renderer", path = "./lua/nvim_tree/_meta/config/renderer.lua", }, |
20 | | - { helptag = "nvim-tree-config-hijack-directories", section = "Config: hijack_directories", path = "./lua/nvim_tree/_meta/config/hijack_directories.lua", }, |
21 | | - { helptag = "nvim-tree-config-update-focused-file", section = "Config: update_focused_file", path = "./lua/nvim_tree/_meta/config/update_focused_file.lua", }, |
22 | | - { helptag = "nvim-tree-config-system-open", section = "Config: system_open", path = "./lua/nvim_tree/_meta/config/system_open.lua", }, |
23 | | - { helptag = "nvim-tree-config-git", section = "Config: git", path = "./lua/nvim_tree/_meta/config/git.lua", }, |
24 | | - { helptag = "nvim-tree-config-diagnostics", section = "Config: diagnostics", path = "./lua/nvim_tree/_meta/config/diagnostics.lua", }, |
25 | | - { helptag = "nvim-tree-config-modified", section = "Config: modified", path = "./lua/nvim_tree/_meta/config/modified.lua", }, |
26 | | - { helptag = "nvim-tree-config-filters", section = "Config: filters", path = "./lua/nvim_tree/_meta/config/filters.lua", }, |
27 | | - { helptag = "nvim-tree-config-live-filter", section = "Config: live_filter", path = "./lua/nvim_tree/_meta/config/live_filter.lua", }, |
28 | | - { helptag = "nvim-tree-config-filesystem-watchers", section = "Config: filesystem_watchers", path = "./lua/nvim_tree/_meta/config/filesystem_watchers.lua", }, |
29 | | - { helptag = "nvim-tree-config-actions", section = "Config: actions", path = "./lua/nvim_tree/_meta/config/actions.lua", }, |
30 | | - { helptag = "nvim-tree-config-trash", section = "Config: trash", path = "./lua/nvim_tree/_meta/config/trash.lua", }, |
31 | | - { helptag = "nvim-tree-config-tab", section = "Config: tab", path = "./lua/nvim_tree/_meta/config/tab.lua", }, |
32 | | - { helptag = "nvim-tree-config-notify", section = "Config: notify", path = "./lua/nvim_tree/_meta/config/notify.lua", }, |
33 | | - { helptag = "nvim-tree-config-bookmarks", section = "Config: bookmarks", path = "./lua/nvim_tree/_meta/config/bookmarks.lua", }, |
34 | | - { helptag = "nvim-tree-config-help", section = "Config: help", path = "./lua/nvim_tree/_meta/config/help.lua", }, |
35 | | - { helptag = "nvim-tree-config-ui", section = "Config: ui", path = "./lua/nvim_tree/_meta/config/ui.lua", name = "UI", }, |
36 | | - { helptag = "nvim-tree-config-experimental", section = "Config: experimental", path = "./lua/nvim_tree/_meta/config/experimental.lua", }, |
37 | | - { helptag = "nvim-tree-config-log", section = "Config: log", path = "./lua/nvim_tree/_meta/config/log.lua", }, |
38 | | - |
39 | | - { helptag = "nvim-tree-config-default", section = "Config: Default", path = "./lua/nvim_tree/_meta/config/default.lua", }, |
| 10 | +local pre = "runtime/lua/nvim_tree/" |
40 | 11 |
|
41 | | - { helptag = "nvim-tree-api", section = "API", path = "./lua/nvim_tree/api.lua", }, |
| 12 | +---@type Src[] |
| 13 | +local srcs_config = { |
| 14 | + { helptag = "nvim-tree-config", section = "Config", path = pre .. "_meta/config.lua", }, |
| 15 | + |
| 16 | + { helptag = "nvim-tree-config-sort", section = "Config: sort", path = pre .. "_meta/config/sort.lua", }, |
| 17 | + { helptag = "nvim-tree-config-view", section = "Config: view", path = pre .. "_meta/config/view.lua", }, |
| 18 | + { helptag = "nvim-tree-config-renderer", section = "Config: renderer", path = pre .. "_meta/config/renderer.lua", }, |
| 19 | + { helptag = "nvim-tree-config-hijack-directories", section = "Config: hijack_directories", path = pre .. "_meta/config/hijack_directories.lua", }, |
| 20 | + { helptag = "nvim-tree-config-update-focused-file", section = "Config: update_focused_file", path = pre .. "_meta/config/update_focused_file.lua", }, |
| 21 | + { helptag = "nvim-tree-config-system-open", section = "Config: system_open", path = pre .. "_meta/config/system_open.lua", }, |
| 22 | + { helptag = "nvim-tree-config-git", section = "Config: git", path = pre .. "_meta/config/git.lua", }, |
| 23 | + { helptag = "nvim-tree-config-diagnostics", section = "Config: diagnostics", path = pre .. "_meta/config/diagnostics.lua", }, |
| 24 | + { helptag = "nvim-tree-config-modified", section = "Config: modified", path = pre .. "_meta/config/modified.lua", }, |
| 25 | + { helptag = "nvim-tree-config-filters", section = "Config: filters", path = pre .. "_meta/config/filters.lua", }, |
| 26 | + { helptag = "nvim-tree-config-live-filter", section = "Config: live_filter", path = pre .. "_meta/config/live_filter.lua", }, |
| 27 | + { helptag = "nvim-tree-config-filesystem-watchers", section = "Config: filesystem_watchers", path = pre .. "_meta/config/filesystem_watchers.lua", }, |
| 28 | + { helptag = "nvim-tree-config-actions", section = "Config: actions", path = pre .. "_meta/config/actions.lua", }, |
| 29 | + { helptag = "nvim-tree-config-trash", section = "Config: trash", path = pre .. "_meta/config/trash.lua", }, |
| 30 | + { helptag = "nvim-tree-config-tab", section = "Config: tab", path = pre .. "_meta/config/tab.lua", }, |
| 31 | + { helptag = "nvim-tree-config-notify", section = "Config: notify", path = pre .. "_meta/config/notify.lua", }, |
| 32 | + { helptag = "nvim-tree-config-bookmarks", section = "Config: bookmarks", path = pre .. "_meta/config/bookmarks.lua", }, |
| 33 | + { helptag = "nvim-tree-config-help", section = "Config: help", path = pre .. "_meta/config/help.lua", }, |
| 34 | + { helptag = "nvim-tree-config-ui", section = "Config: ui", path = pre .. "_meta/config/ui.lua", }, |
| 35 | + { helptag = "nvim-tree-config-experimental", section = "Config: experimental", path = pre .. "_meta/config/experimental.lua", }, |
| 36 | + { helptag = "nvim-tree-config-log", section = "Config: log", path = pre .. "_meta/config/log.lua", }, |
| 37 | + |
| 38 | + { helptag = "nvim-tree-config-default", section = "Config: Default", path = pre .. "_meta/config/default.lua", }, |
| 39 | + |
| 40 | + { helptag = "nvim-tree-api", section = "API Placeholder", path = pre .. "api.lua", }, |
| 41 | +} |
42 | 42 |
|
43 | | - { helptag = "nvim-tree-api-commands", section = "API: commands", path = "./lua/nvim_tree/_meta/api/commands.lua", }, |
44 | | - { helptag = "nvim-tree-api-events", section = "API: events", path = "./lua/nvim_tree/_meta/api/events.lua", }, |
45 | | - { helptag = "nvim-tree-api-filter", section = "API: filter", path = "./lua/nvim_tree/_meta/api/filter.lua", }, |
46 | | - { 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", }, |
49 | | - { helptag = "nvim-tree-api-health", section = "API: health", path = "./lua/nvim_tree/_meta/api/health.lua", }, |
50 | | - { helptag = "nvim-tree-api-map", section = "API: map", path = "./lua/nvim_tree/_meta/api/map.lua", }, |
51 | | - { helptag = "nvim-tree-api-marks", section = "API: marks", path = "./lua/nvim_tree/_meta/api/marks.lua", }, |
52 | | - { helptag = "nvim-tree-api-node", section = "API: node", path = "./lua/nvim_tree/_meta/api/node.lua", }, |
53 | | - { helptag = "nvim-tree-api-tree", section = "API: tree", path = "./lua/nvim_tree/_meta/api/tree.lua", }, |
| 43 | +---@type Src[] |
| 44 | +local srcs_api = { |
| 45 | + { helptag = "nvim-tree-api", section = "API", path = pre .. "api.lua", }, |
| 46 | + |
| 47 | + { helptag = "nvim-tree-api-commands", section = "API: commands", path = pre .. "_meta/api/commands.lua", }, |
| 48 | + { helptag = "nvim-tree-api-events", section = "API: events", path = pre .. "_meta/api/events.lua", }, |
| 49 | + { helptag = "nvim-tree-api-filter", section = "API: filter", path = pre .. "_meta/api/filter.lua", }, |
| 50 | + { helptag = "nvim-tree-api-fs", section = "API: fs", path = pre .. "_meta/api/fs.lua", }, |
| 51 | + { helptag = "nvim-tree-api-git", section = "API: git", path = pre .. "_meta/api/git.lua", }, |
| 52 | + { helptag = "nvim-tree-api-health", section = "API: health", path = pre .. "_meta/api/health.lua", }, |
| 53 | + { helptag = "nvim-tree-api-map", section = "API: map", path = pre .. "_meta/api/map.lua", }, |
| 54 | + { helptag = "nvim-tree-api-marks", section = "API: marks", path = pre .. "_meta/api/marks.lua", }, |
| 55 | + { helptag = "nvim-tree-api-node", section = "API: node", path = pre .. "_meta/api/node.lua", }, |
| 56 | + { helptag = "nvim-tree-api-tree", section = "API: tree", path = pre .. "_meta/api/tree.lua", }, |
54 | 57 | } |
55 | 58 |
|
56 | | --- hydrate file names |
57 | | -for _, m in ipairs(srcs) do |
58 | | - m.file_name = vim.fn.fnamemodify(m.path, ":t") |
| 59 | +---Map paths to file names |
| 60 | +---File names are the unique key that gen_vimdoc.lua uses |
| 61 | +---@param srcs Src[] |
| 62 | +---@return string[] file names |
| 63 | +local function section_order(srcs) |
| 64 | + return vim.tbl_map(function(src) |
| 65 | + return vim.fn.fnamemodify(src.path, ":t") |
| 66 | + end, srcs) |
59 | 67 | end |
60 | 68 |
|
61 | | ---name is derived by the generator as the file name with the first letter capitalised |
62 | | ---except for some like UI which are overridden in srcs |
63 | | ----@type table<string, Src> |
64 | | -local srcs_by_name = {} |
65 | | -for _, m in ipairs(srcs) do |
66 | | - local name = m.name or m.file_name:gsub(".lua", ""):gsub("^%l", string.upper) |
67 | | - srcs_by_name[name] = m |
| 69 | +---Extract paths |
| 70 | +---@param srcs Src[] |
| 71 | +---@return string[] file names |
| 72 | +local function files(srcs) |
| 73 | + return vim.tbl_map(function(src) |
| 74 | + return src.path |
| 75 | + end, srcs) |
| 76 | +end |
| 77 | + |
| 78 | +---Find a Src or error. |
| 79 | +---Name is the (sometimes specifically hardcoded) mangled case filename with .lua stripped |
| 80 | +---@param name string |
| 81 | +---@param srcs Src[] |
| 82 | +---@return Src? |
| 83 | +local function src_by_name(name, srcs) |
| 84 | + for _, s in ipairs(srcs) do |
| 85 | + if s.path:match(name:lower() .. ".lua$") then |
| 86 | + return s |
| 87 | + end |
| 88 | + end |
| 89 | + error(string.format("\n\nPath for lower, extension stripped file name='%s' not found in\nsrcs=%s\n", name, vim.inspect(srcs))) |
68 | 90 | end |
69 | 91 |
|
70 | 92 | -- @type table<string,nvim.gen_vimdoc.Config> |
71 | | -local config = { |
72 | | - all = { |
| 93 | +return { |
| 94 | + -- Config |
| 95 | + { |
73 | 96 | filename = "nvim-tree-lua.txt", |
| 97 | + section_order = section_order(srcs_config), |
| 98 | + files = files(srcs_config), |
| 99 | + section_fmt = function(name) return src_by_name(name, srcs_config).section end, |
| 100 | + helptag_fmt = function(name) return src_by_name(name, srcs_config).helptag end, |
| 101 | + }, |
| 102 | + -- API |
| 103 | + { |
| 104 | + filename = "nvim-tree-lua.txt", |
| 105 | + section_order = section_order(srcs_api), |
| 106 | + files = files(srcs_api), |
| 107 | + section_fmt = function(name) return src_by_name(name, srcs_api).section end, |
| 108 | + helptag_fmt = function(name) return src_by_name(name, srcs_api).helptag end, |
74 | 109 |
|
75 | | - -- source file name is used to set order |
76 | | - section_order = vim.tbl_map(function(src) return src.file_name end, srcs), |
77 | | - |
78 | | - -- path |
79 | | - files = vim.tbl_map(function(src) return src.path end, srcs), |
80 | | - |
81 | | - append_only = vim.tbl_map(function(src) return src.append_only and src.file_name or nil end, srcs), |
82 | | - |
83 | | - section_fmt = function(name) |
84 | | - print(string.format("section_fmt name=%s", name)) |
85 | | - return srcs_by_name[name] and srcs_by_name[name].section or |
86 | | - error(string.format("unknown name %s passed to section_fmt", name)) |
87 | | - end, |
88 | | - |
89 | | - helptag_fmt = function(name) |
90 | | - print(string.format("helptag_fmt name=%s", name)) |
91 | | - return srcs_by_name[name] and srcs_by_name[name].helptag or |
92 | | - error(string.format("unknown name %s passed to helptag_fmt", name)) |
93 | | - end, |
94 | | - |
95 | | - -- optional, no default xform |
| 110 | + -- optional, no default xform to override |
96 | 111 | fn_xform = function(fun) |
97 | | - print(string.format("fn_xform fun=%s", vim.inspect(fun))) |
98 | | - |
99 | 112 | if (fun.module) then |
100 | 113 | -- generator doesn't strip meta |
101 | 114 | -- also cascades into fn_helptag_fmt |
102 | 115 | local module = fun.module:gsub("._meta", "", 1) |
103 | 116 |
|
104 | 117 | -- remove the API prefix from the left aligned function name |
105 | 118 | -- 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 |
109 | 119 | local name, replaced = fun.name:gsub("^" .. module .. "%.", "", 1) |
110 | | - -- if (replaced ~= 1) then |
111 | | - -- error(string.format("function name does not start with module: %s", vim.inspect(fun))) |
112 | | - -- end |
113 | | - |
114 | | - print(string.format("fn_xform name: %s -> %s", fun.name, name)) |
| 120 | + if (replaced ~= 1) then |
| 121 | + error(string.format("\n\nfun.name='%s' does not start with _meta stripped module='%s'\nfun=%s", fun.name, module, vim.inspect(fun))) |
| 122 | + end |
115 | 123 |
|
116 | 124 | fun.module = module |
117 | 125 | fun.name = name |
118 | 126 | end |
119 | 127 | end, |
120 | 128 | } |
121 | 129 | } |
122 | | - |
123 | | -return config |
|
0 commit comments