Skip to content

Commit 183c5b4

Browse files
authored
Some printing fixes (#306)
* do not try to syntax highlight files with non julia extensions * stop falling back to lowered code when CodeTracking cant find the method start we can instead just set `defline = 0` and thereby have an "unknown" method start while still showing the source code
1 parent c8faa28 commit 183c5b4

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/locationinfo.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@ function locinfo(frame::Frame)
77
ret = JuliaInterpreter.whereis(frame)
88
ret === nothing && return nothing
99
current_file, current_line = ret
10+
body_defline = CodeTracking.definition(String, meth)
1011
local body, defline
11-
try # https://github.com/timholy/CodeTracking.jl/issues/31
12-
body, defline = CodeTracking.definition(String, meth)
13-
catch
14-
return nothing
12+
unknown_start = false
13+
if body_defline === nothing
14+
unknown_start = true
15+
else
16+
body, defline = body_defline
17+
if deffile != current_file || defline > current_line
18+
unknown_start = true
19+
end
1520
end
16-
if deffile != current_file || defline > current_line
21+
if unknown_start
1722
isfile(current_file) || return nothing
1823
body = read(current_file, String)
1924
defline = 0 # We are not sure where the context start in cases like these, could be improved?
2025
end
21-
return defline, current_line, body
26+
return defline, deffile, current_line, body
2227
else
2328
println("not yet implemented")
2429
end
@@ -88,4 +93,4 @@ function locdesc(io, frame::Frame; current_line=false)
8893
path = string(_print_full_path[] ? meth.file : basename(String(meth.file)), ":", line)
8994
path = CodeTracking.replace_buildbot_stdlibpath(String(path))
9095
print(io, ") at ", path)
91-
end
96+
end

src/printing.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ function print_status(io::IO, frame::Frame; force_lowered=false)
134134
loc = locinfo(frame)
135135

136136
if loc !== nothing && !force_lowered
137-
defline, current_line, body = loc
137+
defline, deffile, current_line, body = loc
138138
breakpoint_lines = breakpoint_linenumbers(frame)
139-
ok = print_sourcecode(outbuf, body, current_line, defline, breakpoint_lines)
139+
ok = print_sourcecode(outbuf, body, current_line, defline, deffile, breakpoint_lines)
140140
if !ok
141141
printstyled(io, "failed to lookup source code, showing lowered code:\n"; color=Base.warn_color())
142142
print_codeinfo(outbuf, frame)
@@ -240,8 +240,11 @@ function breakpoint_char(bp::BreakpointState)
240240
return bp.condition === JuliaInterpreter.falsecondition ? ' ' : ''
241241
end
242242

243-
function print_sourcecode(io::IO, code::AbstractString, current_line::Integer, defline::Integer, breakpoint_lines::Dict{Int, BreakpointState} = Dict{Int, BreakpointState}())
244-
code = highlight_code(code; context=io)
243+
function print_sourcecode(io::IO, code::AbstractString, current_line::Integer, defline::Integer, deffile::AbstractString, breakpoint_lines::Dict{Int, BreakpointState} = Dict{Int, BreakpointState}())
244+
_, ext = splitext(deffile)
245+
if isempty(ext) || ext == ".jl"
246+
code = highlight_code(code; context=io)
247+
end
245248
file = SourceFile(code)
246249
current_offsetline = current_line - defline + 1
247250
checkbounds(Bool, file.offsets, current_offsetline) || return false

test/misc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ end
5656
frame = Debugger.@make_frame f()
5757
state = dummy_state(frame)
5858
execute_command(state, Val{:n}(), "n")
59-
defline, current_line, body = Debugger.locinfo(state.frame)
59+
defline, deffile, current_line, body = Debugger.locinfo(state.frame)
6060
@test occursin("handle_message(logger, level", body)
6161

6262
f_unicode() =

0 commit comments

Comments
 (0)