Skip to content

Commit

Permalink
Improve approach to get type name
Browse files Browse the repository at this point in the history
  • Loading branch information
adisonlampert committed Mar 29, 2023
1 parent e3c5863 commit bf582fd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
17 changes: 5 additions & 12 deletions lib/debug/server_dap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1010,16 +1010,6 @@ def evaluate_result r
variable nil, r
end

def type_name obj
klass = M_CLASS.bind_call(obj)

begin
klass.name || klass.to_s
rescue Exception => e
"<Error: #{e.message} (#{e.backtrace.first}>"
end
end

def variable_ name, obj, indexedVariables: 0, namedVariables: 0
if indexedVariables > 0 || namedVariables > 0
vid = @var_map.size + 1
Expand All @@ -1037,17 +1027,20 @@ def variable_ name, obj, indexedVariables: 0, namedVariables: 0
str = value_inspect(obj)
end

klass = M_CLASS.bind_call(obj)
type_name = M_NAME.bind_call(klass)

if name
{ name: name,
value: str,
type: type_name(obj),
type: type_name.to_s,
variablesReference: vid,
indexedVariables: indexedVariables,
namedVariables: namedVariables,
}
else
{ result: str,
type: type_name(obj),
type: type_name.to_s,
variablesReference: vid,
indexedVariables: indexedVariables,
namedVariables: namedVariables,
Expand Down
1 change: 1 addition & 0 deletions lib/debug/thread_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module DEBUGGER__
M_RESPOND_TO_P = method(:respond_to?).unbind
M_METHOD = method(:method).unbind
M_OBJECT_ID = method(:object_id).unbind
M_NAME = method(:name).unbind

module SkipPathHelper
def skip_path?(path)
Expand Down
4 changes: 2 additions & 2 deletions test/protocol/variables_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_overwritten_name_method
variable_info = locals.find { |local| local[:name] == "f" }

assert_match /#<Foo:.*>/, variable_info[:value]
assert_match /<Error: wrong number of arguments \(given 0, expected 1\) /, variable_info[:type]
assert_equal "Foo", variable_info[:type]

req_terminate_debuggee
end
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_overwritten_to_s_method

variable_info = locals.find { |local| local[:name] == "f" }
assert_match /#<Foo:.*>/, variable_info[:value]
assert_match /<Error: wrong number of arguments \(given 0, expected 1\) /, variable_info[:type]
assert_equal "Foo", variable_info[:type]

req_terminate_debuggee
end
Expand Down

0 comments on commit bf582fd

Please sign in to comment.