Skip to content

Commit 4d295e4

Browse files
authored
refine breakpoint printing (#99)
1 parent e302d48 commit 4d295e4

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Debugger.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using REPL.LineEdit
1010
using REPL.REPLCompletions
1111

1212
using CodeTracking
13-
using JuliaInterpreter: JuliaInterpreter, Frame, @lookup, FrameCode, BreakpointRef, debug_command, leaf, root
13+
using JuliaInterpreter: JuliaInterpreter, Frame, @lookup, FrameCode, BreakpointRef, debug_command, leaf, root, BreakpointState
1414

1515
using JuliaInterpreter: pc_expr, moduleof, linenumber, extract_args,
1616
root, caller, whereis, get_return, nstatements

src/printing.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ end
7575

7676
function breakpoint_linenumbers(frame::Frame)
7777
framecode = frame.framecode
78-
breakpoint_lines = Int[]
78+
breakpoint_lines = Dict{Int, BreakpointState}()
7979
for stmtidx in 1:length(framecode.breakpoints)
8080
isassigned(framecode.breakpoints, stmtidx) || continue
8181
bp = framecode.breakpoints[stmtidx]
82-
push!(breakpoint_lines, JuliaInterpreter.linenumber(frame, stmtidx))
82+
line = JuliaInterpreter.linenumber(frame, stmtidx)
83+
breakpoint_lines[line] = bp
8384
end
8485
return breakpoint_lines
8586
end
@@ -199,8 +200,14 @@ end
199200

200201

201202
const RESET = Crayon(reset = true)
203+
function breakpoint_char(bp::BreakpointState)
204+
if bp.isactive
205+
return bp.condition === JuliaInterpreter.truecondition ? '' : ''
206+
end
207+
return bp.condition === JuliaInterpreter.falsecondition ? ' ' : ''
208+
end
202209

203-
function print_sourcecode(io::IO, code::String, line::Integer, defline::Integer, breakpoint_lines::Vector{Int} = [])
210+
function print_sourcecode(io::IO, code::String, line::Integer, defline::Integer, breakpoint_lines::Dict{Int, BreakpointState} = Dict{Int, BreakpointState}())
204211
code = highlight_code(code; context=io)
205212
file = SourceFile(code)
206213
startoffset, stopoffset = compute_source_offsets(code, file.offsets[line], defline, line+NUM_SOURCE_LINES_UP_DOWN[]; file=file)
@@ -238,12 +245,10 @@ function print_sourcecode(io::IO, code::String, line::Integer, defline::Integer,
238245
code[i] = code[i][min_indentation+1:end]
239246
end
240247

241-
filter!(x -> x in(startline:stopline), breakpoint_lines)
242-
243248
for textline in code
244-
break_on_line = lineno in breakpoint_lines
249+
break_on_line = haskey(breakpoint_lines, lineno)
245250
prefix = (" ", :normal)
246-
break_on_line && (prefix = ("", :light_red))
251+
break_on_line && (prefix = (breakpoint_char(breakpoint_lines[lineno]), :light_red))
247252
lineno == current_line && (prefix = (">", :yellow))
248253
printstyled(io,
249254
string(prefix[1], lpad(lineno, stoplinelength), " "),

0 commit comments

Comments
 (0)