helix
helix copied to clipboard
Support for modules?
Hey so this is really awesome and I'd like to try it out, unfortunately my use case is that I only have ruby modules, not classes. Are you planning to add support for reopen_module syntax too?
Yep! Currently the coverage is pretty sparse and driven by the examples. Feel free to send a PR with an example using module (or I will get to it eventually).
:+1: for this. I'm wanting to re-implement the basic of active_support/inflector/methods.rb in rust so that I can have https://github.com/NullVoxPopuli/case_transform be fast, so that ActiveModelSerializers doesn't spend so much time on transforming keys
@NullVoxPopuli we've done a lot of work recently and I suspect some of it will make this easier. @chancancode any thoughts?
I'd love to try out Helix on my rust extension projects (currently using a more bare-bones approach) but also require modules. Looking over the code and macros, it looks like existing method definitions and parsing is pretty heavily integrate with "Class" idioms (the parser particularly, but also MethodDefinition being inside the class definitions file, for example).
If I wanted to assist in implementing this, where would I start to broaden out the definitions from class to class or module?
@nomoon is your use case "using modules as namespace" or are you defining methods inside the module?
i.e. do you just need to nest the class inside the right modules (and possibly create them if they don't already exists, like mkdir -p) or do you need the ability to define Rust methods on a (new or existing) module?
@chancancode My use cases involve both defining modules at top-level and nested under other modules, as well as defining module instance methods (to be included in other classes) and module methods themselves (to be called directly).
As far as my other work using ruby_sys goes, the C API is pretty agnostic as far as defining methods, and even defining modules is pretty straightforward (IIRC rb_define_module_under can take rb_cObject to perform basically the same as rb_define_module), so the big issue is being able to use the module keyword in the ruby macro to define/open modules and get them to call the rb_define_method and rb_define_singleton_method equivalents in those contexts.
I'm still familiarizing myself with the helix codebase, but haven't yet been able to wrap my head around the complex parse macros, and am not sure what the prevailing opinions would be on moving/generalizing the MethodDefinition and MethodSpecification stuff that's currently in src/class_definition.rs