Skip to content

Commit f75e172

Browse files
committed
inline evlauation during debugging
1 parent 97483de commit f75e172

4 files changed

Lines changed: 39 additions & 8 deletions

File tree

src/debugger/debugger.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using ..Atom, MacroTools, Lazy, Hiccup
1414

1515
include("breakpoints.jl")
1616
include("stepper.jl")
17+
include("eval.jl")
1718
include("repl.jl")
1819
include("workspace.jl")
1920
include("datatip.jl")

src/debugger/eval.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Atom: undefined
2+
3+
function interpret(code::AbstractString, state::DebuggerState = STATE)
4+
state.frame === nothing && return
5+
eval_code(active_frame(state), code)
6+
end
7+
8+
# if returned value is `Atom.undefined`, this means `code` shouldn't be evaluated within this frame
9+
function interpret_string(code, path, line, state::DebuggerState = STATE)
10+
# frame validation
11+
state.frame === nothing && return undefined
12+
13+
frame = state.frame
14+
scope = frame.framecode.scope
15+
16+
# only work for methods
17+
scope isa Module && return undefined
18+
19+
# path identity check
20+
path fullpath(getfile(frame)) && return undefined
21+
22+
# line number check
23+
defstr, startline = definition(String, scope)
24+
endline = startline + sum(c === '\n' for c in defstr)
25+
startline <= line <= endline || return undefined
26+
27+
return interpret(code, state)
28+
end

src/debugger/repl.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,3 @@ function LineEdit.complete_line(c::JunoDebuggerRPELCompletionProvider, s, state:
8787

8888
return ret, partial[range], should_complete
8989
end
90-
91-
# Evaluation
92-
function interpret(code::AbstractString, state::DebuggerState = STATE)
93-
state.frame === nothing && return
94-
eval_code(active_frame(state), code)
95-
end

src/eval.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ function evalshow(text, line, path, mod)
3131
result = hideprompt() do
3232
with_logger(JunoProgressLogger()) do
3333
withpath(path) do
34-
res = @errs include_string(mod, text, path, line)
34+
res = @errs if isdebugging() && (_res = JunoDebugger.interpret_string(text, path, line)) !== undefined
35+
_res
36+
else
37+
include_string(mod, text, path, line)
38+
end
3539

3640
if res isa EvalError
3741
Base.showerror(IOContext(stderr, :limit => true), res)
@@ -71,7 +75,11 @@ function eval(text, line, path, mod, errorinrepl = false)
7175
result = hideprompt() do
7276
with_logger(JunoProgressLogger()) do
7377
withpath(path) do
74-
res = @errs include_string(mod, text, path, line)
78+
res = @errs if isdebugging() && (_res = JunoDebugger.interpret_string(text, path, line)) !== undefined
79+
_res
80+
else
81+
include_string(mod, text, path, line)
82+
end
7583
if errorinrepl && res isa EvalError
7684
try
7785
Base.showerror(IOContext(stderr, :limit => true), res)

0 commit comments

Comments
 (0)