Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

follow-up #957 #971

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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