Issue #114: trying harder to resolve references by unqualified method name

This commit is contained in:
Steve Donovan 2013-11-28 11:57:13 +02:00
parent 63e3618c05
commit 4294b2e2da
3 changed files with 33 additions and 29 deletions

View File

@ -219,13 +219,6 @@ function File:finish()
local this_mod local this_mod
local items = self.items local items = self.items
local tagged_inside local tagged_inside
local function add_section (item, display_name)
display_name = display_name or item.display_name
this_mod.section = item
this_mod.kinds:add_kind(display_name,display_name..' ',nil,item)
this_mod.sections:append(item)
this_mod.sections.by_name[display_name:gsub('%A','_')] = item
end
for item in items:iter() do for item in items:iter() do
if mod_section_type(this_mod) == 'factory' and item.tags then if mod_section_type(this_mod) == 'factory' and item.tags then
local klass = '@{'..this_mod.section.name..'}' local klass = '@{'..this_mod.section.name..'}'
@ -289,7 +282,6 @@ function File:finish()
display_name = summary display_name = summary
end end
item.display_name = display_name item.display_name = display_name
--~ add_section(item)
this_mod.section = item this_mod.section = item
this_mod.kinds:add_kind(display_name,display_name..' ',nil,item) this_mod.kinds:add_kind(display_name,display_name..' ',nil,item)
this_mod.sections:append(item) this_mod.sections:append(item)
@ -343,14 +335,15 @@ function File:finish()
-- a class is either a @type section or a @classmod module. Is this a _method_? -- a class is either a @type section or a @classmod module. Is this a _method_?
local class = classmod and this_mod.name or this_section.name local class = classmod and this_mod.name or this_section.name
local static = item.tags.constructor or item.tags.static or item.type ~= 'function' local static = item.tags.constructor or item.tags.static or item.type ~= 'function'
if classmod then -- methods and metamethods go into their own special sections... -- methods and metamethods go into their own special sections...
if classmod and item.type == 'function' then
local inferred_section local inferred_section
if item.name:match '^__' then if item.name:match '^__' then
inferred_section = 'Metamethods' inferred_section = 'Metamethods'
elseif not static then elseif not static then
inferred_section = 'Methods' inferred_section = 'Methods'
end end
if inferred_section then print('name',item.name,inferred_section) if inferred_section then
item.tags.within = init_within_section(this_mod,inferred_section) item.tags.within = init_within_section(this_mod,inferred_section)
end end
end end
@ -391,7 +384,6 @@ function File:finish()
local these_items = this_mod.items local these_items = this_mod.items
these_items.by_name[item.name] = item these_items.by_name[item.name] = item
these_items:append(item) these_items:append(item)
--~ print(item.name,section_description,item.type)
this_mod.kinds:add(item,these_items,section_description) this_mod.kinds:add(item,these_items,section_description)
end end
@ -1124,7 +1116,7 @@ function Module:process_see_reference (s,modules,istype)
return nil,"module not found: "..packmod return nil,"module not found: "..packmod
end end
end end
fun_ref = mod_ref.items.by_name[name] fun_ref = mod_ref:get_fun_ref(name)
if fun_ref then if fun_ref then
return reference(s,mod_ref,fun_ref) return reference(s,mod_ref,fun_ref)
else else
@ -1138,7 +1130,18 @@ function Module:process_see_reference (s,modules,istype)
else -- plain jane name; module in this package, function in this module else -- plain jane name; module in this package, function in this module
mod_ref = modules.by_name[self.package..'.'..s] mod_ref = modules.by_name[self.package..'.'..s]
if ismod(mod_ref) then return reference(s, mod_ref,nil) end if ismod(mod_ref) then return reference(s, mod_ref,nil) end
fun_ref = self.items.by_name[s] fun_ref = self:get_fun_ref(s)
if fun_ref then return reference(s,self,fun_ref)
else
local ref = lua_manual_ref (s)
if ref then return ref end
return nil, "function not found: "..s.." in this module"
end
end
end
function Module:get_fun_ref(s)
local fun_ref = self.items.by_name[s]
-- did not get an exact match, so try to match by the unqualified fun name -- did not get an exact match, so try to match by the unqualified fun name
if not fun_ref then if not fun_ref then
local patt = '[.:]'..s..'$' local patt = '[.:]'..s..'$'
@ -1149,15 +1152,10 @@ function Module:process_see_reference (s,modules,istype)
end end
end end
end end
if fun_ref then return reference(s,self,fun_ref) return fun_ref
else
local ref = lua_manual_ref (s)
if ref then return ref end
return nil, "function not found: "..s.." in this module"
end
end
end end
-- resolving @see references. A word may be either a function in this module, -- resolving @see references. A word may be either a function in this module,
-- or a module in this package. A MOD.NAME reference is within this package. -- or a module in this package. A MOD.NAME reference is within this package.
-- Otherwise, the full qualified name must be used. -- Otherwise, the full qualified name must be used.

View File

@ -97,7 +97,7 @@ function html.generate_output(ldoc, args, project)
function ldoc.module_name (mod) function ldoc.module_name (mod)
local name = mod.name local name = mod.name
if args.unqualified and mod.type == 'module' then -- leave out package (also for 'classmod'??) if args.unqualified and (mod.type == 'module' or mod.type == 'classmod') then -- leave out package
name = name:gsub('^.-%.','') name = name:gsub('^.-%.','')
elseif mod.type == 'topic' then elseif mod.type == 'topic' then
if mod.display_name then if mod.display_name then

View File

@ -137,7 +137,6 @@ function KindMap.add_kind (klass,tag,kind,subnames,item)
end end
end end
----- some useful utility functions ------ ----- some useful utility functions ------
function M.module_basepath() function M.module_basepath()
@ -151,12 +150,19 @@ function M.module_basepath()
end end
-- split a qualified name into the module part and the name part, -- split a qualified name into the module part and the name part,
-- e.g 'pl.utils.split' becomes 'pl.utils' and 'split' -- e.g 'pl.utils.split' becomes 'pl.utils' and 'split'. Also
-- must understand colon notation!
function M.split_dotted_name (s) function M.split_dotted_name (s)
local s1,s2 = path.splitext(s) local s1,s2 = s:match '^(.+)[%.:](.+)$'
if s2=='' then return nil if s1 then -- we can split
else return s1,s2:sub(2) return s1,s2
else
return nil
end end
--~ local s1,s2 = path.splitext(s)
--~ if s2=='' then return nil
--~ else return s1,s2:sub(2)
--~ end
end end
-- grab lines from a line iterator `iter` until the line matches the pattern. -- grab lines from a line iterator `iter` until the line matches the pattern.