aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r--crates/ra_editor/src/typing.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs
index 4ee4f394f..c0b22a9ec 100644
--- a/crates/ra_editor/src/typing.rs
+++ b/crates/ra_editor/src/typing.rs
@@ -139,32 +139,30 @@ pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit>
139pub fn on_dot_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { 139pub fn on_dot_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> {
140 let before_dot_offset = offset - TextUnit::of_char('.'); 140 let before_dot_offset = offset - TextUnit::of_char('.');
141 141
142 let _whitespace = find_leaf_at_offset(file.syntax(), before_dot_offset).left_biased()?; 142 let whitespace = find_leaf_at_offset(file.syntax(), before_dot_offset).left_biased()?;
143 143
144 // find whitespace just left of the dot 144 // find whitespace just left of the dot
145 ast::Whitespace::cast(_whitespace)?; 145 ast::Whitespace::cast(whitespace)?;
146 146
147 // make sure there is a method call 147 // make sure there is a method call
148 let _method_call = _whitespace 148 let method_call = whitespace
149 .siblings(Direction::Prev) 149 .siblings(Direction::Prev)
150 // first is whitespace 150 // first is whitespace
151 .skip(1) 151 .skip(1)
152 .next()?; 152 .next()?;
153 153
154 ast::MethodCallExprNode::cast(_method_call)?; 154 ast::MethodCallExprNode::cast(method_call)?;
155 155
156 // find how much the _method call is indented 156 // find how much the _method call is indented
157 let method_chain_indent = _method_call 157 let method_chain_indent = method_call
158 .ancestors() 158 .parent()?
159 .skip(1)
160 .next()?
161 .siblings(Direction::Prev) 159 .siblings(Direction::Prev)
162 .skip(1) 160 .skip(1)
163 .next()? 161 .next()?
164 .leaf_text() 162 .leaf_text()
165 .map(|x| last_line_indent_in_whitespace(x))?; 163 .map(|x| last_line_indent_in_whitespace(x))?;
166 164
167 let current_indent = TextUnit::of_str(last_line_indent_in_whitespace(_whitespace.leaf_text()?)); 165 let current_indent = TextUnit::of_str(last_line_indent_in_whitespace(whitespace.leaf_text()?));
168 // TODO: indent is always 4 spaces now. A better heuristic could look on the previous line(s) 166 // TODO: indent is always 4 spaces now. A better heuristic could look on the previous line(s)
169 167
170 let target_indent = TextUnit::of_str(method_chain_indent) + TextUnit::from_usize(4); 168 let target_indent = TextUnit::of_str(method_chain_indent) + TextUnit::from_usize(4);
@@ -337,7 +335,7 @@ mod tests {
337 use super::*; 335 use super::*;
338 use crate::test_utils::{ 336 use crate::test_utils::{
339 add_cursor, assert_eq_text, check_action, extract_offset, extract_range, 337 add_cursor, assert_eq_text, check_action, extract_offset, extract_range,
340}; 338 };
341 339
342 fn check_join_lines(before: &str, after: &str) { 340 fn check_join_lines(before: &str, after: &str) {
343 check_action(before, after, |file, offset| { 341 check_action(before, after, |file, offset| {