Skip to content
Merged
4 changes: 2 additions & 2 deletions src/notebook/Notebook.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 19 additions & 5 deletions src/packages/PkgCompat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ module PkgCompat

export package_versions, package_completions

import REPL
import Pkg
import Pkg.Types: VersionRange
import RegistryInstances
import ..Pluto

@static if VERSION<v"1.11"
const REPLMode=Pkg.REPLMode
else
const REPLMode = Base.get_extension(Pkg, :REPLExt)
end

# Should be in Base
flatmap(args...) = vcat(map(args...)...)

Expand Down Expand Up @@ -171,14 +178,15 @@ _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."
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
Expand Down Expand Up @@ -264,7 +272,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
Expand All @@ -282,10 +296,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())
Expand Down
14 changes: 7 additions & 7 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/runner/PlutoRunner/src/PlutoRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ end
function show_richest_withreturned(context::IOContext, @nospecialize(args))
buffer = IOBuffer(; sizehint=0)
val = show_richest(IOContext(buffer, context), args)
return (resize!(buffer.data, buffer.size), val)
return (view(buffer.data,1:buffer.size), val)
end

"Super important thing don't change."
Expand Down