From c6c7ed502d7ce304d2e36e87233e8e0fcbb90f3a Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Mon, 6 May 2024 22:19:43 +0200 Subject: [PATCH] improve precompilation for `st` in the Pkg REPL (#3893) --- ext/REPLExt/REPLExt.jl | 20 +++++++++++--------- ext/REPLExt/precompile.jl | 4 ++++ src/precompile.jl | 7 +++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ext/REPLExt/REPLExt.jl b/ext/REPLExt/REPLExt.jl index 834cc01fca..b787f3d3a9 100644 --- a/ext/REPLExt/REPLExt.jl +++ b/ext/REPLExt/REPLExt.jl @@ -106,6 +106,16 @@ function do_cmds(repl::REPL.AbstractREPL, commands::Union{String, Vector{Command end end +function on_done(s, buf, ok, repl) + ok || return REPL.transition(s, :abort) + input = String(take!(buf)) + REPL.reset(repl) + do_cmds(repl, input) + REPL.prepare_next(repl) + REPL.reset_state(s) + s.current_mode.sticky || REPL.transition(s, main) +end + # Set up the repl Pkg REPLMode function create_mode(repl::REPL.AbstractREPL, main::LineEdit.Prompt) pkg_mode = LineEdit.Prompt(promptf; @@ -122,15 +132,7 @@ function create_mode(repl::REPL.AbstractREPL, main::LineEdit.Prompt) search_prompt, skeymap = LineEdit.setup_search_keymap(hp) prefix_prompt, prefix_keymap = LineEdit.setup_prefix_keymap(hp, pkg_mode) - pkg_mode.on_done = (s, buf, ok) -> begin - ok || return REPL.transition(s, :abort) - input = String(take!(buf)) - REPL.reset(repl) - do_cmds(repl, input) - REPL.prepare_next(repl) - REPL.reset_state(s) - s.current_mode.sticky || REPL.transition(s, main) - end + pkg_mode.on_done = (s, buf, ok) -> Base.@invokelatest(on_done(s, buf, ok, repl)) mk = REPL.mode_keymap(main) diff --git a/ext/REPLExt/precompile.jl b/ext/REPLExt/precompile.jl index 268cbc1204..0b6630edb6 100644 --- a/ext/REPLExt/precompile.jl +++ b/ext/REPLExt/precompile.jl @@ -28,6 +28,10 @@ let end copy!(DEPOT_PATH, original_depot_path) copy!(LOAD_PATH, original_load_path) + + Base.precompile(Tuple{typeof(REPL.LineEdit.complete_line), REPLExt.PkgCompletionProvider, REPL.LineEdit.PromptState}) + Base.precompile(Tuple{typeof(REPL.REPLCompletions.completion_text), REPL.REPLCompletions.PackageCompletion}) + Base.precompile(Tuple{typeof(REPLExt.on_done), REPL.LineEdit.MIState, Base.GenericIOBuffer{Memory{UInt8}}, Bool, REPL.LineEditREPL}) end if Base.generating_output() diff --git a/src/precompile.jl b/src/precompile.jl index 72b796a5cb..b27fb913b5 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -152,6 +152,13 @@ let Base.precompile(Tuple{typeof(Pkg.API.status)}) Base.precompile(Tuple{typeof(Pkg.Types.read_project_compat),Base.Dict{String,Any},Pkg.Types.Project,},) Base.precompile(Tuple{typeof(Pkg.Versions.semver_interval),Base.RegexMatch}) + + Base.precompile(Tuple{typeof(Pkg.REPLMode.do_cmds), Array{Pkg.REPLMode.Command, 1}, Base.TTY}) + + Base.precompile(Tuple{typeof(Pkg.Types.read_project_workspace), Base.Dict{String, Any}, Pkg.Types.Project}) + Base.precompile(Tuple{Type{Pkg.REPLMode.QString}, String, Bool}) + Base.precompile(Tuple{typeof(Pkg.REPLMode.parse_package), Array{Pkg.REPLMode.QString, 1}, Base.Dict{Symbol, Any}}) + Base.precompile(Tuple{Type{Pkg.REPLMode.Command}, Pkg.REPLMode.CommandSpec, Base.Dict{Symbol, Any}, Array{Pkg.Types.PackageSpec, 1}}) end copy!(DEPOT_PATH, original_depot_path) copy!(LOAD_PATH, original_load_path)