timholy / Revise.jl

Automatically update function definitions in a running Julia session
https://timholy.github.io/Revise.jl/stable
Other
1.21k stars 110 forks source link

Revise chokes on comments between docstring and function #253

Closed thofma closed 5 years ago

thofma commented 5 years ago

Thanks again for your amazing work @timholy. After updating to v2.0.1, I noticed the following regression: Revise now refuses/fails to track a file if there is a comment between a docstring and a function definition, like in:

@doc doc"""
bla
"""
# s
function f() 
  return 1
end

The error is:

ERROR: BoundsError: attempt to access 3-element Array{Any,1} at index [4]
Stacktrace:
 [1] getindex at ./array.jl:731 [inlined]
 [2] #split_expressions!#19(::Bool, ::String, ::Function, ::Array{Tuple{Module,Expr},1}, ::Dict{Module,Array{Expr,1}}, ::Expr, ::Module, ::Expr) at /home/blabla/.julia/packages/JuliaInterpreter/62ZyY/src/construct.jl:419
 [3] #split_expressions! at ./none:0 [inlined]
 [4] #split_expressions!#20(::String, ::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:extract_docexprs,),Tuple{Bool}}}, ::Function, ::Array{Tuple{Module,Expr},1}, ::Dict{Module,Array{Expr,1}}, ::Expr, ::Module, ::Array{Any,1}) at /home/blabla/.julia/packages/JuliaInterpreter/62ZyY/src/construct.jl:438
 [5] #split_expressions! at ./none:0 [inlined]
 [6] #split_expressions!#19(::Bool, ::String, ::Function, ::Array{Tuple{Module,Expr},1}, ::Dict{Module,Array{Expr,1}}, ::Expr, ::Module, ::Expr) at /home/blabla/.julia/packages/JuliaInterpreter/62ZyY/src/construct.jl:400
 [7] #split_expressions!#18 at ./none:0 [inlined]
 [8] #split_expressions! at ./none:0 [inlined]
 [9] parse_source!(::OrderedCollections.OrderedDict{Module,OrderedCollections.OrderedDict{Revise.RelocatableExpr,Union{Nothing, Array{Any,1}}}}, ::String, ::String, ::Module) at /home/blabla/.julia/dev/Revise/src/parsing.jl:44
 [10] parse_source!(::OrderedCollections.OrderedDict{Module,OrderedCollections.OrderedDict{Revise.RelocatableExpr,Union{Nothing, Array{Any,1}}}}, ::String, ::Module) at /home/blabla/.julia/dev/Revise/src/parsing.jl:27
 [11] parse_source at /home/blabla/.julia/dev/Revise/src/parsing.jl:10 [inlined]
 [12] track(::Module, ::String) at /home/blabla/.julia/dev/Revise/src/Revise.jl:585
 [13] includet(::String) at /home/blabla/.julia/dev/Revise/src/Revise.jl:617

P.S. It also chokes on empty files.

thofma commented 5 years ago

Looking at the documentation again (https://docs.julialang.org/en/v1/manual/documentation/index.html), I read that "Note that no blank lines or comments may intervene between a docstring and the documented object.".

So at the end, this is not a bug in Revise/JuliaInterpreter?

timholy commented 5 years ago

Right, watch what happens at the REPL:

julia> """
       bla
       """
       # s
"bla\n"

julia> function f() 
         return 1
       end
f (generic function with 1 method)

help?> f
search: f fd for fma fld fld1 fill fdio frexp foldr foldl flush floor float first fill! fetch fldmod filter falses finally foreach fldmod1 findmin findmax findall filter!

  No documentation found.

  f is a Function.

  # 1 method for generic function "f":
  [1] f() in Main at REPL[2]:2

The same is true if you put it in a file. Finally, using @doc explicitly is rarely necessary anymore.

But many thanks for the report about empty files! Fix coming.

thofma commented 5 years ago

I think you may have to reopen it (https://github.com/JuliaLang/julia/issues/31470#issuecomment-476368692). Or should I open a new issue over at JuliaDebugger?

timholy commented 5 years ago

https://github.com/JuliaDebug/JuliaInterpreter.jl/pull/221

thofma commented 5 years ago

Thanks!