Merge pull request #18667 from 1hakusai1/generate_custom_imple_with_no_snippet

fix: Generate implementation with items even if snippet text edit is disabled
This commit is contained in:
Lukas Wirth 2024-12-12 10:51:44 +00:00 committed by GitHub
commit 8ffa5ecb76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -139,7 +139,7 @@ fn add_assist(
let trait_path = make::ty_path(replace_trait_path.clone());
match (ctx.config.snippet_cap, impl_def_with_items) {
(None, _) => {
(None, None) => {
let impl_def = generate_trait_impl(adt, trait_path);
ted::insert_all(
@ -147,6 +147,12 @@ fn add_assist(
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
);
}
(None, Some((impl_def, _))) => {
ted::insert_all(
insert_after,
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
);
}
(Some(cap), None) => {
let impl_def = generate_trait_impl(adt, trait_path);
@ -272,7 +278,7 @@ fn update_attribute(
#[cfg(test)]
mod tests {
use crate::tests::{check_assist, check_assist_not_applicable};
use crate::tests::{check_assist, check_assist_no_snippet_cap, check_assist_not_applicable};
use super::*;
@ -297,6 +303,30 @@ impl core::fmt::Debug for Foo {
f.debug_struct("Foo").field("bar", &self.bar).finish()
}
}
"#,
)
}
#[test]
fn add_custom_impl_without_snippet() {
check_assist_no_snippet_cap(
replace_derive_with_manual_impl,
r#"
//- minicore: fmt, derive
#[derive(Debu$0g)]
struct Foo {
bar: String,
}
"#,
r#"
struct Foo {
bar: String,
}
impl core::fmt::Debug for Foo {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Foo").field("bar", &self.bar).finish()
}
}
"#,
)
}