Skip to content

Commit 670f96a

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

File tree

3 files changed

+7
-41
lines changed

3 files changed

+7
-41
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: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -102,35 +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]
106-
107-
req_terminate_debuggee
108-
end
109-
end
110-
end
111-
112-
class DAPOverwrittenToSMethod < ProtocolTestCase
113-
PROGRAM = <<~RUBY
114-
1| class Foo
115-
2| def self.name
116-
3| nil
117-
4| end
118-
5| def self.to_s(value) end
119-
6| end
120-
7| f = Foo.new
121-
8| __LINE__
122-
RUBY
123-
124-
def test_overwritten_to_s_method
125-
run_protocol_scenario PROGRAM, cdp: false do
126-
req_add_breakpoint 8
127-
req_continue
128-
129-
locals = gather_variables
130-
131-
variable_info = locals.find { |local| local[:name] == "f" }
132-
assert_match /#<Foo:.*>/, variable_info[:value]
133-
assert_match /<Error: wrong number of arguments \(given 0, expected 1\) /, variable_info[:type]
105+
assert_equal "Foo", variable_info[:type]
134106

135107
req_terminate_debuggee
136108
end

0 commit comments

Comments
 (0)