Skip to content

Commit 367d3af

Browse files
author
Ruby
committed
follow-up #957
* use `M_NAME` to call `Module#name` * use parens to avoid warnings: `warning: ambiguity between regexp and two divisions...`
1 parent 7b1ef07 commit 367d3af

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/debug/server_dap.rb

+12-5
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,16 @@ def evaluate_result r
10241024
variable nil, r
10251025
end
10261026

1027+
def type_name obj
1028+
klass = M_CLASS.bind_call(obj)
1029+
1030+
begin
1031+
M_NAME.bind_call(klass) || klass.to_s
1032+
rescue Exception => e
1033+
"<Error: #{e.message} (#{e.backtrace.first}>"
1034+
end
1035+
end
1036+
10271037
def variable_ name, obj, indexedVariables: 0, namedVariables: 0
10281038
if indexedVariables > 0 || namedVariables > 0
10291039
vid = @var_map.size + 1
@@ -1041,20 +1051,17 @@ def variable_ name, obj, indexedVariables: 0, namedVariables: 0
10411051
str = value_inspect(obj)
10421052
end
10431053

1044-
klass = M_CLASS.bind_call(obj)
1045-
type_name = M_NAME.bind_call(klass)
1046-
10471054
if name
10481055
{ name: name,
10491056
value: str,
1050-
type: type_name || klass.to_s,
1057+
type: type_name(obj),
10511058
variablesReference: vid,
10521059
indexedVariables: indexedVariables,
10531060
namedVariables: namedVariables,
10541061
}
10551062
else
10561063
{ result: str,
1057-
type: type_name || klass.to_s,
1064+
type: type_name(obj),
10581065
variablesReference: vid,
10591066
indexedVariables: indexedVariables,
10601067
namedVariables: namedVariables,

test/protocol/variables_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_overwritten_name_method
101101

102102
variable_info = locals.find { |local| local[:name] == "f" }
103103

104-
assert_match /#<Foo:.*>/, variable_info[:value]
104+
assert_match(/\#<Foo:.*>/, variable_info[:value])
105105
assert_equal "Foo", variable_info[:type]
106106

107107
req_terminate_debuggee
@@ -126,7 +126,7 @@ def test_overwritten_class_method
126126
locals = gather_variables
127127

128128
variable_info = locals.find { |local| local[:name] == "f" }
129-
assert_match /#<Foo:.*>/, variable_info[:value]
129+
assert_match(/\#<Foo:.*>/, variable_info[:value])
130130
assert_equal "Foo", variable_info[:type]
131131

132132
req_terminate_debuggee
@@ -148,8 +148,8 @@ def test_anonymous_class_instance
148148
locals = gather_variables
149149

150150
variable_info = locals.find { |local| local[:name] == "f" }
151-
assert_match /#<Class:.*>/, variable_info[:value]
152-
assert_match /#<Class:.*>/, variable_info[:type]
151+
assert_match(/\#<Class:.*>/, variable_info[:value])
152+
assert_match(/\#<Class:.*>/, variable_info[:type])
153153

154154
req_terminate_debuggee
155155
end

0 commit comments

Comments
 (0)