From 543edd865a4c95518104cdf68fa0ffa1fe305989 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 2 Apr 2024 15:40:10 +0200 Subject: [PATCH 1/2] Support docstrings for `@connector`s and `@component`s --- src/systems/abstractsystem.jl | 2 +- test/components.jl | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/systems/abstractsystem.jl b/src/systems/abstractsystem.jl index c808aa4057..a6b31843d1 100644 --- a/src/systems/abstractsystem.jl +++ b/src/systems/abstractsystem.jl @@ -1555,7 +1555,7 @@ function component_post_processing(expr, isconnector) args = sig.args[2:end] quote - function $fname($(args...)) + $Base.@__doc__ function $fname($(args...)) # we need to create a closure to escape explicit return in `body`. res = (() -> $body)() if $isdefined(res, :gui_metadata) && $getfield(res, :gui_metadata) === nothing diff --git a/test/components.jl b/test/components.jl index d4bedb8eb7..0acf89aa64 100644 --- a/test/components.jl +++ b/test/components.jl @@ -298,3 +298,25 @@ rc_eqs = [connect(capacitor.n, resistor.p) sys = structural_simplify(rc_model) prob = ODEProblem(sys, u0, (0, 10.0)) sol = solve(prob, Tsit5()) + +@testset "docstrings (#1155)" begin + """ + Hey there, Pin1! + """ + @connector function Pin1(; name) + @variables t + sts = @variables v(t)=1.0 i(t)=1.0 + ODESystem(Equation[], t, sts, []; name = name) + end + @test string(Base.doc(Pin1)) == "Hey there, Pin1!\n" + + """ + Hey there, Pin2! + """ + @component function Pin2(; name) + @variables t + sts = @variables v(t)=1.0 i(t)=1.0 + ODESystem(Equation[], t, sts, []; name = name) + end + @test string(Base.doc(Pin2)) == "Hey there, Pin2!\n" +end \ No newline at end of file From 52ca36493a166342ee1528ceca0df6a44c477144 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 2 Apr 2024 15:43:37 +0200 Subject: [PATCH 2/2] Fix format --- test/components.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/components.jl b/test/components.jl index 0acf89aa64..d9233558c3 100644 --- a/test/components.jl +++ b/test/components.jl @@ -319,4 +319,4 @@ sol = solve(prob, Tsit5()) ODESystem(Equation[], t, sts, []; name = name) end @test string(Base.doc(Pin2)) == "Hey there, Pin2!\n" -end \ No newline at end of file +end