Skip to content

Commit

Permalink
improve precompilation for st in the Pkg REPL (JuliaLang#3893)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored May 6, 2024
1 parent ed7a8dc commit c6c7ed5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
20 changes: 11 additions & 9 deletions ext/REPLExt/REPLExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions ext/REPLExt/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c6c7ed5

Please sign in to comment.