Skip to content

Commit fc3e1e0

Browse files
feat: add src/commondeps.jl
1 parent 75a90a2 commit fc3e1e0

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

src/commondeps.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using DocStringExtensions, Reexport, ForceImport, Pkg
2+
3+
"""
4+
Modified `_CLEANMETHODLIST` abbreviation with sanitized file paths.
5+
"""
6+
struct _CleanMethodList <: DocStringExtensions.Abbreviation end
7+
8+
const _CLEANMETHODLIST = _CleanMethodList()
9+
10+
function DocStringExtensions.format(::_CleanMethodList, buf, doc)
11+
local binding = doc.data[:binding]
12+
local typesig = doc.data[:typesig]
13+
local modname = doc.data[:module]
14+
local func = Docs.resolve(binding)
15+
local groups = DocStringExtensions.methodgroups(func, typesig, modname; exact=false)
16+
if !isempty(groups)
17+
println(buf)
18+
local pkg_root = Pkg.pkgdir(modname) # Use Pkg.pkgdir here
19+
if pkg_root === nothing
20+
@warn "Could not determine package root for module $modname using _CLEANMETHODLIST. Paths will be shown as basenames."
21+
end
22+
for group in groups
23+
println(buf, "```julia")
24+
for method in group
25+
DocStringExtensions.printmethod(buf, binding, func, method)
26+
println(buf)
27+
end
28+
println(buf, "```\n")
29+
if !isempty(group)
30+
local method = group[1]
31+
local file = string(method.file)
32+
local line = method.line
33+
local path =
34+
if pkg_root !== nothing && !isempty(file) &&
35+
startswith(file, pkg_root)
36+
basename(file) # relpath(file, pkg_root)
37+
# elseif !isempty(file) && isfile(file)
38+
# basename(file)
39+
else
40+
string(method.file) # Fallback
41+
end
42+
local URL = DocStringExtensions.url(method)
43+
isempty(URL) || println(buf, "defined at [`$path:$line`]($URL).")
44+
end
45+
println(buf)
46+
end
47+
println(buf)
48+
end
49+
return nothing
50+
end

0 commit comments

Comments
 (0)