Skip to content

Commit 31a92d6

Browse files
committed
Support autoinstall prompt
1 parent be024fd commit 31a92d6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/BasicAutoloads.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,27 @@ function (al::_Autoload)(@nospecialize(expr))
5555
target in al.already_ran && return expr
5656
push!(al.already_ran, target)
5757
try
58+
try_autoinstall(target)
5859
Main.eval(target)
5960
catch err
6061
@info "Failed to run `$target`" exception=err
6162
end
6263
end
6364
expr
6465
end
66+
function try_autoinstall(expr::Expr)
67+
REPL = Base.loaded_modules[Base.PkgId(Base.UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL")]
68+
isdefined(REPL, :install_packages_hooks) || return
69+
expr.head in (:using, :import) || return
70+
for arg in expr.args
71+
arg isa Expr && arg.head == :. && length(arg.args) == 1 || continue
72+
mod = only(arg.args)
73+
mod isa Symbol && Base.identify_package(String(mod)) === nothing || continue
74+
for f in REPL.install_packages_hooks
75+
Base.invokelatest(f, [mod]) && break
76+
end
77+
end
78+
end
6579

6680
function _register_ast_transform(ast_transform)
6781
if isdefined(Base, :active_repl_backend)

0 commit comments

Comments
 (0)