Skip to content

Commit d7908fe

Browse files
committed
Improve approach to get type name
1 parent e3c5863 commit d7908fe

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

lib/debug/server_dap.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,16 +1010,6 @@ def evaluate_result r
10101010
variable nil, r
10111011
end
10121012

1013-
def type_name obj
1014-
klass = M_CLASS.bind_call(obj)
1015-
1016-
begin
1017-
klass.name || klass.to_s
1018-
rescue Exception => e
1019-
"<Error: #{e.message} (#{e.backtrace.first}>"
1020-
end
1021-
end
1022-
10231013
def variable_ name, obj, indexedVariables: 0, namedVariables: 0
10241014
if indexedVariables > 0 || namedVariables > 0
10251015
vid = @var_map.size + 1
@@ -1037,17 +1027,20 @@ def variable_ name, obj, indexedVariables: 0, namedVariables: 0
10371027
str = value_inspect(obj)
10381028
end
10391029

1030+
klass = M_CLASS.bind_call(obj)
1031+
type_name = M_NAME.bind_call(klass)
1032+
10401033
if name
10411034
{ name: name,
10421035
value: str,
1043-
type: type_name(obj),
1036+
type: type_name,
10441037
variablesReference: vid,
10451038
indexedVariables: indexedVariables,
10461039
namedVariables: namedVariables,
10471040
}
10481041
else
10491042
{ result: str,
1050-
type: type_name(obj),
1043+
type: type_name,
10511044
variablesReference: vid,
10521045
indexedVariables: indexedVariables,
10531046
namedVariables: namedVariables,

lib/debug/thread_client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module DEBUGGER__
1414
M_RESPOND_TO_P = method(:respond_to?).unbind
1515
M_METHOD = method(:method).unbind
1616
M_OBJECT_ID = method(:object_id).unbind
17+
M_NAME = method(:name).unbind
1718

1819
module SkipPathHelper
1920
def skip_path?(path)

test/protocol/variables_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_overwritten_name_method
102102
variable_info = locals.find { |local| local[:name] == "f" }
103103

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

107107
req_terminate_debuggee
108108
end
@@ -130,7 +130,7 @@ def test_overwritten_to_s_method
130130

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

135135
req_terminate_debuggee
136136
end

0 commit comments

Comments
 (0)