Codebase list lua-ldoc / 4294b2e
Issue #114: trying harder to resolve references by unqualified method name Steve Donovan 10 years ago
3 changed file(s) with 34 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
218218 local this_mod
219219 local items = self.items
220220 local tagged_inside
221 local function add_section (item, display_name)
222 display_name = display_name or item.display_name
223 this_mod.section = item
224 this_mod.kinds:add_kind(display_name,display_name..' ',nil,item)
225 this_mod.sections:append(item)
226 this_mod.sections.by_name[display_name:gsub('%A','_')] = item
227 end
228221 for item in items:iter() do
229222 if mod_section_type(this_mod) == 'factory' and item.tags then
230223 local klass = '@{'..this_mod.section.name..'}'
288281 display_name = summary
289282 end
290283 item.display_name = display_name
291 --~ add_section(item)
292284 this_mod.section = item
293285 this_mod.kinds:add_kind(display_name,display_name..' ',nil,item)
294286 this_mod.sections:append(item)
342334 -- a class is either a @type section or a @classmod module. Is this a _method_?
343335 local class = classmod and this_mod.name or this_section.name
344336 local static = item.tags.constructor or item.tags.static or item.type ~= 'function'
345 if classmod then -- methods and metamethods go into their own special sections...
337 -- methods and metamethods go into their own special sections...
338 if classmod and item.type == 'function' then
346339 local inferred_section
347340 if item.name:match '^__' then
348341 inferred_section = 'Metamethods'
349342 elseif not static then
350343 inferred_section = 'Methods'
351344 end
352 if inferred_section then print('name',item.name,inferred_section)
345 if inferred_section then
353346 item.tags.within = init_within_section(this_mod,inferred_section)
354347 end
355348 end
390383 local these_items = this_mod.items
391384 these_items.by_name[item.name] = item
392385 these_items:append(item)
393 --~ print(item.name,section_description,item.type)
394386 this_mod.kinds:add(item,these_items,section_description)
395387 end
396388
11231115 return nil,"module not found: "..packmod
11241116 end
11251117 end
1126 fun_ref = mod_ref.items.by_name[name]
1118 fun_ref = mod_ref:get_fun_ref(name)
11271119 if fun_ref then
11281120 return reference(s,mod_ref,fun_ref)
11291121 else
11371129 else -- plain jane name; module in this package, function in this module
11381130 mod_ref = modules.by_name[self.package..'.'..s]
11391131 if ismod(mod_ref) then return reference(s, mod_ref,nil) end
1140 fun_ref = self.items.by_name[s]
1141 -- did not get an exact match, so try to match by the unqualified fun name
1142 if not fun_ref then
1143 local patt = '[.:]'..s..'$'
1144 for qname,ref in pairs(self.items.by_name) do
1145 if qname:match(patt) then
1146 fun_ref = ref
1147 break
1148 end
1149 end
1150 end
1132 fun_ref = self:get_fun_ref(s)
11511133 if fun_ref then return reference(s,self,fun_ref)
11521134 else
11531135 local ref = lua_manual_ref (s)
11561138 end
11571139 end
11581140 end
1141
1142 function Module:get_fun_ref(s)
1143 local fun_ref = self.items.by_name[s]
1144 -- did not get an exact match, so try to match by the unqualified fun name
1145 if not fun_ref then
1146 local patt = '[.:]'..s..'$'
1147 for qname,ref in pairs(self.items.by_name) do
1148 if qname:match(patt) then
1149 fun_ref = ref
1150 break
1151 end
1152 end
1153 end
1154 return fun_ref
1155 end
1156
11591157
11601158 -- resolving @see references. A word may be either a function in this module,
11611159 -- or a module in this package. A MOD.NAME reference is within this package.
9696
9797 function ldoc.module_name (mod)
9898 local name = mod.name
99 if args.unqualified and mod.type == 'module' then -- leave out package (also for 'classmod'??)
99 if args.unqualified and (mod.type == 'module' or mod.type == 'classmod') then -- leave out package
100100 name = name:gsub('^.-%.','')
101101 elseif mod.type == 'topic' then
102102 if mod.display_name then
136136 end
137137 end
138138
139
140139 ----- some useful utility functions ------
141140
142141 function M.module_basepath()
150149 end
151150
152151 -- split a qualified name into the module part and the name part,
153 -- e.g 'pl.utils.split' becomes 'pl.utils' and 'split'
152 -- e.g 'pl.utils.split' becomes 'pl.utils' and 'split'. Also
153 -- must understand colon notation!
154154 function M.split_dotted_name (s)
155 local s1,s2 = path.splitext(s)
156 if s2=='' then return nil
157 else return s1,s2:sub(2)
158 end
155 local s1,s2 = s:match '^(.+)[%.:](.+)$'
156 if s1 then -- we can split
157 return s1,s2
158 else
159 return nil
160 end
161 --~ local s1,s2 = path.splitext(s)
162 --~ if s2=='' then return nil
163 --~ else return s1,s2:sub(2)
164 --~ end
159165 end
160166
161167 -- grab lines from a line iterator `iter` until the line matches the pattern.