1010--- @field section string arbitrary
1111--- @field path string relative to root
1212
13+ --- TODO #3241 do this for all classes, moving decorator up to nvim_tree.api.Decorator
14+
15+ --- Module overrides
16+ --- @type table<string , string>
17+ local module_overrides = {
18+ [" nvim_tree.classic" ] = " nvim_tree"
19+ }
20+
1321local pre = " runtime/lua/nvim_tree/"
1422
1523--- @type Src[]
@@ -39,24 +47,24 @@ local srcs_config = {
3947 { helptag = " nvim-tree-config-log" , section = " Config: log" , path = pre .. " _meta/config/log.lua" , },
4048
4149 { helptag = " nvim-tree-config-default" , section = " Config: Default" , path = pre .. " _meta/config/default.lua" , },
42-
43- { helptag = " nvim-tree-api" , section = " placeholder for next Config" , path = pre .. " api.lua" , },
4450}
4551
4652--- @type Src[]
4753local srcs_api = {
48- { helptag = " nvim-tree-api" , section = " API" , path = pre .. " api.lua" , },
49-
50- { helptag = " nvim-tree-api-commands" , section = " API: commands" , path = pre .. " _meta/api/commands.lua" , },
51- { helptag = " nvim-tree-api-events" , section = " API: events" , path = pre .. " _meta/api/events.lua" , },
52- { helptag = " nvim-tree-api-filter" , section = " API: filter" , path = pre .. " _meta/api/filter.lua" , },
53- { helptag = " nvim-tree-api-fs" , section = " API: fs" , path = pre .. " _meta/api/fs.lua" , },
54- { helptag = " nvim-tree-api-git" , section = " API: git" , path = pre .. " _meta/api/git.lua" , },
55- { helptag = " nvim-tree-api-health" , section = " API: health" , path = pre .. " _meta/api/health.lua" , },
56- { helptag = " nvim-tree-api-map" , section = " API: map" , path = pre .. " _meta/api/map.lua" , },
57- { helptag = " nvim-tree-api-marks" , section = " API: marks" , path = pre .. " _meta/api/marks.lua" , },
58- { helptag = " nvim-tree-api-node" , section = " API: node" , path = pre .. " _meta/api/node.lua" , },
59- { helptag = " nvim-tree-api-tree" , section = " API: tree" , path = pre .. " _meta/api/tree.lua" , },
54+ { helptag = " nvim-tree-api" , section = " API" , path = pre .. " api.lua" , },
55+
56+ { helptag = " nvim-tree-api-commands" , section = " API: commands" , path = pre .. " _meta/api/commands.lua" , },
57+ { helptag = " nvim-tree-api-events" , section = " API: events" , path = pre .. " _meta/api/events.lua" , },
58+ { helptag = " nvim-tree-api-filter" , section = " API: filter" , path = pre .. " _meta/api/filter.lua" , },
59+ { helptag = " nvim-tree-api-fs" , section = " API: fs" , path = pre .. " _meta/api/fs.lua" , },
60+ { helptag = " nvim-tree-api-git" , section = " API: git" , path = pre .. " _meta/api/git.lua" , },
61+ { helptag = " nvim-tree-api-health" , section = " API: health" , path = pre .. " _meta/api/health.lua" , },
62+ { helptag = " nvim-tree-api-map" , section = " API: map" , path = pre .. " _meta/api/map.lua" , },
63+ { helptag = " nvim-tree-api-marks" , section = " API: marks" , path = pre .. " _meta/api/marks.lua" , },
64+ { helptag = " nvim-tree-api-node" , section = " API: node" , path = pre .. " _meta/api/node.lua" , },
65+ { helptag = " nvim-tree-api-tree" , section = " API: tree" , path = pre .. " _meta/api/tree.lua" , },
66+ { helptag = " nvim-tree-api-decorator" , section = " API: Decorator" , path = pre .. " _meta/api/decorator.lua" , },
67+ { helptag = " nvim-tree-api-class" , section = " API: Class" , path = pre .. " classic.lua" , },
6068}
6169
6270--- Map paths to file names
@@ -92,6 +100,17 @@ local function src_by_name(name, srcs)
92100 error (string.format (" \n\n Path for lower, extension stripped file name='%s' not found in\n srcs=%s\n " , name , vim .inspect (srcs )))
93101end
94102
103+ --- HACK
104+ --- Problem:
105+ --- Generator generates fields for a class' methods.
106+ --- This is a problem as method fields don't have a module and aren't transformed.
107+ --- Method field fun only contains: classvar, desc, name and (function) type
108+ --- Solution:
109+ --- Collect a map of "class:method" to modules when the real method passes through fn_xform
110+ --- This works as the real method function is processed before the field method.
111+ --- @type table<string , string>
112+ local modules_by_method = {}
113+
95114-- @type nvim.gen_vimdoc.Config[]
96115return {
97116 -- Config
@@ -110,23 +129,42 @@ return {
110129 section_fmt = function (name ) return src_by_name (name , srcs_api ).section end ,
111130 helptag_fmt = function (name ) return src_by_name (name , srcs_api ).helptag end ,
112131
113- -- optional, no default xform to override
114132 fn_xform = function (fun )
115- if (fun .module ) then
116- -- generator doesn't strip meta
117- -- also cascades into fn_helptag_fmt
118- local module = fun .module :gsub (" ._meta" , " " , 1 )
119-
120- -- remove the API prefix from the left aligned function name
121- -- this will cascade into fn_helptag_fmt, which will apply the module prefix anyway
122- local name , replaced = fun .name :gsub (" ^" .. module .. " %." , " " , 1 )
133+ -- generator doesn't strip _meta; this propagates to fn_helptag_fmt
134+ fun .module = fun .module :gsub (" ._meta" , " " , 1 )
135+ fun .module = module_overrides [fun .module ] or fun .module
136+
137+ if not fun .class then
138+ -- functions require the module to be stripped from the name, classes do not
139+ local name , replaced = fun .name :gsub (" ^" .. fun .module .. " %." , " " , 1 )
123140 if (replaced ~= 1 ) then
124- error (string.format (" \n\n fun.name='%s' does not start with _meta stripped module='%s'\n fun=%s" , fun .name , module , vim .inspect (fun )))
141+ error (string.format (" \n\n fn_xform: fun.name='%s' does not start with _meta stripped \n fun=%s" ,
142+ fun .name , vim .inspect (fun )))
125143 end
126-
127- fun .module = module
128144 fun .name = name
145+ elseif fun .class and fun .classvar and fun .name then
146+ -- note the module for use by method fields
147+ modules_by_method [fun .classvar .. " :" .. fun .name ] = fun .module
148+ end
149+ end ,
150+
151+ -- fn_helptag_fmt_common modified:
152+ -- module prepended to classes
153+ -- module is fetched from modules_by_method when fun.module unavailable
154+ fn_helptag_fmt = function (fun )
155+ local fn_sfx = fun .table and " " or " ()"
156+ if fun .classvar then
157+ local module = fun .module or modules_by_method [fun .classvar .. " :" .. fun .name ]
158+ if not module then
159+ error (string.format (" \n\n fn_helptag_fmt: no module:\n fun=%s\n modules_by_method=%s" ,
160+ vim .inspect (fun ), vim .inspect (modules_by_method )))
161+ end
162+ return string.format (" %s.%s:%s%s" , module , fun .classvar , fun .name , fn_sfx )
163+ end
164+ if fun .module then
165+ return string.format (" %s.%s%s" , fun .module , fun .name , fn_sfx )
129166 end
167+ return fun .name .. fn_sfx
130168 end ,
131169 }
132170}
0 commit comments