KristofferC / OhMyREPL.jl

Syntax highlighting and other enhancements for the Julia REPL
https://kristofferc.github.io/OhMyREPL.jl/latest/
Other
768 stars 60 forks source link

Script-style doctests don't appear in the REPL's `help?>` when OhMyREPL is loaded #293

Open navidcy opened 1 year ago

navidcy commented 1 year ago

I've been struggling with this for a bit and I think it has something to do with OhMyREPL.

I define a function foo with a docstring that includes a doctest with a "script" example. Then I ask for the help?> foo and if OhMyREPL is loaded then the doctest does not appear!

(Note that if I used a REPL example doctest then all is good!)

Here's a MWE.

Af first I load Julia without OhMyREPL. Everything looks OK. If then I load OhMyREPL and ask again of the docstring of foo the example is disappeared!

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.5 (2023-01-08)
 _/ |\__'_|_|_|\__'_|  |
|__/                   |

julia> """
           foo(x)

       A function called foo.

       Example
       =======
       ```jldoctest
       foo(2)
       # output
       2
   """
   foo(x) = x

foo

help?> foo search: foo floor pointer_from_objref OverflowError RoundFromZero unsafe_copyto! functionloc

foo(x)

A function called foo.

Example ≡≡≡≡≡≡≡≡≡

foo(2)

output

2

julia> using OhMyREPL

help?> foo search: foo floor pointer_from_objref OverflowError RoundFromZero unsafe_copyto! functionloc

foo(x)

A function called foo.

Example ≡≡≡≡≡≡≡≡≡

julia>

KristofferC commented 1 year ago

The issue here is that you are doing a jldoctest but you do not include the julia> prompt. Doing it as:

"""
           foo(x)

       A function called foo.

       Example
       =======
       ```jldoctest
       julia> foo(2) # <------------- note julia>
       # output
       2
   """
   foo(x) = x


Makes it work. I'll try fix this nonetheless.
navidcy commented 1 year ago

True. But without OhMyREPL it works both ways. So I was getting confused and puzzled why I wasn't seeing the docstring examples but others could see them.

navidcy commented 1 year ago

x-ref: https://discourse.julialang.org/t/doctests-dont-appear-in-repl-help-mode/98534