Skip to content

Commit 06dc358

Browse files
authored
Merge pull request #20336 from ChayimFriedman2/mut-trait-impl-snippet
fix: In generate_mut_trait_impl, don't add a tabstop if the client does not support snippets
2 parents 67edaa3 + 8394155 commit 06dc358

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

crates/ide-assists/src/handlers/generate_mut_trait_impl.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ pub(crate) fn generate_mut_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>
104104
format!("Generate `{trait_new}` impl from this `{trait_name}` trait"),
105105
target,
106106
|edit| {
107-
edit.insert(target.start(), format!("$0{impl_def}\n\n{indent}"));
107+
edit.insert(
108+
target.start(),
109+
if ctx.config.snippet_cap.is_some() {
110+
format!("$0{impl_def}\n\n{indent}")
111+
} else {
112+
format!("{impl_def}\n\n{indent}")
113+
},
114+
);
108115
},
109116
)
110117
}
@@ -161,7 +168,10 @@ fn process_ret_type(ref_ty: &ast::RetType) -> Option<ast::Type> {
161168

162169
#[cfg(test)]
163170
mod tests {
164-
use crate::tests::{check_assist, check_assist_not_applicable};
171+
use crate::{
172+
AssistConfig,
173+
tests::{TEST_CONFIG, check_assist, check_assist_not_applicable, check_assist_with_config},
174+
};
165175

166176
use super::*;
167177

@@ -402,6 +412,43 @@ impl<T> Index$0<i32> for [T; 3] {}
402412
pub trait AsRef<T: ?Sized> {}
403413
404414
impl AsRef$0<i32> for [T; 3] {}
415+
"#,
416+
);
417+
}
418+
419+
#[test]
420+
fn no_snippets() {
421+
check_assist_with_config(
422+
generate_mut_trait_impl,
423+
AssistConfig { snippet_cap: None, ..TEST_CONFIG },
424+
r#"
425+
//- minicore: index
426+
pub enum Axis { X = 0, Y = 1, Z = 2 }
427+
428+
impl<T> core::ops::Index$0<Axis> for [T; 3] {
429+
type Output = T;
430+
431+
fn index(&self, index: Axis) -> &Self::Output {
432+
&self[index as usize]
433+
}
434+
}
435+
"#,
436+
r#"
437+
pub enum Axis { X = 0, Y = 1, Z = 2 }
438+
439+
impl<T> core::ops::IndexMut<Axis> for [T; 3] {
440+
fn index_mut(&mut self, index: Axis) -> &mut Self::Output {
441+
&mut self[index as usize]
442+
}
443+
}
444+
445+
impl<T> core::ops::Index<Axis> for [T; 3] {
446+
type Output = T;
447+
448+
fn index(&self, index: Axis) -> &Self::Output {
449+
&self[index as usize]
450+
}
451+
}
405452
"#,
406453
);
407454
}

0 commit comments

Comments
 (0)