about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorLukas Wirth <me@lukaswirth.dev>2025-07-29 10:12:14 +0000
committerGitHub <noreply@github.com>2025-07-29 10:12:14 +0000
commitf5ecbb5eff5591d30de250f62f5ae1bcbd4e1afe (patch)
treec2d09fc5a3e487b970fe680316f511d9d5996e57 /src/tools
parentf7c3a899327bd272572f82ffba64e2ea024f3710 (diff)
parentbad05ff4ffa5a61dcc8787d40796f9533b33b750 (diff)
downloadrust-f5ecbb5eff5591d30de250f62f5ae1bcbd4e1afe.tar.gz
rust-f5ecbb5eff5591d30de250f62f5ae1bcbd4e1afe.zip
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
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs
index 9c4bcdd4030..ae1ae24d1ec 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs
@@ -104,7 +104,14 @@ pub(crate) fn generate_mut_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>
         format!("Generate `{trait_new}` impl from this `{trait_name}` trait"),
         target,
         |edit| {
-            edit.insert(target.start(), format!("$0{impl_def}\n\n{indent}"));
+            edit.insert(
+                target.start(),
+                if ctx.config.snippet_cap.is_some() {
+                    format!("$0{impl_def}\n\n{indent}")
+                } else {
+                    format!("{impl_def}\n\n{indent}")
+                },
+            );
         },
     )
 }
@@ -161,7 +168,10 @@ fn process_ret_type(ref_ty: &ast::RetType) -> Option<ast::Type> {
 
 #[cfg(test)]
 mod tests {
-    use crate::tests::{check_assist, check_assist_not_applicable};
+    use crate::{
+        AssistConfig,
+        tests::{TEST_CONFIG, check_assist, check_assist_not_applicable, check_assist_with_config},
+    };
 
     use super::*;
 
@@ -405,4 +415,41 @@ impl AsRef$0<i32> for [T; 3] {}
 "#,
         );
     }
+
+    #[test]
+    fn no_snippets() {
+        check_assist_with_config(
+            generate_mut_trait_impl,
+            AssistConfig { snippet_cap: None, ..TEST_CONFIG },
+            r#"
+//- minicore: index
+pub enum Axis { X = 0, Y = 1, Z = 2 }
+
+impl<T> core::ops::Index$0<Axis> for [T; 3] {
+    type Output = T;
+
+    fn index(&self, index: Axis) -> &Self::Output {
+        &self[index as usize]
+    }
+}
+"#,
+            r#"
+pub enum Axis { X = 0, Y = 1, Z = 2 }
+
+impl<T> core::ops::IndexMut<Axis> for [T; 3] {
+    fn index_mut(&mut self, index: Axis) -> &mut Self::Output {
+        &mut self[index as usize]
+    }
+}
+
+impl<T> core::ops::Index<Axis> for [T; 3] {
+    type Output = T;
+
+    fn index(&self, index: Axis) -> &Self::Output {
+        &self[index as usize]
+    }
+}
+"#,
+        );
+    }
 }