aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/typing.rs20
1 files changed, 7 insertions, 13 deletions
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs
index 6f04f0be4..867a0f0bd 100644
--- a/crates/ra_ide/src/typing.rs
+++ b/crates/ra_ide/src/typing.rs
@@ -111,7 +111,7 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<SingleFileChange>
111 Some(SingleFileChange { 111 Some(SingleFileChange {
112 label: "reindent dot".to_string(), 112 label: "reindent dot".to_string(),
113 edit: TextEdit::replace(TextRange::new(offset - current_indent_len, offset), target_indent), 113 edit: TextEdit::replace(TextRange::new(offset - current_indent_len, offset), target_indent),
114 cursor_position: Some(offset + target_indent_len - current_indent_len + TextSize::of('.')), 114 cursor_position: None,
115 }) 115 })
116} 116}
117 117
@@ -130,7 +130,7 @@ fn on_arrow_typed(file: &SourceFile, offset: TextSize) -> Option<SingleFileChang
130 Some(SingleFileChange { 130 Some(SingleFileChange {
131 label: "add space after return type".to_string(), 131 label: "add space after return type".to_string(),
132 edit: TextEdit::insert(after_arrow, " ".to_string()), 132 edit: TextEdit::insert(after_arrow, " ".to_string()),
133 cursor_position: Some(after_arrow), 133 cursor_position: None,
134 }) 134 })
135} 135}
136 136
@@ -140,7 +140,7 @@ mod tests {
140 140
141 use super::*; 141 use super::*;
142 142
143 fn do_type_char(char_typed: char, before: &str) -> Option<(String, SingleFileChange)> { 143 fn do_type_char(char_typed: char, before: &str) -> Option<String> {
144 let (offset, before) = extract_offset(before); 144 let (offset, before) = extract_offset(before);
145 let edit = TextEdit::insert(offset, char_typed.to_string()); 145 let edit = TextEdit::insert(offset, char_typed.to_string());
146 let mut before = before.to_string(); 146 let mut before = before.to_string();
@@ -148,21 +148,15 @@ mod tests {
148 let parse = SourceFile::parse(&before); 148 let parse = SourceFile::parse(&before);
149 on_char_typed_inner(&parse.tree(), offset, char_typed).map(|it| { 149 on_char_typed_inner(&parse.tree(), offset, char_typed).map(|it| {
150 it.edit.apply(&mut before); 150 it.edit.apply(&mut before);
151 (before.to_string(), it) 151 before.to_string()
152 }) 152 })
153 } 153 }
154 154
155 fn type_char(char_typed: char, before: &str, after: &str) { 155 fn type_char(char_typed: char, before: &str, after: &str) {
156 let (actual, file_change) = do_type_char(char_typed, before) 156 let actual = do_type_char(char_typed, before)
157 .unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed)); 157 .unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed));
158 158
159 if after.contains("<|>") { 159 assert_eq_text!(after, &actual);
160 let (offset, after) = extract_offset(after);
161 assert_eq_text!(&after, &actual);
162 assert_eq!(file_change.cursor_position, Some(offset))
163 } else {
164 assert_eq_text!(after, &actual);
165 }
166 } 160 }
167 161
168 fn type_char_noop(char_typed: char, before: &str) { 162 fn type_char_noop(char_typed: char, before: &str) {
@@ -350,6 +344,6 @@ fn foo() {
350 344
351 #[test] 345 #[test]
352 fn adds_space_after_return_type() { 346 fn adds_space_after_return_type() {
353 type_char('>', "fn foo() -<|>{ 92 }", "fn foo() -><|> { 92 }") 347 type_char('>', "fn foo() -<|>{ 92 }", "fn foo() -> { 92 }")
354 } 348 }
355} 349}