From 367d3af2d9395b6fb9322e1408afd7bee98bc96b Mon Sep 17 00:00:00 2001 From: Ruby Date: Fri, 5 May 2023 03:17:01 +0900 Subject: [PATCH] follow-up #957 * use `M_NAME` to call `Module#name` * use parens to avoid warnings: `warning: ambiguity between regexp and two divisions...` --- lib/debug/server_dap.rb | 17 ++++++++++++----- test/protocol/variables_test.rb | 8 ++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb index 681b62a35..db3d66604 100644 --- a/lib/debug/server_dap.rb +++ b/lib/debug/server_dap.rb @@ -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 + "" + end + end + def variable_ name, obj, indexedVariables: 0, namedVariables: 0 if indexedVariables > 0 || namedVariables > 0 vid = @var_map.size + 1 @@ -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, diff --git a/test/protocol/variables_test.rb b/test/protocol/variables_test.rb index 8da270715..9b82419e8 100644 --- a/test/protocol/variables_test.rb +++ b/test/protocol/variables_test.rb @@ -101,7 +101,7 @@ def test_overwritten_name_method variable_info = locals.find { |local| local[:name] == "f" } - assert_match /#/, variable_info[:value] + assert_match(/\#/, variable_info[:value]) assert_equal "Foo", variable_info[:type] req_terminate_debuggee @@ -126,7 +126,7 @@ def test_overwritten_class_method locals = gather_variables variable_info = locals.find { |local| local[:name] == "f" } - assert_match /#/, variable_info[:value] + assert_match(/\#/, variable_info[:value]) assert_equal "Foo", variable_info[:type] req_terminate_debuggee @@ -148,8 +148,8 @@ def test_anonymous_class_instance locals = gather_variables variable_info = locals.find { |local| local[:name] == "f" } - assert_match /#/, variable_info[:value] - assert_match /#/, variable_info[:type] + assert_match(/\#/, variable_info[:value]) + assert_match(/\#/, variable_info[:type]) req_terminate_debuggee end