aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/typing
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/typing')
-rw-r--r--crates/ra_ide/src/typing/on_enter.rs32
1 files changed, 15 insertions, 17 deletions
diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs
index 30c8c5572..85be14ad3 100644
--- a/crates/ra_ide/src/typing/on_enter.rs
+++ b/crates/ra_ide/src/typing/on_enter.rs
@@ -38,17 +38,15 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
38 } 38 }
39 39
40 let indent = node_indent(&file, comment.syntax())?; 40 let indent = node_indent(&file, comment.syntax())?;
41 let inserted = format!("\n{}{} ", indent, prefix); 41 let inserted = format!("\n{}{} $0", indent, prefix);
42 let cursor_position = position.offset + TextSize::of(&inserted);
43 let edit = TextEdit::insert(position.offset, inserted); 42 let edit = TextEdit::insert(position.offset, inserted);
44 43
45 Some( 44 let mut res = SourceChange::source_file_edit(
46 SourceChange::source_file_edit( 45 "On enter",
47 "on enter", 46 SourceFileEdit { edit, file_id: position.file_id },
48 SourceFileEdit { edit, file_id: position.file_id }, 47 );
49 ) 48 res.is_snippet = true;
50 .with_cursor(FilePosition { offset: cursor_position, file_id: position.file_id }), 49 Some(res)
51 )
52} 50}
53 51
54fn followed_by_comment(comment: &ast::Comment) -> bool { 52fn followed_by_comment(comment: &ast::Comment) -> bool {
@@ -84,7 +82,7 @@ fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> {
84 82
85#[cfg(test)] 83#[cfg(test)]
86mod tests { 84mod tests {
87 use test_utils::{add_cursor, assert_eq_text, extract_offset}; 85 use test_utils::{assert_eq_text, extract_offset};
88 86
89 use crate::mock_analysis::single_file; 87 use crate::mock_analysis::single_file;
90 88
@@ -96,8 +94,8 @@ mod tests {
96 let result = analysis.on_enter(FilePosition { offset, file_id }).unwrap()?; 94 let result = analysis.on_enter(FilePosition { offset, file_id }).unwrap()?;
97 95
98 assert_eq!(result.source_file_edits.len(), 1); 96 assert_eq!(result.source_file_edits.len(), 1);
99 let actual = result.source_file_edits[0].edit.apply(&before); 97 let mut actual = before.to_string();
100 let actual = add_cursor(&actual, result.cursor_position.unwrap().offset); 98 result.source_file_edits[0].edit.apply(&mut actual);
101 Some(actual) 99 Some(actual)
102 } 100 }
103 101
@@ -120,7 +118,7 @@ fn foo() {
120", 118",
121 r" 119 r"
122/// Some docs 120/// Some docs
123/// <|> 121/// $0
124fn foo() { 122fn foo() {
125} 123}
126", 124",
@@ -136,7 +134,7 @@ impl S {
136 r" 134 r"
137impl S { 135impl S {
138 /// Some 136 /// Some
139 /// <|> docs. 137 /// $0 docs.
140 fn foo() {} 138 fn foo() {}
141} 139}
142", 140",
@@ -150,7 +148,7 @@ fn foo() {
150", 148",
151 r" 149 r"
152/// 150///
153/// <|> Some docs 151/// $0 Some docs
154fn foo() { 152fn foo() {
155} 153}
156", 154",
@@ -174,7 +172,7 @@ fn main() {
174 r" 172 r"
175fn main() { 173fn main() {
176 // Fix 174 // Fix
177 // <|> me 175 // $0 me
178 let x = 1 + 1; 176 let x = 1 + 1;
179} 177}
180", 178",
@@ -194,7 +192,7 @@ fn main() {
194 r" 192 r"
195fn main() { 193fn main() {
196 // Fix 194 // Fix
197 // <|> 195 // $0
198 // me 196 // me
199 let x = 1 + 1; 197 let x = 1 + 1;
200} 198}