Skip to content

Commit 8696c82

Browse files
committed
feat: generate getter assist places the cursor at the generated function
1 parent af54b1e commit 8696c82

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

crates/ide_assists/src/handlers/generate_getter.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
//
2424
// impl Person {
2525
// /// Get a reference to the person's name.
26-
// fn name(&self) -> &String {
26+
// fn $0name(&self) -> &String {
2727
// &self.name
2828
// }
2929
// }
@@ -49,7 +49,7 @@ pub(crate) fn generate_getter(acc: &mut Assists, ctx: &AssistContext) -> Option<
4949
//
5050
// impl Person {
5151
// /// Get a mutable reference to the person's name.
52-
// fn name_mut(&mut self) -> &mut String {
52+
// fn $0name_mut(&mut self) -> &mut String {
5353
// &mut self.name
5454
// }
5555
// }
@@ -119,7 +119,12 @@ pub(crate) fn generate_getter_impl(
119119
strukt.syntax().text_range().end()
120120
});
121121

122-
builder.insert(start_offset, buf);
122+
match ctx.config.snippet_cap {
123+
Some(cap) => {
124+
builder.insert_snippet(cap, start_offset, buf.replacen("fn ", "fn $0", 1))
125+
}
126+
None => builder.insert(start_offset, buf),
127+
}
123128
},
124129
)
125130
}
@@ -146,7 +151,7 @@ struct Context {
146151
147152
impl Context {
148153
/// Get a reference to the context's data.
149-
fn data(&self) -> &Data {
154+
fn $0data(&self) -> &Data {
150155
&self.data
151156
}
152157
}
@@ -167,7 +172,7 @@ struct Context {
167172
168173
impl Context {
169174
/// Get a mutable reference to the context's data.
170-
fn data_mut(&mut self) -> &mut Data {
175+
fn $0data_mut(&mut self) -> &mut Data {
171176
&mut self.data
172177
}
173178
}
@@ -224,7 +229,7 @@ pub(crate) struct Context {
224229
225230
impl Context {
226231
/// Get a reference to the context's data.
227-
pub(crate) fn data(&self) -> &Data {
232+
pub(crate) fn $0data(&self) -> &Data {
228233
&self.data
229234
}
230235
}
@@ -262,7 +267,7 @@ impl Context {
262267
}
263268
264269
/// Get a reference to the context's count.
265-
fn count(&self) -> &usize {
270+
fn $0count(&self) -> &usize {
266271
&self.count
267272
}
268273
}

crates/ide_assists/src/tests/generated.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ struct Person {
786786
787787
impl Person {
788788
/// Get a reference to the person's name.
789-
fn name(&self) -> &String {
789+
fn $0name(&self) -> &String {
790790
&self.name
791791
}
792792
}
@@ -810,7 +810,7 @@ struct Person {
810810
811811
impl Person {
812812
/// Get a mutable reference to the person's name.
813-
fn name_mut(&mut self) -> &mut String {
813+
fn $0name_mut(&mut self) -> &mut String {
814814
&mut self.name
815815
}
816816
}

0 commit comments

Comments
 (0)