Skip to content

Commit 28b94ea

Browse files
IanButterworthKristofferC
authored and
KristofferC
committed
Pkg REPL: cache pkg_mode lookup (#54359)
Might as well avoid the effort on following Pkg repl switches. It doesn't make a noticeable difference on my machine, but who knows on slower systems. (cherry picked from commit 5a5624c)
1 parent 242229b commit 28b94ea

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

stdlib/REPL/src/REPL.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,9 @@ setup_interface(
10411041
extra_repl_keymap::Any = repl.options.extra_keymap
10421042
) = setup_interface(repl, hascolor, extra_repl_keymap)
10431043

1044+
# we have to grab this after Pkg is loaded so cache it
1045+
pkg_mode::Union{Nothing,LineEdit.Prompt} = nothing
1046+
10441047
# This non keyword method can be precompiled which is important
10451048
function setup_interface(
10461049
repl::LineEditREPL,
@@ -1186,18 +1189,20 @@ function setup_interface(
11861189
end,
11871190
']' => function (s::MIState,o...)
11881191
if isempty(s) || position(LineEdit.buffer(s)) == 0
1189-
pkgid = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
1190-
REPLExt = Base.require_stdlib(pkgid, "REPLExt")
1191-
pkg_mode = nothing
1192-
if REPLExt isa Module && isdefined(REPLExt, :PkgCompletionProvider)
1193-
for mode in repl.interface.modes
1194-
if mode isa LineEdit.Prompt && mode.complete isa REPLExt.PkgCompletionProvider
1195-
pkg_mode = mode
1196-
break
1192+
global pkg_mode
1193+
if pkg_mode === nothing
1194+
pkgid = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
1195+
REPLExt = Base.require_stdlib(pkgid, "REPLExt")
1196+
pkg_mode = nothing
1197+
if REPLExt isa Module && isdefined(REPLExt, :PkgCompletionProvider)
1198+
for mode in repl.interface.modes
1199+
if mode isa LineEdit.Prompt && mode.complete isa REPLExt.PkgCompletionProvider
1200+
pkg_mode = mode
1201+
break
1202+
end
11971203
end
11981204
end
11991205
end
1200-
# TODO: Cache the `pkg_mode`?
12011206
if pkg_mode !== nothing
12021207
buf = copy(LineEdit.buffer(s))
12031208
transition(s, pkg_mode) do

0 commit comments

Comments
 (0)