Proposal: Option to add a crate with all items marked as `pub`
My Primary use case for irust is to test/play with crates I'm working on with :add --path. One annoying part of this is having to edit the source file and set an item's visibility to pub every time I want to access it. It would be great to have the option to add a crate with all items marked as pub automatically.
I think we can do this by copying the source code to a temporary directory and using syn and prettyplease on all .rs files to change the visibility of all items before the call to cargo add.
If this is something that the project is open to, I can make a PR.
I think it make sense but I prefer this feature is added as a script https://github.com/sigmaSd/IRust/blob/master/SCRIPTS.md
The easiest way I think
- add a CargoAddCommand here https://github.com/sigmaSd/IRust/blob/master/crates/irust_api/src/lib.rs#L80
- implement it here https://github.com/sigmaSd/IRust/blob/master/crates/irust/src/irust/engine.rs#L62
- create a script that listens to InputEvent
- when an input event is triggered, if the input starts with :add and contains --path proceed to the next step
- splt the input to get the path , copy it to a temp dir , modify it, then return CargAddCommand with the temp path
I started the work here https://github.com/sigmaSd/IRust/compare/super_add?expand=1
The prototype does work, I tested on simple crates
But it needs a log of cleanup, also its maybe a good time to improve the scirpt manager in irust (currently it discards all errors which make it annoying to debug issues)
I dont know when I will have time to finish it, if you're interested it should be a good starting point
The script should also print the new crate path, because if the user wants to do some modifications he should do them there or maybe we monitor the original crate and copy it again when there is changes, but the first idea is easier
Actually CargoCommandAdd is not needed, it can be replaced by the already present Command::Parse which is more general (Its been a while since I used these apis)
I cleaned up the script, I tested with simple crates and it seems to work, turns out there is no need for any code changes from irust , so you can just use it today
to use it:
- Set
activate_scriptingtotruein irust config file. - compile https://github.com/sigmaSd/IRust/tree/master/script_examples/super_add
- Copy the resulting binary to ~/.config/irust/script/
run irust and run :scripts to make sure that SuperAdd is active (it should be green)
now just use :add --path locallib and the script will copy it and mark its item as pub and add it as a dep
If you make changes to that crate, just run :add again
Demo
https://github.com/user-attachments/assets/2febabf4-1797-4e49-9d94-78f7f93d3c78
@sigmaSd sorry for the delay replying to the thread. I got busy over the weekend. Thank you very much for the implementation!
No problem, its a cool idea that why I got interested,
Btw you need to install irust from crates.io, prebuilt binaries from github ci don't detect scripts for some reason (I'm debugging that)
Like I said I tested with simple crates, there might be edge cases that need to be handled
Btw you need to install irust from crates.io, prebuilt binaries from github ci don't detect scripts for some reason (I'm debugging that)
Fixed it (it turns out I was uploading musl builds, which don't support scripting)
I created https://github.com/sigmaSd/IRust/pull/157 with some minor fixes. It may be best to use a slightly different command like :suadd for this plugin. Is there a way for the plugin to tell irust about new commands it adds? If not, it should be easy to add, no?