Hello everybody,
My goal is to run a notebook-like analysis script interactively in the REPL (without reloading neither the REPL nor the LSP) while changing/adding code. The same applies to test scripts.
I divide the code in scripts and helper functions. The helpers are defined in modules (that can have interdependencies) and are part of a package.
The analysis scripts run in the same environment of the package, but are not included in the package. The same is valid for tests.
I got the impression that this setup follows julia best practices, but i’m a julia beginner and not really sure of it.
To reproduce the problem I’m having:
I use Julia 1.12
clone the repo at GitHub - JuliaLang/Example.jl: Example Julia package repo. · GitHub
-
add Revise to the package
-
add a script run.jl
# run.jl
using Revise
using Example
hello("julia")
Until this point all works perfectly, changing the already defined functions in src/Example.jl is no problem and JETLS, the REPL and Revise are all happy.
The problem comes if we edit src/Example.jl adding a new function:
module Example
export hello, domath, new_func
"""
hello(who::String)
Return "Hello, `who`".
"""
hello(who::String) = "Hello, $who"
"""
domath(x::Number)
Return `x + 5`.
"""
domath(x::Number) = x + 5
new_func() = "hello "
end
If now I try to use new_func in run.jl JETLS will show a not defined error. The REPL + Revise works well tough. The exact same happen for the test file in test folder.
As far as I understand this happens because JETLS analyzed the script in “script mode” and does not do a full analysis (?).
I found a couple of suggested tricks here, where one suggest to add to src/Example.jl something like:
@static if false
include("../run.jl")
end
But JETLS is too “smart” and this solution does not work. It also does not work if one moves the run.jl to the src folder and uses the same trick.
How do you guys actually do this?
I would really apreciate if you could share your thougts/solutions to this (I guess common) issue. Thanks!
Finally I’d like to take the opportunity to thank aviatesk for all the effort on JETLS, which is truly a great project, thanks!!