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

Recommendations for use with debug gem #6

Open
alexevanczuk opened this issue Apr 5, 2024 · 2 comments
Open

Recommendations for use with debug gem #6

alexevanczuk opened this issue Apr 5, 2024 · 2 comments

Comments

@alexevanczuk
Copy link

Hello!

I'm starting to use the new ruby debugger (https://github.com/ruby/debug) in VSCode and making use of this gem to skip through sorbet stuff. Right now, I'm just manually calling PrySorbet::UnwrapCommand.new.process in my debugger, and it works like a charm. Is there a recommended way to automatically run this when entering a debug session with debug? This is called pry-sorbet so maybe supporting debug is a non-goal, but I thought I'd ask!

@pmandrw
Copy link

pmandrw commented Sep 9, 2024

@alexevanczuk I happened upon your comment going down a similar road to you. debug has a nice feature which allows you to define a ~/.rdbgrc.rb which runs code prior to a debug session.

require 'sorbet-runtime'

class SorbetUnwrap
  def self.call
    return unless defined?(T::Private::Methods)

    # For each signature wrapper, call the lambda associated with the wrapper
    # to finalize the method wrapping
    sig_wrappers = T::Private::Methods.instance_variable_get(:@sig_wrappers) || {}
    sig_wrappers.values.each do |sig_wrapper|
      sig_wrapper.call
    rescue NameError
    end

    # Now that all methods are properly wrapped with optimized wrappers
    # we can replace them with the original methods
    signatures_by_method = T::Private::Methods.instance_variable_get(:@signatures_by_method) || {}
    signatures_by_method.values.each do |signature|
      T::Configuration.without_ruby_warnings do
        T::Private::DeclState.current.without_on_method_added do
          if signature.mode == T::Private::Methods::Modes.abstract
            signature.owner.send(:remove_method, signature.method_name)
          else
            signature.owner.send(:define_method, signature.method_name, signature.method)
          end
        end
      end
    end
  end
end

def sorbet_unwrap # or just call it
  SorbetUnwrap.call; nil
end

Not sure if there's a more elegant way to package this functionality. I skimmed through the source and it seems a bit lighter on pluggable abstractions than pry

@alexevanczuk
Copy link
Author

Thanks @pmandrw. I found that adding this to my ~/.zshrc worked as well:

export RUBY_DEBUG_SKIP_PATH="
/Users/alexevanczuk/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/:
/Users/alexevanczuk/workspace/monorail/spec/rails_helper.rb:
lib/middleware/
"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants