Share variable inspection logic between CDP and DAP
The logic that decides how variables are presented is repeated between the CDP and DAP implementations. This is error prone and leads to inconsistencies, where improvements are made to one or the other, but not both. E.g.:
- The special
#dumpmember forStringonly exists in VSCode #869 - This feature to hide special
#classmembers only exists for VSCode #986 - VSCode formats hash keys with
value_inspect, but not Chrome - CDP adds
#classappears at the end, whereas DAP adds#classto the start.
This PR extracts the variable inspection logic into a new VariableInspector class, which can be shared between VSCode and Chrome. This gives a central place to make future improvements.
I tried to make only the minimal behaviour changes necessary to unify the two implementations.
This PR then unlocks the ability to make some changes really nice/easily:
- #1003
- #1004
- #1005
- I like an idea to unify CDP and DAP because of implementation.
- However I'm not sure we can merge it because of difference between CDP and DAP (I don't know the CDP details). Do you have a time to trouble shooting for CDP?
- The name "variable.rb" doesn't make sense for me because it's only for the representation (the name is too general). debug.gem has a policy to reduce the number of "require" to reduce the boot time. Can we merge it with variable_inspector.rb?
Do you have a time to trouble shooting for CDP?
I've already run this with CDP, it works great.
Can we merge it with variable_inspector.rb?
@ko1 Done. I still call it class Variable. It's a general name, but I don't have any better ideas. Please suggest if you have any.
Also, some tests are failed in protocol part. Can you fix them? FYI: https://github.com/ruby/debug/blob/master/CONTRIBUTING.md
@ono-max I can have a look over the holiday break next week :)
Hey @ono-max, Happy new year!
I've fixed the protocol tests, and rebased onto the latest master.
There's 2 test failures in test/console/nested_break_test.rb left, but I don't see how they could be related.
It seems to be that some protocol tests are still failed. Can you please check them? If you need help, please let me know 👍
I believe that https://github.com/ruby/debug/actions/runs/7405610000/job/20183471986?pr=1001 and https://github.com/ruby/debug/actions/runs/7405610000/job/20183471690?pr=1001 are not flakey tests.
@ono-max Hmmm I think we have one of those "it works on my machine" situations
$ bundle exec rake test_protocol
Loaded suite /Users/alex/.gem/ruby/3.3.0/gems/rake-13.0.6/lib/rake/rake_test_loader
Started
Finished in 1.438602 seconds.
--------------------------------------------------------------------------------
2 tests, 690 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
--------------------------------------------------------------------------------
1.39 tests/s, 479.63 assertions/s
I'm running on Ruby 3.3.0 on macOS Sonoma 14.2.1.
I suspect these errors are coming from the ancestors chains being in different in CI, but I don't know why that would be. Could you please help me investigate this? I don't have access to a Linux machine to compare against.
I investigated the cause of the failed tests. I believe that the reason is because ancestor classes are changed from Ruby 3.1. Thus, we can skip the test if the Ruby version is lower than 3.1, e.g. 6f154ac
@ono-max Fantastic find! I pulled that commit into this PR, so you get credit for it :)
Is this ready to merge?
I appreciate your dedicated efforts and hard work. @ko1-san will merge this PR 👍
@ono-max Thanks!
Could you run the CI one more time, so we're sure it's green before merging?
@ono-max I think the remaining test failures are just flakey tests. I can reproduce them Ruby 3.1.4, but they fail less than 1/10 times.
@ko1 Can you please review and merge this?