about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2021-05-23 23:22:38 +0300
committerAleksey Kladov <aleksey.kladov@gmail.com>2021-05-23 23:43:33 +0300
commit8696c82777f9992fceadc531536bf90b64cf753d (patch)
treea4adc7abf12fd3b1e61aca0c922b93e0eaab800b
parentaf54b1e248f377853957ada0270e269bedb577b4 (diff)
downloadrust-8696c82777f9992fceadc531536bf90b64cf753d.tar.gz
rust-8696c82777f9992fceadc531536bf90b64cf753d.zip
feat: generate getter assist places the cursor at the generated function
-rw-r--r--crates/ide_assists/src/handlers/generate_getter.rs19
-rw-r--r--crates/ide_assists/src/tests/generated.rs4
2 files changed, 14 insertions, 9 deletions
diff --git a/crates/ide_assists/src/handlers/generate_getter.rs b/crates/ide_assists/src/handlers/generate_getter.rs
index c7739582446..9faaaf284b0 100644
--- a/crates/ide_assists/src/handlers/generate_getter.rs
+++ b/crates/ide_assists/src/handlers/generate_getter.rs
@@ -23,7 +23,7 @@ use crate::{
 //
 // impl Person {
 //     /// Get a reference to the person's name.
-//     fn name(&self) -> &String {
+//     fn $0name(&self) -> &String {
 //         &self.name
 //     }
 // }
@@ -49,7 +49,7 @@ pub(crate) fn generate_getter(acc: &mut Assists, ctx: &AssistContext) -> Option<
 //
 // impl Person {
 //     /// Get a mutable reference to the person's name.
-//     fn name_mut(&mut self) -> &mut String {
+//     fn $0name_mut(&mut self) -> &mut String {
 //         &mut self.name
 //     }
 // }
@@ -119,7 +119,12 @@ pub(crate) fn generate_getter_impl(
                     strukt.syntax().text_range().end()
                 });
 
-            builder.insert(start_offset, buf);
+            match ctx.config.snippet_cap {
+                Some(cap) => {
+                    builder.insert_snippet(cap, start_offset, buf.replacen("fn ", "fn $0", 1))
+                }
+                None => builder.insert(start_offset, buf),
+            }
         },
     )
 }
@@ -146,7 +151,7 @@ struct Context {
 
 impl Context {
     /// Get a reference to the context's data.
-    fn data(&self) -> &Data {
+    fn $0data(&self) -> &Data {
         &self.data
     }
 }
@@ -167,7 +172,7 @@ struct Context {
 
 impl Context {
     /// Get a mutable reference to the context's data.
-    fn data_mut(&mut self) -> &mut Data {
+    fn $0data_mut(&mut self) -> &mut Data {
         &mut self.data
     }
 }
@@ -224,7 +229,7 @@ pub(crate) struct Context {
 
 impl Context {
     /// Get a reference to the context's data.
-    pub(crate) fn data(&self) -> &Data {
+    pub(crate) fn $0data(&self) -> &Data {
         &self.data
     }
 }
@@ -262,7 +267,7 @@ impl Context {
     }
 
     /// Get a reference to the context's count.
-    fn count(&self) -> &usize {
+    fn $0count(&self) -> &usize {
         &self.count
     }
 }
diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs
index 4406406a278..ffc915fd4d9 100644
--- a/crates/ide_assists/src/tests/generated.rs
+++ b/crates/ide_assists/src/tests/generated.rs
@@ -786,7 +786,7 @@ struct Person {
 
 impl Person {
     /// Get a reference to the person's name.
-    fn name(&self) -> &String {
+    fn $0name(&self) -> &String {
         &self.name
     }
 }
@@ -810,7 +810,7 @@ struct Person {
 
 impl Person {
     /// Get a mutable reference to the person's name.
-    fn name_mut(&mut self) -> &mut String {
+    fn $0name_mut(&mut self) -> &mut String {
         &mut self.name
     }
 }