diff --git a/src/notebook/Notebook.jl b/src/notebook/Notebook.jl index 0a34c59857..858081d9c3 100644 --- a/src/notebook/Notebook.jl +++ b/src/notebook/Notebook.jl @@ -44,8 +44,8 @@ Base.@kwdef mutable struct Notebook # per notebook compiler options # nothing means to use global session compiler options compiler_options::Union{Nothing,Configuration.CompilerOptions}=nothing - # nbpkg_ctx::Union{Nothing,PkgContext}=nothing - nbpkg_ctx::Union{Nothing,PkgContext}=PkgCompat.create_empty_ctx() + nbpkg_ctx::Union{Nothing,PkgContext}=nothing + # nbpkg_ctx::Union{Nothing,PkgContext}=PkgCompat.create_empty_ctx() nbpkg_ctx_instantiated::Bool=false nbpkg_restart_recommended_msg::Union{Nothing,String}=nothing nbpkg_restart_required_msg::Union{Nothing,String}=nothing diff --git a/src/packages/PkgCompat.jl b/src/packages/PkgCompat.jl index f0e857fc00..c84a9767ec 100644 --- a/src/packages/PkgCompat.jl +++ b/src/packages/PkgCompat.jl @@ -2,11 +2,21 @@ module PkgCompat export package_versions, package_completions +import REPL import Pkg import Pkg.Types: VersionRange import RegistryInstances import ..Pluto + + + +@static if isdefined(Pkg,:REPLMode) && isdefined(Pkg.REPLMode,:complete_remote_package) + const REPLMode=Pkg.REPLMode +else + const REPLMode = Base.get_extension(Pkg, :REPLExt) +end + # Should be in Base flatmap(args...) = vcat(map(args...)...) @@ -171,7 +181,7 @@ _get_registries() = RegistryInstances.reachable_registries() # (✅ "Public" API using RegistryInstances) "The cached output value of `_get_registries`." -const _parsed_registries = Ref(_get_registries()) +const _parsed_registries = Ref(RegistryInstances.RegistryInstance[]) # (✅ "Public" API using RegistryInstances) "Re-parse the installed registries from disk." @@ -179,6 +189,7 @@ function refresh_registry_cache() _parsed_registries[] = _get_registries() end + # ⚠️✅ Internal API with fallback const _updated_registries_compat = @static if isdefined(Pkg, :UPDATED_REGISTRY_THIS_SESSION) && Pkg.UPDATED_REGISTRY_THIS_SESSION isa Ref{Bool} Pkg.UPDATED_REGISTRY_THIS_SESSION @@ -264,7 +275,13 @@ end # ⚠️ Internal API with fallback is_stdlib(package_name::AbstractString) = package_name ∈ _stdlibs() -global_ctx = PkgContext() + + +# Initial fill of registry cache +function __init__() + refresh_registry_cache() + global global_ctx=PkgContext() +end ### # Package names @@ -282,10 +299,10 @@ end function _registered_package_completions(partial_name::AbstractString)::Vector{String} # compat try - @static if hasmethod(Pkg.REPLMode.complete_remote_package, (String,)) - Pkg.REPLMode.complete_remote_package(partial_name) + @static if hasmethod(REPLMode.complete_remote_package, (String,)) + REPLMode.complete_remote_package(partial_name) else - Pkg.REPLMode.complete_remote_package(partial_name, 1, length(partial_name))[1] + REPLMode.complete_remote_package(partial_name, 1, length(partial_name))[1] end catch e @warn "Pkg compat: failed to autocomplete packages" exception=(e,catch_backtrace()) diff --git a/src/precompile.jl b/src/precompile.jl index d7bbb8bd6b..d9373a20cd 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -36,13 +36,13 @@ PrecompileTools.@compile_workload begin Pluto.topological_order(topology, topology.cell_order) end - let - io = IOBuffer() - # Notebook file format. - Pluto.save_notebook(io, nb) - seekstart(io) - Pluto.load_notebook_nobackup(io, "whatever.jl") - end + # let + # io = IOBuffer() + # # Notebook file format. + # Pluto.save_notebook(io, nb) + # seekstart(io) + # Pluto.load_notebook_nobackup(io, "whatever.jl") + # end let state1 = Pluto.notebook_to_js(nb)