From e8d7bcc35507425f384cff25feb564ac41a5c5a7 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 9 Feb 2021 12:30:13 +0100 Subject: Add getter/setter assists 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 --- crates/assists/src/tests/generated.rs | 71 +++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'crates/assists/src/tests') diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs index 0dbb05f2a..6f2b22bc2 100644 --- a/crates/assists/src/tests/generated.rs +++ b/crates/assists/src/tests/generated.rs @@ -533,6 +533,54 @@ fn bar(arg: &str, baz: Baz) ${0:-> ()} { ) } +#[test] +fn doctest_generate_getter() { + check_doc_test( + "generate_getter", + r#####" +struct Person { + nam$0e: String, +} +"#####, + r#####" +struct Person { + name: String, +} + +impl Person { + /// Get a reference to the person's name. + fn name(&self) -> &String { + &self.name + } +} +"#####, + ) +} + +#[test] +fn doctest_generate_getter_mut() { + check_doc_test( + "generate_getter_mut", + r#####" +struct Person { + nam$0e: String, +} +"#####, + r#####" +struct Person { + name: String, +} + +impl Person { + /// Get a mutable reference to the person's name. + fn name_mut(&mut self) -> &mut String { + &mut self.name + } +} +"#####, + ) +} + #[test] fn doctest_generate_impl() { check_doc_test( @@ -571,7 +619,30 @@ struct Ctx { impl Ctx { fn $0new(data: T) -> Self { Self { data } } } +"#####, + ) +} +#[test] +fn doctest_generate_setter() { + check_doc_test( + "generate_setter", + r#####" +struct Person { + nam$0e: String, +} +"#####, + r#####" +struct Person { + name: String, +} + +impl Person { + /// Set the person's name. + fn set_name(&mut self, name: String) { + self.name = name; + } +} "#####, ) } -- cgit v1.2.3