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/handlers/generate_enum_match_method.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'crates/assists/src/handlers/generate_enum_match_method.rs') diff --git a/crates/assists/src/handlers/generate_enum_match_method.rs b/crates/assists/src/handlers/generate_enum_match_method.rs index 9d6b161c9..c3ff38b66 100644 --- a/crates/assists/src/handlers/generate_enum_match_method.rs +++ b/crates/assists/src/handlers/generate_enum_match_method.rs @@ -4,7 +4,7 @@ use syntax::ast::{self, AstNode, NameOwner}; use test_utils::mark; use crate::{ - utils::{find_impl_block, find_struct_impl}, + utils::{find_impl_block, find_struct_impl, generate_impl_text}, AssistContext, AssistId, AssistKind, Assists, }; @@ -82,7 +82,7 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext) let start_offset = impl_def .and_then(|impl_def| find_impl_block(impl_def, &mut buf)) .unwrap_or_else(|| { - buf = generate_impl_text(&parent_enum, &buf); + buf = generate_impl_text(&ast::Adt::Enum(parent_enum.clone()), &buf); parent_enum.syntax().text_range().end() }); @@ -91,16 +91,6 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext) ) } -// Generates the surrounding `impl Type { }` including type and lifetime -// parameters -fn generate_impl_text(strukt: &ast::Enum, code: &str) -> String { - let mut buf = String::with_capacity(code.len()); - buf.push_str("\n\nimpl "); - buf.push_str(strukt.name().unwrap().text()); - format_to!(buf, " {{\n{}\n}}", code); - buf -} - #[cfg(test)] mod tests { use test_utils::mark; -- cgit v1.2.3