-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathrepl.jl
More file actions
89 lines (70 loc) · 2.65 KB
/
repl.jl
File metadata and controls
89 lines (70 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using REPL
using REPL.LineEdit
using REPL.REPLCompletions
using JuliaInterpreter: moduleof, locals, eval_code
import ..Atom: @msg
const normal_prefix = @static Sys.iswindows() ? "\e[33m" : "\e[38;5;166m"
const compiled_prefix = "\e[96m"
function debugprompt()
try
panel = REPL.LineEdit.Prompt("debug> ";
prompt_prefix = isCompileMode() ? compiled_prefix : normal_prefix,
prompt_suffix = Base.text_colors[:normal],
complete = JunoDebuggerRPELCompletionProvider(),
on_enter = REPL.return_callback)
panel.hist = REPL.REPLHistoryProvider(Dict{Symbol,Any}(:junodebug => panel))
REPL.history_reset_state(panel.hist)
search_prompt, skeymap = LineEdit.setup_search_keymap(panel.hist)
search_prompt.complete = REPL.LatexCompletions()
panel.on_done = (s, buf, ok) -> begin
if !ok
LineEdit.transition(s, :abort)
REPL.LineEdit.reset_state(s)
return false
end
@msg working()
line = String(take!(buf))
if isempty(line)
@msg doneWorking()
return true
end
try
r = interpret(line)
r ≠ nothing && display(r)
catch err
display_error(stderr, err, stacktrace(catch_backtrace()))
end
println()
LineEdit.reset_state(s)
@msg doneWorking()
@msg updateWorkspace()
return true
end
panel.keymap_dict = LineEdit.keymap(Dict{Any,Any}[skeymap, LineEdit.history_keymap, LineEdit.default_keymap, LineEdit.escape_defaults])
REPL.run_interface(Base.active_repl.t, REPL.LineEdit.ModalInterface([panel, search_prompt]))
catch e
@msg doneWorking()
@msg updateWorkspace()
e isa InterruptException || rethrow(e)
end
end
# completions
struct JunoDebuggerRPELCompletionProvider <: REPL.CompletionProvider end
function LineEdit.complete_line(c::JunoDebuggerRPELCompletionProvider, s, state::DebuggerState = STATE)
partial = REPL.beforecursor(s.input_buffer)
full = LineEdit.input_string(s)
frame = active_frame(state)
# module-aware repl backend completions
comps, range, should_complete = REPLCompletions.completions(full, lastindex(partial), moduleof(frame))
ret = map(REPLCompletions.completion_text, comps)
# local completions -- should be shown first
@>> locals(frame) filter!(v -> begin
# ref: https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/master/src/utils.jl#L365-L370
if v.name == Symbol("#self") && (v.value isa Type || sizeof(v.value) == 0)
return false
else
return startswith(string(v.name), partial)
end
end) map(v -> string(v.name)) prepend!(ret) unique!
return ret, partial[range], should_complete
end