Skip to content

Commit

Permalink
Move VSCodeServer stuff to ext
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick committed Sep 24, 2024
1 parent cf2006a commit bc8774d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 88 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ version = "0.3.0"
[weakdeps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
VSCodeServer = "9f5989ce-84fe-42d4-91ec-6a7a8d53ed0f"

[extensions]
AbbrvStackTracesDistributedExt = ["Distributed"]
AbbrvStackTracesREPLExt = ["REPL"]
AbbrvStackTracesVSCodeServerExt = ["VSCodeServer"]

[compat]
Distributed = "1"
Expand Down
80 changes: 80 additions & 0 deletions ext/AbbrvStackTracesVSCodeServerExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module AbbrvStackTracesVSCodeServerExt

__precompile__(false)

@eval Main begin
import .VSCodeServer:
crop_backtrace,
EvalErrorStack,
display_repl_error,
replcontext,
unwrap_loaderror

import Base:
showerror

import Base.StackTraces:
stacktrace

function display_repl_error(io, err, bt)
st = stacktrace(VSCodeServer.crop_backtrace(bt))
printstyled(io, "ERROR: "; bold=true, color=Base.error_color())
showerror(IOContext(io, :limit => true, :compacttrace => true), err, st)
println(io)
end
function display_repl_error(io, stack::VSCodeServer.EvalErrorStack)
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(IOContext(io, :limit => true, :compacttrace => true), i == 1 ? unwrap_loaderror(err) : err, st)
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

end
1 change: 0 additions & 1 deletion src/AbbreviatedStackTraces.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module AbbreviatedStackTraces

include("override-vscode.jl")
include("override-client.jl")
include("override-errorshow.jl")
include("override-stacktraces.jl")
Expand Down
87 changes: 0 additions & 87 deletions src/override-vscode.jl

This file was deleted.

0 comments on commit bc8774d

Please sign in to comment.