-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add getter/setter assists #7617
Conversation
82481a6
to
db65241
Compare
These do indeed share some common code like looking up the field the cursor is on and such, I wonder if it would make sense to put all of these assists in one module and extract those common bits into small helper functions. @matklad probably has a better eye for this. |
db65241
to
7b3c89e
Compare
About 2/3rds of the file for each of these assists are tests and docs. The few bits which are for a large part just the template generation. I suspect it may be easier to keep them separate and possibly merge later than the other way around. It's unclear how #5943 will be implemented in the future, so at least for now keeping things separate may be the easiest to work with? |
Finish implementing `generate_setter` assists Make `generate_impl_text` util generic generate getter methods Fix getter / setter naming It's now in-line with the Rust API naming guidelines: https://rust-lang.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getter apply clippy Improve examples
7b3c89e
to
e8d7bcc
Compare
7619: Add #[track_caller] to assist tests r=matklad a=yoshuawuyts This points the source of a failed assertion to the code which called it, rather than the location within the assertion helper method. While working on #7617 I had trouble locating some failing tests, and it was only by adding these attributes during development that I was able to locate them. This is only applied to test helpers, which means it comes at no runtime cost. And even then: I didn't experience any noticeable performance with this enabled or disabled. Mostly just a more pleasant experience debugging test failures (: Co-authored-by: Yoshua Wuyts <[email protected]>
Sounds good to me 👍 |
7650: Add `find_impl_block_end` assist helper r=Veykril a=yoshuawuyts Fixes #7605. This makes it so assists can use helpers to either append a method to the start or the end of an `impl` block. Thanks! @Veykril if this is merged, perhaps it could be good to update the gif in #7617 (comment) ? -- this should fix the ordering issue when generating multiple methods. Co-authored-by: Yoshua Wuyts <[email protected]>
Gif of the assists after #7662 |
Hi, |
It seems to not work if the impl has a macro
When I generate getters/setters it creates a new impl instead of adding to the existing one:
|
This patch makes progress towards the design outlined in #5943, and includes a small refactor which closes #7607. All together this patch does 4 things:
generate_getter
assist.generate_getter_mut
assist.generate_setter
assist.generate_impl_text
function fromgenerate_new
intoutils
(which closesgenerate_enum_match
doesn't work with generic params #7607).Design Notes
I've chosen to follow the Rust API guidelines on getters as closely as possible. This deliberately leaves "builder pattern"-style setters out of scope.
Also, similar to #7570 this assist generates doc comments. I think this should work well in most cases, and for the few where it doesn't it's probably easily edited. This makes it slightly less correct than the #7570 implementation, but I think this is still useful enough to include for many of the same reasons.
The reason why this PR contains 3 assists, rather than 1, is because each of them is so similar to the others that it felt more noisy to do them separately than all at once. The amount of code added does not necessarily reflect that, but hope that still makes sense.
Examples
Input
generate getter
generate mut getter
generate setter