Skip to content

Commit

Permalink
follow-up #957
Browse files Browse the repository at this point in the history
* use `M_NAME` to call `Module#name`
* use parens to avoid warnings: `warning: ambiguity between regexp and two divisions...`
  • Loading branch information
Ruby committed May 4, 2023
1 parent 7b1ef07 commit 367d3af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
17 changes: 12 additions & 5 deletions lib/debug/server_dap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,16 @@ def evaluate_result r
variable nil, r
end

def type_name obj
klass = M_CLASS.bind_call(obj)

begin
M_NAME.bind_call(klass) || 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 @@ -1041,20 +1051,17 @@ 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 || klass.to_s,
type: type_name(obj),
variablesReference: vid,
indexedVariables: indexedVariables,
namedVariables: namedVariables,
}
else
{ result: str,
type: type_name || klass.to_s,
type: type_name(obj),
variablesReference: vid,
indexedVariables: indexedVariables,
namedVariables: namedVariables,
Expand Down
8 changes: 4 additions & 4 deletions test/protocol/variables_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_overwritten_name_method

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

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

req_terminate_debuggee
Expand All @@ -126,7 +126,7 @@ def test_overwritten_class_method
locals = gather_variables

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

req_terminate_debuggee
Expand All @@ -148,8 +148,8 @@ def test_anonymous_class_instance
locals = gather_variables

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

req_terminate_debuggee
end
Expand Down

0 comments on commit 367d3af

Please sign in to comment.