Skip to content

Commit 2a0938c

Browse files
authored
Support docstrings for @connectors and @components (#2602)
* Support docstrings for `@connector`s and `@component`s * Fix format
1 parent 4b06356 commit 2a0938c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/systems/abstractsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ function component_post_processing(expr, isconnector)
15551555
args = sig.args[2:end]
15561556

15571557
quote
1558-
function $fname($(args...))
1558+
$Base.@__doc__ function $fname($(args...))
15591559
# we need to create a closure to escape explicit return in `body`.
15601560
res = (() -> $body)()
15611561
if $isdefined(res, :gui_metadata) && $getfield(res, :gui_metadata) === nothing

test/components.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,25 @@ rc_eqs = [connect(capacitor.n, resistor.p)
298298
sys = structural_simplify(rc_model)
299299
prob = ODEProblem(sys, u0, (0, 10.0))
300300
sol = solve(prob, Tsit5())
301+
302+
@testset "docstrings (#1155)" begin
303+
"""
304+
Hey there, Pin1!
305+
"""
306+
@connector function Pin1(; name)
307+
@variables t
308+
sts = @variables v(t)=1.0 i(t)=1.0
309+
ODESystem(Equation[], t, sts, []; name = name)
310+
end
311+
@test string(Base.doc(Pin1)) == "Hey there, Pin1!\n"
312+
313+
"""
314+
Hey there, Pin2!
315+
"""
316+
@component function Pin2(; name)
317+
@variables t
318+
sts = @variables v(t)=1.0 i(t)=1.0
319+
ODESystem(Equation[], t, sts, []; name = name)
320+
end
321+
@test string(Base.doc(Pin2)) == "Hey there, Pin2!\n"
322+
end

0 commit comments

Comments
 (0)