From cf74683aacb9483f9d026b8392370025a327b50a Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Sat, 1 Jun 2024 12:44:07 +0200 Subject: [PATCH] revert pkg_mode caching & tidy Reverts "Pkg REPL: cache `pkg_mode` lookup (#54359)" as this function is replaced when Pkg loads by a simpler repl switch so no caching is needed --- stdlib/REPL/src/REPL.jl | 60 +++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index cf92d74e0508c..782644494aa2d 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -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, @@ -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