tapioca icon indicating copy to clipboard operation
tapioca copied to clipboard

Loading custom extensions in addition to custom compilers

Open olivier-thatch opened this issue 2 years ago • 2 comments

Hello,

I am trying to write a custom compiler for a gem that uses a DSL to add methods to Active Record model classes.

The problem is that the DSL simply calls define_singleton_method and does not maintain a list of the methods it defines. So there is no way to know which methods were defined by the gem when introspecting an Active Record model class.

After digging into the Tapioca repo, I saw that the compilers for delegated_type and has_secure_token have the same issue, and the workaround is to override the DSL methods to maintain a list of generated methods internally, using this extension.

I want to do something similar, however it looks like while Tapioca will look for custom compilers in the sorbet/tapioca/compilers directory, there is no equivalent for loading custom extensions. Extensions have to be loaded before the application, and the application is loaded before compilers, so I can't load the extension from the compiler.

Did I miss something, or is this something that is not currently supported? If not, would you be open to a PR to add support for this?

olivier-thatch avatar Aug 10 '23 20:08 olivier-thatch

Good point. I don't see a reason not to support this. Implementation can be similar to the load_dsl_compilers method https://github.com/Shopify/tapioca/blob/fcbde0df4680a5a1897117bfa838c2eda0830b0c/lib/tapioca/loaders/dsl.rb#L63-L65

KaanOzkan avatar Aug 11 '23 20:08 KaanOzkan

We actually have some work in progress about this: https://github.com/Shopify/tapioca/commit/12255bb93bf30a7dd32e5bbaf0e818ab1c9942ee

Morriar avatar Aug 11 '23 21:08 Morriar

#1602 was merged a while back, so this can be closed :)

olivier-thatch avatar May 21 '24 16:05 olivier-thatch