Skip to content

Commit f286fc6

Browse files
Merge branch 'master' into mk-fix-alltypesigs
2 parents e5c1c5c + 1df1224 commit f286fc6

File tree

9 files changed

+160
-92
lines changed

9 files changed

+160
-92
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
${{ runner.os }}-test-
3737
${{ runner.os }}-
3838
- uses: julia-actions/julia-runtest@latest
39+
continue-on-error: ${{ matrix.version == 'nightly' }}
3940
- uses: julia-actions/julia-processcoverage@v1
4041
- uses: codecov/codecov-action@v1
4142
with:

.github/workflows/register.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Register Package
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
version:
6+
description: Version to register or component to bump
7+
required: true
8+
jobs:
9+
register:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: julia-actions/RegisterAction@latest
13+
with:
14+
token: ${{ secrets.GITHUB_TOKEN }}

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DocStringExtensions"
22
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
3-
version = "0.8.6"
3+
version = "0.9.2"
44

55
[deps]
66
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,14 @@ Contributions are very welcome, as are feature requests and suggestions. Please
3232
[gitter-url]: https://gitter.im/juliadocs/users
3333

3434
[docs-latest-img]: https://img.shields.io/badge/docs-latest-blue.svg
35-
[docs-latest-url]: https://juliadocs.github.io/DocStringExtensions.jl/latest
35+
[docs-latest-url]: https://DocStringExtensions.juliadocs.org/latest
3636

3737
[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg
38-
[docs-stable-url]: https://juliadocs.github.io/DocStringExtensions.jl/stable
38+
[docs-stable-url]: https://DocStringExtensions.juliadocs.org/stable
3939

4040
[github-action-img]: https://github.com/JuliaDocs/DocStringExtensions.jl/actions/workflows/ci.yml/badge.svg
4141
[github-action-url]: https://github.com/JuliaDocs/DocStringExtensions.jl/actions/workflows/ci.yml
4242

43-
[travis-img]: https://travis-ci.org/JuliaDocs/DocStringExtensions.jl.svg?branch=master
44-
[travis-url]: https://travis-ci.org/JuliaDocs/DocStringExtensions.jl
45-
46-
[appveyor-img]: https://ci.appveyor.com/api/projects/status/7bixd69chxps91wx/branch/master?svg=true
47-
[appveyor-url]: https://ci.appveyor.com/project/JuliaDocs/docstringextensions-jl/branch/master
48-
4943
[codecov-img]: https://codecov.io/gh/JuliaDocs/DocStringExtensions.jl/branch/master/graph/badge.svg
5044
[codecov-url]: https://codecov.io/gh/JuliaDocs/DocStringExtensions.jl
5145

src/abbreviations.jl

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,9 @@ type `Vector{Any}`.
8181
8282
- `x::String`
8383
84-
- `y::Int`
84+
- `y::Int`: Unlike the `x` field this field has been documented.
8585
86-
Unlike the `x` field this field has been documented.
87-
88-
- `z::Array{Any, 1}`
89-
90-
Another documented field.
86+
- `z::Array{Any, 1}`: Another documented field.
9187
```
9288
"""
9389
const TYPEDFIELDS = TypeFields(true)
@@ -96,23 +92,23 @@ function format(abbrv::TypeFields, buf, doc)
9692
local docs = get(doc.data, :fields, Dict())
9793
local binding = doc.data[:binding]
9894
local object = Docs.resolve(binding)
99-
# On 0.7 fieldnames() on an abstract type throws an error. We then explicitly return
100-
# an empty vector to be consistent with the behaviour on v0.6.
10195
local fields = isabstracttype(object) ? Symbol[] : fieldnames(object)
10296
if !isempty(fields)
10397
println(buf)
10498
for field in fields
105-
if abbrv.types
106-
println(buf, " - `", field, "::", fieldtype(object, field), "`")
107-
else
108-
println(buf, " - `", field, "`")
109-
end
99+
print(buf, " - `", field)
100+
abbrv.types && print(buf, "::", fieldtype(object, field))
101+
print(buf, "`")
110102
# Print the field docs if they exist and aren't a `doc"..."` docstring.
111103
if haskey(docs, field) && isa(docs[field], AbstractString)
112-
println(buf)
104+
print(buf, ": ")
105+
indented = true
113106
for line in split(docs[field], "\n")
114-
println(buf, isempty(line) ? "" : " ", rstrip(line))
107+
println(buf, indented || isempty(line) ? "" : " ", rstrip(line))
108+
indented = false
115109
end
110+
else
111+
println(buf)
116112
end
117113
println(buf)
118114
end
@@ -394,7 +390,7 @@ function format(::TypedMethodSignatures, buf, doc)
394390
end
395391
end
396392

397-
if Sys.iswindows()
393+
@static if Sys.iswindows() && VERSION < v"1.8"
398394
t = tuples[findlast(f, tuples)]
399395
else
400396
t = tuples[findfirst(f, tuples)]
@@ -670,6 +666,7 @@ function template_key(doc::Docs.DocStr)
670666
_key(::Function, ::typeof(Union{}), binding) = ismacro(binding) ? :MACROS : :FUNCTIONS
671667
_key(::Function, sig, binding) = ismacro(binding) ? :MACROS : :METHODS
672668
_key(::DataType, ::typeof(Union{}), binding) = :TYPES
669+
_key(::UnionAll, ::typeof(Union{}), binding) = :TYPES
673670
_key(::DataType, sig, binding) = :METHODS
674671
_key(other, sig, binding) = :DEFAULT
675672

src/utilities.jl

Lines changed: 85 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,45 @@ function parsedocs(mod::Module)
175175
end
176176
end
177177

178+
"""
179+
$(:SIGNATURES)
180+
181+
Decides whether a length of method is too big to be visually appealing.
182+
"""
183+
method_length_over_limit(len::Int) = len > 60
184+
185+
function printmethod_format(buffer::IOBuffer, binding::String, args::Vector{String}, kws::Vector{String}; return_type = "")
186+
187+
sep_delim = " "
188+
paren_delim = ""
189+
indent = ""
190+
191+
if method_length_over_limit(
192+
length(binding) +
193+
1 +
194+
sum(length.(args)) +
195+
sum(length.(kws)) +
196+
2*max(0, length(args)-1) +
197+
2*length(kws) +
198+
1 +
199+
length(return_type))
200+
201+
sep_delim = "\n"
202+
paren_delim = "\n"
203+
indent = " "
204+
end
205+
206+
print(buffer, binding)
207+
print(buffer, "($paren_delim")
208+
join(buffer, Ref(indent).*args, ",$sep_delim")
209+
if !isempty(kws)
210+
print(buffer, ";$sep_delim")
211+
join(buffer, Ref(indent).*kws, ",$sep_delim")
212+
end
213+
print(buffer, "$paren_delim)")
214+
print(buffer, return_type)
215+
return buffer
216+
end
178217

179218
"""
180219
$(:SIGNATURES)
@@ -194,19 +233,10 @@ f(x; a = 1, b...) = x
194233
sig = printmethod(Docs.Binding(Main, :f), f, first(methods(f)))
195234
```
196235
"""
197-
function printmethod(buffer::IOBuffer, binding::Docs.Binding, func, method::Method)
198-
# TODO: print qualified?
199-
print(buffer, binding.var)
200-
print(buffer, "(")
201-
join(buffer, arguments(method), ", ")
202-
local kws = keywords(func, method)
203-
if !isempty(kws)
204-
print(buffer, "; ")
205-
join(buffer, kws, ", ")
206-
end
207-
print(buffer, ")")
208-
return buffer
209-
end
236+
printmethod(buffer::IOBuffer, binding::Docs.Binding, func, method::Method) =
237+
printmethod_format(buffer, string(binding.var),
238+
string.(arguments(method)),
239+
string.(keywords(func, method)))
210240

211241
"""
212242
$(:SIGNATURES)
@@ -274,18 +304,16 @@ sig = printmethod(Docs.Binding(Main, :f), f, first(methods(f)))
274304
"""
275305
function printmethod(buffer::IOBuffer, binding::Docs.Binding, func, method::Method, typesig)
276306
# TODO: print qualified?
277-
print(buffer, binding.var)
278-
print(buffer, "(")
279-
local args = arguments(method)
280-
local where_syntax = []
307+
local args = string.(arguments(method))
308+
local kws = string.(keywords(func, method))
281309

282310
# find inner tuple type
283-
function f(t)
311+
function find_inner_tuple_type(t)
284312
# t is always either a UnionAll which represents a generic type or a Tuple where each parameter is the argument
285313
if t isa DataType && t <: Tuple
286314
t
287315
elseif t isa UnionAll
288-
f(t.body)
316+
find_inner_tuple_type(t.body)
289317
else
290318
error("Expected `typeof($t)` to be `Tuple` or `UnionAll` but found `$typeof(t)`")
291319
end
@@ -309,45 +337,35 @@ function printmethod(buffer::IOBuffer, binding::Docs.Binding, func, method::Meth
309337
typ
310338
end
311339

312-
for (i, sym) in enumerate(args)
313-
if typesig isa UnionAll
314-
# e.g. Tuple{Vector{T}} where T<:Number
315-
# or Tuple{String, T, T} where T<:Number
316-
# or Tuple{Type{T}, String, Union{Nothing, Function}} where T<:Number
317-
t = [x for x in f(typesig).types]
318-
t = [get_typesig(x, x) for x in t][i]
319-
else
320-
# e.g. Tuple{Vector{Int}}
321-
t = typesig.types[i]
322-
end
340+
# if `typesig` is an UnionAll, it may be
341+
# e.g. Tuple{Vector{T}} where T<:Number
342+
# or Tuple{String, T, T} where T<:Number
343+
# or Tuple{Type{T}, String, Union{Nothing, Function}} where T<:Number
344+
# in the other case, it's usually something like Tuple{Vector{Int}}.
345+
argtypes = typesig isa UnionAll ?
346+
[get_typesig(t, t) for t in find_inner_tuple_type(typesig).types] :
347+
collect(typesig.types)
348+
349+
args = map(args, argtypes) do arg,t
350+
type = ""
351+
suffix = ""
323352
if isvarargtype(t)
324-
elt = vararg_eltype(t)
325-
if elt === Any
326-
print(buffer, "$sym...")
327-
else
328-
print(buffer, "$sym::$elt...")
329-
end
330-
elseif t === Any
331-
print(buffer, sym)
332-
else
333-
print(buffer, "$sym::$t")
353+
t = vararg_eltype(t)
354+
suffix = "..."
334355
end
335-
336-
if i != length(args)
337-
print(buffer, ", ")
356+
if t!==Any
357+
type = "::$t"
338358
end
359+
360+
"$arg$type$suffix"
339361
end
340-
local kws = keywords(func, method)
341-
if !isempty(kws)
342-
print(buffer, "; ")
343-
join(buffer, kws, ", ")
344-
end
345-
print(buffer, ")")
362+
346363
rt = Base.return_types(func, typesig)
347-
if length(rt) >= 1 && rt[1] !== Nothing && rt[1] !== Union{}
348-
print(buffer, " -> $(rt[1])")
349-
end
350-
buffer
364+
365+
return printmethod_format(buffer, string(binding.var), args, string.(kws);
366+
return_type =
367+
length(rt) >= 1 && rt[1] !== Nothing && rt[1] !== Union{} ?
368+
" -> $(rt[1])" : "")
351369
end
352370

353371
printmethod(b, f, m) = String(take!(printmethod(IOBuffer(), b, f, m)))
@@ -402,7 +420,7 @@ function keywords(func, m::Method)
402420
# table is a MethodTable object. For some reason, the :kwsorter field is not always
403421
# defined. An undefined kwsorter seems to imply that there are no methods in the
404422
# MethodTable with keyword arguments.
405-
if isdefined(table, :kwsorter)
423+
if !(Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0) || isdefined(table, :kwsorter)
406424
# Fetching method keywords stolen from base/replutil.jl:572-576 (commit 3b45cdc9aab0):
407425
kwargs = VERSION < v"1.4.0-DEV.215" ? Base.kwarg_decl(m, typeof(table.kwsorter)) : Base.kwarg_decl(m)
408426
if isa(kwargs, Vector) && length(kwargs) > 0
@@ -432,12 +450,21 @@ args = arguments(first(methods(f)))
432450
```
433451
"""
434452
function arguments(m::Method)
435-
local template = get_method_source(m)
436-
if isdefined(template, :slotnames)
437-
local args = map(template.slotnames[1:nargs(m)]) do arg
453+
local argnames = nothing
454+
if isdefined(m, :generator)
455+
# Generated function.
456+
argnames = m.generator.argnames
457+
else
458+
local template = get_method_source(m)
459+
if isdefined(template, :slotnames)
460+
argnames = template.slotnames
461+
end
462+
end
463+
if argnames !== nothing
464+
local args = map(argnames[1:nargs(m)]) do arg
438465
arg === Symbol("#unused#") ? "_" : arg
439466
end
440-
return filter(arg -> arg !== Symbol("#self#"), args)
467+
return filter(arg -> arg !== Symbol("#self#") && arg !== Symbol("#ctor-self#"), args)
441468
end
442469
return Symbol[]
443470
end

test/TestModule/M.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ h_2(x::A{Int}) = x
1515
h_3(x::A{T}) where {T} = x
1616
h_4(x, ::Int, z) = x
1717

18+
@generated g_1(x) = x
19+
@generated g_2(x::String) = x
20+
1821
i_1(x; y = x) = x * y
1922
i_2(x::Int; y = x) = x * y
2023
i_3(x::T; y = x) where {T} = x * y

test/templates.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const K = 1
3535
"mutable struct `T`"
3636
mutable struct T end
3737

38+
"mutable struct `ISSUE_115{S}`"
39+
mutable struct ISSUE_115{S} end
40+
3841
"`@kwdef` struct `S`"
3942
Base.@kwdef struct S end
4043

@@ -101,6 +104,9 @@ module OtherModule
101104
"mutable struct `T`"
102105
mutable struct T end
103106

107+
"mutable struct `ISSUE_115{S}`"
108+
mutable struct ISSUE_115{S} end
109+
104110
"macro `@m`"
105111
macro m(x) end
106112

0 commit comments

Comments
 (0)