Skip to content

Commit

Permalink
Restore VSCode function
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick committed Sep 24, 2024
1 parent c1027b6 commit cf2006a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/override-vscode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ try
@eval Main begin
import .VSCodeServer:
crop_backtrace,
EvalErrorStack,
display_repl_error,
replcontext,
unwrap_loaderror

import Base:
Expand All @@ -33,6 +35,50 @@ try
println(io)
end
end

replcontext(io, limit_types_flag, hide_internal_frames_flag) = IOContext(
io,
:limit => true,
:displaysize => get(stdout, :displaysize, (60, 120)),
:stacktrace_types_limited => limit_types_flag,
:compacttrace => hide_internal_frames_flag
)

function display_repl_error(io, err, bt; unwrap = false)
limit_types_flag = Ref(false)
hide_internal_frames_flag = Ref(true)

st = stacktrace(crop_backtrace(bt))
printstyled(io, "ERROR: "; bold = true, color = Base.error_color())
showerror(replcontext(io, limit_types_flag, hide_internal_frames_flag), err, st)
if limit_types_flag[] || hide_internal_frames_flag[]
limit_types_flag[] && print(io, "Some type information was truncated. ")
hide_internal_frames_flag[] && print(io, "Some frames were hidden. ")
print(io, "Use `show(err)` to see complete trace.")
println(io)
end
println(io)
end

function display_repl_error(io, stack::EvalErrorStack; unwrap = false)
limit_types_flag = Ref(false)
hide_internal_frames_flag = Ref(true)

printstyled(io, "ERROR: "; bold = true, color = Base.error_color())
for (i, (err, bt)) in enumerate(reverse(stack.stack))
i !== 1 && print(io, "\ncaused by: ")
st = stacktrace(crop_backtrace(bt))
showerror(replcontext(io, limit_types_flag, hide_internal_frames_flag), unwrap && i == 1 ? unwrap_loaderror(err) : err, st)
println(io)
end

if limit_types_flag[] || hide_internal_frames_flag[]
limit_types_flag[] && print(io, "Some type information was truncated. ")
hide_internal_frames_flag[] && print(io, "Some frames were hidden. ")
print(io, "Use `show(err)` to see complete trace.")
println(io)
end
end
end
catch e
if !isa(e, UndefVarError) || e.var != :VSCodeServer
Expand Down

0 comments on commit cf2006a

Please sign in to comment.