Skip to content

Commit c17d430

Browse files
authored
Merge pull request rust-lang#18667 from 1hakusai1/generate_custom_imple_with_no_snippet
fix: Generate implementation with items even if snippet text edit is disabled
2 parents 96d9761 + 41bd955 commit c17d430

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,20 @@ fn add_assist(
139139
let trait_path = make::ty_path(replace_trait_path.clone());
140140

141141
match (ctx.config.snippet_cap, impl_def_with_items) {
142-
(None, _) => {
142+
(None, None) => {
143143
let impl_def = generate_trait_impl(adt, trait_path);
144144

145145
ted::insert_all(
146146
insert_after,
147147
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
148148
);
149149
}
150+
(None, Some((impl_def, _))) => {
151+
ted::insert_all(
152+
insert_after,
153+
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
154+
);
155+
}
150156
(Some(cap), None) => {
151157
let impl_def = generate_trait_impl(adt, trait_path);
152158

@@ -272,7 +278,7 @@ fn update_attribute(
272278

273279
#[cfg(test)]
274280
mod tests {
275-
use crate::tests::{check_assist, check_assist_not_applicable};
281+
use crate::tests::{check_assist, check_assist_no_snippet_cap, check_assist_not_applicable};
276282

277283
use super::*;
278284

@@ -297,6 +303,30 @@ impl core::fmt::Debug for Foo {
297303
f.debug_struct("Foo").field("bar", &self.bar).finish()
298304
}
299305
}
306+
"#,
307+
)
308+
}
309+
#[test]
310+
fn add_custom_impl_without_snippet() {
311+
check_assist_no_snippet_cap(
312+
replace_derive_with_manual_impl,
313+
r#"
314+
//- minicore: fmt, derive
315+
#[derive(Debu$0g)]
316+
struct Foo {
317+
bar: String,
318+
}
319+
"#,
320+
r#"
321+
struct Foo {
322+
bar: String,
323+
}
324+
325+
impl core::fmt::Debug for Foo {
326+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
327+
f.debug_struct("Foo").field("bar", &self.bar).finish()
328+
}
329+
}
300330
"#,
301331
)
302332
}

0 commit comments

Comments
 (0)