Skip to content

Commit

Permalink
revert pkg_mode caching & tidy
Browse files Browse the repository at this point in the history
Reverts "Pkg REPL: cache `pkg_mode` lookup (JuliaLang#54359)"
as this function is replaced when Pkg loads by a simpler repl switch so no caching is needed
  • Loading branch information
IanButterworth committed Jun 1, 2024
1 parent 5b919ce commit cf74683
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1080,9 +1080,6 @@ setup_interface(
extra_repl_keymap::Any = repl.options.extra_keymap
) = setup_interface(repl, hascolor, extra_repl_keymap)

# we have to grab this after Pkg is loaded so cache it
pkg_mode::Union{Nothing,LineEdit.Prompt} = nothing

# This non keyword method can be precompiled which is important
function setup_interface(
repl::LineEditREPL,
Expand Down Expand Up @@ -1228,41 +1225,40 @@ function setup_interface(
end,
']' => function (s::MIState,o...)
if isempty(s) || position(LineEdit.buffer(s)) == 0
global pkg_mode
if pkg_mode === nothing
LineEdit.clear_line(LineEdit.terminal(s))
# use 6 .'s here because its the same width as the most likely `@v1.xx` env name
print(LineEdit.terminal(s), styled"{blue,bold:({gray:......}) pkg> }")
# spawn Pkg load to avoid blocking typing during loading. Typing will block if only 1 thread
t_replswitch = Threads.@spawn begin
pkgid = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
REPLExt = Base.require_stdlib(pkgid, "REPLExt")
if REPLExt isa Module && isdefined(REPLExt, :PkgCompletionProvider)
for mode in repl.interface.modes
if mode isa LineEdit.Prompt && mode.complete isa REPLExt.PkgCompletionProvider
pkg_mode = mode
break
end
end
end
if pkg_mode !== nothing
buf = copy(LineEdit.buffer(s))
transition(s, pkg_mode) do
LineEdit.state(s, pkg_mode).input_buffer = buf
# print a dummy pkg prompt while Pkg loads
LineEdit.clear_line(LineEdit.terminal(s))
# use 6 .'s here because its the same width as the most likely `@v1.xx` env name
print(LineEdit.terminal(s), styled"{blue,bold:({gray:......}) pkg> }")
pkg_mode = nothing
# spawn Pkg load to avoid blocking typing during loading. Typing will block if only 1 thread
t_replswitch = Threads.@spawn begin
pkgid = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
REPLExt = Base.require_stdlib(pkgid, "REPLExt")
if REPLExt isa Module && isdefined(REPLExt, :PkgCompletionProvider)
for mode in repl.interface.modes
if mode isa LineEdit.Prompt && mode.complete isa REPLExt.PkgCompletionProvider
pkg_mode = mode
break
end
end
end
Base.errormonitor(t_replswitch)
# while loading just accept all keys, no keymap functionality
while !istaskdone(t_replswitch)
c = read(stdin, Char)
istaskdone(t_replswitch) && break
edit_insert(s, c)
if pkg_mode !== nothing
buf = copy(LineEdit.buffer(s))
transition(s, pkg_mode) do
LineEdit.state(s, pkg_mode).input_buffer = buf
end
end
return
end
Base.errormonitor(t_replswitch)
# while loading just accept all keys, no keymap functionality
while !istaskdone(t_replswitch)
c = read(stdin, Char)
istaskdone(t_replswitch) && break
edit_insert(s, c)
end
else
edit_insert(s, ']')
end
edit_insert(s, ']')
end,

# Bracketed Paste Mode
Expand Down

0 comments on commit cf74683

Please sign in to comment.