Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out more doc signature expressions #774

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Revise"
uuid = "295af30f-e4ad-537b-8983-00126c2a3abe"
version = "3.5.7"
version = "3.5.8"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Expand Down
11 changes: 10 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,20 @@ istrivial(a) = a === nothing || isa(a, LineNumberNode)

isgoto(stmt) = isa(stmt, Core.GotoNode) | isexpr(stmt, :gotoifnot)

function unwrap_where(ex::Expr)
while isexpr(ex, :where)
ex = ex.args[1]
end
return ex
end

function pushex!(exsigs::ExprsSigs, ex::Expr)
uex = unwrap(ex)
if is_doc_expr(uex)
body = uex.args[4]
if isa(body, Expr) && body.head !== :call # don't trigger for docexprs like `"docstr" f(x::Int)`
# Don't trigger for exprs where the documented expression is just a signature
# (e.g. `"docstr" f(x::Int)`, `"docstr" f(x::T) where T` etc.)
if isa(body, Expr) && unwrap_where(body).head !== :call
exsigs[RelocatableExpr(body)] = nothing
end
if length(uex.args) < 5
Expand Down
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,23 @@ const issue639report = []
pop!(LOAD_PATH)
end

do_test("doc expr signature") && @testset "Docstring attached to signatures" begin
md = Revise.ModuleExprsSigs(Main)
Revise.parse_source!(md, """
module DocstringSigsOnly
function f end
"basecase" f(x)
"basecase with type" f(x::Int)
"basecase no varname" f(::Float64)
"where" f(x::T) where T <: Int8
"where no varname" f(::T) where T <: String
end
""", "test2", Main)
# Simply test that the "bodies" of the doc exprs are not included as
# standalone expressions.
@test length(md[Main.DocstringSigsOnly]) == 6 # 1 func + 5 doc exprs
end

do_test("Undef in docstrings") && @testset "Undef in docstrings" begin
fn = Base.find_source_file("abstractset.jl") # has lots of examples of """str""" func1, func2
mexsold = Revise.parse_source(fn, Base)
Expand Down
Loading