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

Preserve scope of Symbol to fix #1128 #1238

Merged
merged 4 commits into from
Jul 7, 2021
Merged

Conversation

melonedo
Copy link
Contributor

@melonedo melonedo commented Jun 12, 2021

Replace Core.eval with Docs.Binding for Symbols
Fix #1128

Replace `Core.eval` with `Docs.Binding`
@fonsp
Copy link
Owner

fonsp commented Jun 12, 2021

Thanks! Can you see if it's easy to add a test to

Pluto.jl/test/Dynamic.jl

Lines 146 to 150 in aef57ba

@testset "Docs" begin
@test occursin("square root", Pluto.PlutoRunner.doc_fetcher("sqrt", Main)[1])
@test occursin("square root", Pluto.PlutoRunner.doc_fetcher("Base.sqrt", Main)[1])
@test occursin("No documentation found", Pluto.PlutoRunner.doc_fetcher("Base.findmeta", Main)[1])
end
? If not, let us know

You might want to create a test module to run the doc queries in:

m = Module()
Core.eval(m, quote
	"Look at me!"
	f(x) = x

	...
end)

Pluto.PlutoRunner.doc_fetcher("sqrt", m)
Pluto.PlutoRunner.doc_fetcher("f", m)
...

@melonedo
Copy link
Contributor Author

Thanks! Can you see if it's easy to add a test to

Pluto.jl/test/Dynamic.jl

Lines 146 to 150 in aef57ba

@testset "Docs" begin
@test occursin("square root", Pluto.PlutoRunner.doc_fetcher("sqrt", Main)[1])
@test occursin("square root", Pluto.PlutoRunner.doc_fetcher("Base.sqrt", Main)[1])
@test occursin("No documentation found", Pluto.PlutoRunner.doc_fetcher("Base.findmeta", Main)[1])
end

? If not, let us know

You might want to create a test module to run the doc queries in:

m = Module()
Core.eval(m, quote
	"Look at me!"
	f(x) = x

	...
end)

Pluto.PlutoRunner.doc_fetcher("sqrt", m)
Pluto.PlutoRunner.doc_fetcher("f", m)
...

Oh I did not notice you had instructions for local module, and I struggled on it for some time. Now I added the tests.

I also noticed the expression "m.x" is also untested, but I could not properly test it in a local module, so I marked them as broken.

@fonsp
Copy link
Owner

fonsp commented Jun 14, 2021

You can create modules inside modules:

Core.eval(m, quote
module Hello
"fun"
f(x) = x
end

end)

Core.eval(m, :(Hello.f))

@melonedo
Copy link
Contributor Author

You can create modules inside modules:

Core.eval(m, quote
module Hello
"fun"
f(x) = x
end

end)

Core.eval(m, :(Hello.f))
julia> Core.eval(m, quote
       module Hello
       "fun"
       f(x) = x
       end

       end)
ERROR: syntax: "module" expression not at top level
Stacktrace:
 [1] top-level scope
   @ none:1
 [2] eval(m::Module, e::Any)
   @ Core .\boot.jl:360
 [3] top-level scope
   @ REPL[89]:1

This also occurs if I use it in a .jl file.

@fonsp
Copy link
Owner

fonsp commented Jun 14, 2021

Ah I see, you can't wrap it in a quote:

Core.eval(m, :(
module Hello
"fun"
f(x) = x
end

))

Core.eval(m, quote
g(x) = x
end)

Core.eval(m, :(Hello.f))

@melonedo
Copy link
Contributor Author

Ah I see, you can't wrap it in a quote:

Core.eval(m, :(
module Hello
"fun"
f(x) = x
end

))

Core.eval(m, quote
g(x) = x
end)

Core.eval(m, :(Hello.f))

Thanks!

@fonsp fonsp merged commit 7a1d793 into fonsp:main Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Live docs doesn't return most specific doc
2 participants