Skip to content

Commit c13db52

Browse files
committed
Fix cell filename in stack traces
1 parent 9640789 commit c13db52

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/execute_request.jl

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ function run_cell_code(code)
4949
# Apply macros to ast
5050
mod = current_module[]
5151
file = "In[$n]"
52-
line_node = LineNumberNode(line_no, file)
53-
ast = Meta.parse("begin\n$(code)\nend")
54-
# Make block top level
55-
if Meta.isexpr(ast, :block)
56-
ast.head = :toplevel
57-
end
52+
53+
ast = parse_file(code, file, false)
54+
# More compatible?
55+
#ast = Meta.parse("begin\n$(code)\nend", raise=false)
56+
## Make block top level
57+
#if Meta.isexpr(ast, :block)
58+
# ast.head = :toplevel
59+
# line_node = LineNumberNode(line_no, file)
60+
# push!(ast.args, 1, line_node)
61+
#end
62+
5863
for mac_call in Iterators.reverse(cell_macro_calls)
5964
push!(mac_call.args, ast)
6065
ast = macroexpand(mod, mac_call, recursive=false)
@@ -79,6 +84,29 @@ function _apply_macro(mac, ast, mod)
7984
macroexpand(mod, macro_expr, recursive=false)
8085
end
8186

87+
"""
88+
parse_file(content, fname; raise=true, depwarn=true)
89+
90+
Parse the entire string as a file, reading multiple expressions. Equivalent to
91+
`Meta.parse()` but for more than one expression.
92+
"""
93+
function parse_file(content::AbstractString, fname::AbstractString,
94+
raise::Bool=true, depwarn::Bool=true)
95+
# returns (expr, end_pos). expr is () in case of parse error.
96+
bcontent = String(content)
97+
bfname = String(fname)
98+
# For now, assume all parser warnings are depwarns
99+
ex = Meta.with_logger(depwarn ? Meta.current_logger() : Meta.NullLogger()) do
100+
ccall(:jl_parse_all, Any,
101+
(Ptr{UInt8}, Csize_t, Ptr{UInt8}, Csize_t),
102+
bcontent, sizeof(bcontent), fname, sizeof(fname))
103+
end
104+
if raise && Meta.isexpr(ex, :error)
105+
throw(ParseError(ex.args[1]))
106+
end
107+
ex
108+
end
109+
82110
function execute_request(socket, msg)
83111
code = msg.content["code"]
84112
@vprintln("EXECUTING ", code)

0 commit comments

Comments
 (0)