-
Notifications
You must be signed in to change notification settings - Fork 4
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
Improve variable type name request #14
base: master
Are you sure you want to change the base?
Conversation
c150bb9
to
9109e88
Compare
9109e88
to
e3c5863
Compare
lib/debug/thread_client.rb
Outdated
@@ -14,6 +14,7 @@ module DEBUGGER__ | |||
M_RESPOND_TO_P = method(:respond_to?).unbind | |||
M_METHOD = method(:method).unbind | |||
M_OBJECT_ID = method(:object_id).unbind | |||
M_NAME = Module.instance_method(:name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use the same pattern as above.
lib/debug/server_dap.rb
Outdated
if name | ||
{ name: name, | ||
value: str, | ||
type: type_name(obj), | ||
type: type_name || type_name.to_s, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using this or
, can't we always invoke to_s
?
cfd91dc
to
bf582fd
Compare
lib/debug/server_dap.rb
Outdated
if name | ||
{ name: name, | ||
value: str, | ||
type: type_name(obj), | ||
type: type_name.to_s, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type_name
should already return a String so to_s
may not be necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, everything appears to be working fine when I use just type_name
. Does that make the to_s
test unnecessary?
bf582fd
to
d7908fe
Compare
test/protocol/variables_test.rb
Outdated
end | ||
end | ||
|
||
class DAPOverwrittenToSMethod < ProtocolTestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we don't call to_s
anymore, do we still need this test?
d7908fe
to
670f96a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think it's good to open a PR upstream now. Just a reminder that the PR description should be concise but mention:
- What's the behavioural difference with examples (e.g. parts of the response content)
- Why it's better
d59e3ca
to
a136d09
Compare
a136d09
to
b83389a
Compare
Description
ruby#790 fixes this issue. In this issue, the debugger raises the error:
I took a look at the repository this error was occurring in to figure out what was causing it. Essentially, this
ArgumentError
is coming from theself.name
function having the parametervalue
which is not provided whenklass.name
is called here, causing an exception.In ruby#790, if there is an exception when trying to get the class name, the variable's
type
is set to"<Error: #{e.message} (#{e.backtrace.first}>"
.My first commit adds three tests that test this functionality:
name
method. The type should be an error message that begins with<Error: wrong number of arguments (given 0, expected 1)
.to_s
method. The type should be the same error as 1.name
method and returnnil
because thetype_name
method checksklass.name
first and without overriding the method to returnnil
, the test does not triggerklass.to_s
class
method. This was added in becauseM_CLASS.bind_call(obj)
is used rather thanobj.class
so adding a test to ensure the class name is being set appropriately and not raising an error is useful.I noticed that rather than catching an exception and setting the type to an error message, it would be better to use
M_NAME.bind_call(klass)
to get the type name as this does not callklass.name
so there would be no error. This is an approach that is used by Tapioca here.In my second commit, I implemented this approach. I updated the tests from my first commit to reflect the new changes including removing the
to_s
test as this method is no longer being used. You can see thetype
is nowFoo
instead of an error message. This is more correct.