Require gem classes, but out out of require-time side effects?

Open
#742 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
devtools

Research direction

Start by reproducing the failure with bundle exec tapioca gem debug, both with and without RUBY_DEBUG_ENABLE=0, and inspect the gem's require path and the attach, trap, and fork-interceptor entry points. Done means Tapioca can require debug without side effects and generate an RBS or RBI successfully.

Written by the indexing model from the issue text.

Description

Your proposal

Is it possible to separate out the logic to attempt to attach to a process, and to define all the classes that the library needs?

Additional context

When using type checkers like Sorbet, various tools (srb init, tapioca gem, etc.) attempt to require the gem only to see what classes, methods, and constants the gem defines, so that it can generate either an RBS or RBI file providing annotations for the gem.

It seems that the debug gem does not work for those use cases, because requiring the gem seems to try to attach to the gem:

~/sandbox/default  jez@jez-pc-01
❯ cat Gemfile
source 'https://rubygems.org'

gem 'tapioca'
gem 'debug'

~/sandbox/default  jez@jez-pc-01
❯ bundle install &> /dev/null && bundle exec tapioca gem debug
Requiring all gems to prepare for compiling... DEBUGGER: Attaching after process 676571 fork to child process 676585
 Done

Error: Cannot find gem 'debug'

~/sandbox/default  jez@jez-pc-01
❯ export RUBY_DEBUG_ENABLE=0

~/sandbox/default  jez@jez-pc-01
❯ bundle install &> /dev/null && bundle exec tapioca gem debug
Requiring all gems to prepare for compiling...  Done

Error: Cannot find gem 'debug'

What I would like to be able to do is to have a way to require all the supporting classes/modules/constants/methods that the debug gem defines but not have the gem attempt to do any side effects. For example, I want to require the gem but explicitly opt out of the trap and fork interceptors.

The feature request would be considered complete when it's possible to generate an RBS or RBI for the debug gem without having it fail, as shown in the screenshot above.

Dominant language
Ruby
Stars
1.3k
Forks
146
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/debug

All issues in ruby/debug

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.