-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share variable inspection logic between CDP and DAP
- Loading branch information
1 parent
4ec9d7a
commit ee133fd
Showing
7 changed files
with
485 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require "pp" | ||
|
||
module DEBUGGER__ | ||
class LimitedPP | ||
SHORT_INSPECT_LENGTH = 40 | ||
|
||
def self.pp(obj, max = 80) | ||
out = self.new(max) | ||
catch out do | ||
::PP.singleline_pp(obj, out) | ||
end | ||
out.buf | ||
end | ||
|
||
attr_reader :buf | ||
|
||
def initialize max | ||
@max = max | ||
@cnt = 0 | ||
@buf = String.new | ||
end | ||
|
||
def <<(other) | ||
@buf << other | ||
|
||
if @buf.size >= @max | ||
@buf = @buf[0..@max] + '...' | ||
throw self | ||
end | ||
end | ||
|
||
def self.safe_inspect obj, max_length: SHORT_INSPECT_LENGTH, short: false | ||
if short | ||
LimitedPP.pp(obj, max_length) | ||
else | ||
obj.inspect | ||
end | ||
rescue NoMethodError => e | ||
klass, oid = M_CLASS.bind_call(obj), M_OBJECT_ID.bind_call(obj) | ||
if obj == (r = e.receiver) | ||
"<\##{klass.name}#{oid} does not have \#inspect>" | ||
else | ||
rklass, roid = M_CLASS.bind_call(r), M_OBJECT_ID.bind_call(r) | ||
"<\##{klass.name}:#{roid} contains <\##{rklass}:#{roid} and it does not have #inspect>" | ||
end | ||
rescue Exception => e | ||
"<#inspect raises #{e.inspect}>" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.