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,
};
// Return early if we've found an existing new fn
let impl_def = find_struct_impl(
&ctx,
- &ast::AdtDef::Enum(parent_enum.clone()),
+ &ast::Adt::Enum(parent_enum.clone()),
format!("is_{}", fn_name).as_str(),
)?;
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()
});
)
}
-// Generates the surrounding `impl Type { <code> }` 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;