-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Expanding the patching API #64
Comments
Hi @msaraiva! I'm glad to see that Sourceror is being of use for the community.
I have no plans to expand the patching API, and the current direction is to just make sure it's stable enough and works well enough to be a building block for other tools. The reason for this is that I currently don't have the mental bandwidth to expand what Sourceror is capable of(lots of personal and mental health issues I have to take care of that make it hard for me to concentrate). That said, however, I do welcome contributions to Sourceror(be it a new or improved patching API, new functions, bug fixes). I don't want my personal circumstances to be a roadblock for the elixir community in this space, so I'm very open to the improvements you may want to make to Sourceror. What's more, I'm even also willing to add some of you as maintainers of this repository if needed. I'm in the Elixir Slack too as cc @NickNeck since you've been a big contributor to Sourceror and since this may also be relevant for |
A proposed API for composing many patches to a project. This is very similar and inspired by the patterns that @msaraiva |
@zachdaniel that looks great. In I am not sure if this should be a part of I have also started some experiments with the modules I have created a little script in the recode example that shows all the things above in action, see https://github.com/hrzndhrn/recode/blob/traverse/examples/my_code/scripts/add_use.exs |
Wow! So it looks like you've already implemented practically exactly the proposed API! That is huge 🔥 🔥 🔥 My 2 cents is that that logic would be best served if it lived in sourceror eventually, but I don't think that it is a requirement by any means. I do think that likely some of the extra linting logic in recode would be too much to make that the package distributed for generic code rewriting, so if you were to move that out to something like Come to think of it, the only thing I think your API may be missing is the logic to create a file, but I imagine that isn't a complex addition to your set up. Awesome stuff. |
@NickNeck if you did extract that project modification toolchain to its own repo, I'd likely start using it in the next couple of weeks and would happily contribute. I'd likely end up copying lots of @msaraiva's AST modification utilities from sourceror. It would be ideal to find some way to ensure proper attribution for @msaraiva's code there. |
Thank you.
I have added an example that deletes and creates sources, see https://github.com/hrzndhrn/recode/blob/traverse/examples/my_code/scripts/module_per_file.exs I changed my mind after my last post. I think If |
@NickNeck I'm still reviewing I think at least I'm still considering I may be missing something, but is Operations on the AST don't have to worry about that, as you can just update the AST fragment, convert it to a string, and replace the original text range with the new string, but I'm not sure yet about how that would work with something like Thoughts? |
@doorgan I am happy that you like I am also fine with your opinion about In the moment |
🤔 I think perhaps we can just make formatting a configurable behavior, but realistically I can't imagine anyone doing what we're doing(rewriting source) without wanting at least the end result to be formatted. I think if it were totally up to me we'd place all of it in sourceror, but I'm happy either way :) |
@NickNeck Awesome, thank you so much :) @zachdaniel the issue is that we need the formatter to produce proper string from a piece of AST, but we can't just assume the user wants the whole file to be formatted. This puts us in a situation where we need to decide if Sourceror needs to support these users(IIRC from previous discussions on the implementation of Of course just using the formatter for everything is the simplest solution to all problems, we may as well move everything to sourceror and commit to using the formatter for everything, while still exposing the lower level functions for the users that want to produce fine grained modifications that don't mess up their personal formatting style in the whole file. That's also an option. |
Yeah, I definitely think it makes sense to leave not formatting as an option to allow for cases where people care. I imagine it should relatively easily be added as an option to the API, perhaps even defaulting to |
I have pushed the first beta of |
Hi @doorgan!
We're gathering some folks in the community who want to extract the patcher API from Surface (which is built on top of Sourceror) into a separate project so we could have a generic higher-level library for patching Elixir projects. The lib would also include a few of the most common patchers, like some you can find here https://github.com/surface-ui/surface/blob/main/lib/mix/tasks/surface/surface.init/file_patchers/mix_exs.ex.
One of the things raised during the initial discussion was that we may need to add more functions to sourceror or maybe improve some of the existing ones so they could work on different scenarios. I remember we've discussed the possibility of expanding sourceror's patching API in the past but since it's been a while since out last conversation, I wonder if you still have plans on that regard and how do you see the evolution of Sourceror in that direction. This is important for us to know as we're willing to dedicate part of the effort to make direct contributions to Sourceror.
We've created a group on Slack to discuss the new lib and the next steps we should take. In case you want to participate in the discussion, please let us know.
Thanks for creating Sourceror! ❤️
/cc @davydog187, @zachdaniel, @paulstatezny
The text was updated successfully, but these errors were encountered: