Properly attribute RBIs created by `ActiveSupport.on_load`
Closes #2016 Closes #2048
Motivation
Currently, Tapioca is incorrectly attributing mixins performed by the ActiveSupport.on_load hooks.
A quick summary of how things currently work: whenever a mixin (include, extend, prepend) is performed by a gem for which Tapioca is generating RBIs, we attribute that mixin to a specific location by looking at the backtrace of the call to include/extend/prepend and finding the line that is tagged <top (required)> (or <main> if there is no other tag). This location may be in the gem code, or it may be in the code of another gem entirely.
Then, we can filter those mixins based on where they happen -- only the mixins attributed to a gem get put in that gem's RBI.
This approach does not work when a mixin is performed based on an ActiveSupport.on_load hook because the location that is tagged <top (required)> will be in Rails gem that is being hooked into, rather than in the gem that is performing the on_load hook in the first place.
Implementation
To fix this, we need to change how we choose the location for mixin attribution. By searching for locations tagged with block in <class:..., we can identify locations that trigger a mixin based on a loading hook.
Tests
See automated tests
@KaanOzkan updated! Thanks for the reminder.
@amomchilov Yes that would be awesome, thank you!