@@ -48,7 +48,6 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
49 // Hardcoded for rust for now
49 // Hardcoded for rust for now
50 let indent_scopes = &[
50 let indent_scopes = &[
51− // indent except first or block?
52 "while_expression",
51 "while_expression",
53 "for_expression",
52 "for_expression",
54 "loop_expression",
53 "loop_expression",
@@ -56,14 +55,9 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
56 "if_let_expression",
55 "if_let_expression",
57 // "match_expression",
56 // "match_expression",
58 // "match_arm",
57 // "match_arm",
61− // this is for multiline things, such as:
59+ // indent_except_first_scopes
62− // self.method()
60+ "use_list",
65− // where the first line isn't indented
66− let indent_except_first_scopes = &[
68 "match_block",
62 "match_block",
69 "arguments",
63 "arguments",
@@ -74,10 +68,7 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
74 // "closure_expression",
68 // "closure_expression",
75 "binary_expression",
69 "binary_expression",
76 "field_expression",
70 "field_expression",
78 "where_clause",
71 "where_clause",
83 let outdent = &["where", "}", "]", ")"];
74 let outdent = &["where", "}", "]", ")"];
@@ -92,36 +83,20 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
92 // if we're calculating indentation for a brand new line then the current node will become the
83 // if we're calculating indentation for a brand new line then the current node will become the
93 // parent node. We need to take it's indentation level into account too.
84 // parent node. We need to take it's indentation level into account too.
94 let node_kind = node.kind();
85 let node_kind = node.kind();
96− && (indent_scopes.contains(&node_kind) || indent_except_first_scopes.contains(&node_kind))
86+ if newline && indent_scopes.contains(&node_kind) {
98 increment += 1;
87 increment += 1;
101 while let Some(parent) = node.parent() {
90 while let Some(parent) = node.parent() {
102− let not_first_sibling = node.prev_sibling().is_some();
103− let not_last_sibling = node.next_sibling().is_some();
104− let not_first_or_last_sibling = not_first_sibling && not_last_sibling;
106 let parent_kind = parent.kind();
91 let parent_kind = parent.kind();
107 let start = parent.start_position().row;
92 let start = parent.start_position().row;
109 // detect deeply nested indents in the same line
94 // detect deeply nested indents in the same line
95+ // .map(|a| { <-- ({ is two scopes
96+ // let len = 1; <-- indents one level
97+ // }) <-- }) is two scopes
110 let starts_same_line = start == prev_start;
98 let starts_same_line = start == prev_start;
113− // "name: {}\tparent: {}\trange:\t{} {}\tfirst={:?}\tlast={:?} start={} prev={} same_line={}",
116− // node.range().start_point,
117− // node.range().end_point,
118− // node.prev_sibling().is_none(),
119− // node.next_sibling().is_none(),
120− // node.start_position(),
125 if outdent.contains(&node.kind()) && !starts_same_line {
100 if outdent.contains(&node.kind()) && !starts_same_line {
126 // we outdent by skipping the rules for the current level and jumping up
101 // we outdent by skipping the rules for the current level and jumping up
127 // node = parent;
102 // node = parent;
@@ -129,15 +104,7 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
129 // continue;
104 // continue;
132− // TODO: problem seems to be, ({ is two scopes that merge into one.
133− // so when seeing } we're supposed to jump all the way out of both scopes, but we only do
139− if (indent_scopes.contains(&parent_kind) // && not_first_or_last_sibling
107+ if indent_scopes.contains(&parent_kind) // && not_first_or_last_sibling
140− || indent_except_first_scopes.contains(&parent_kind))
141 && !starts_same_line
108 && !starts_same_line
143 // println!("is_scope {}", parent_kind);
110 // println!("is_scope {}", parent_kind);
@@ -145,11 +112,6 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
145 increment += 1
112 increment += 1
148− // TODO: detect deeply nested indents in same line:
149− // std::panic::set_hook(Box::new(move |info| {
150− // hook(info); <-- indent here is 1
153 // if last_scope && increment > 0 && ...{ ignore }
115 // if last_scope && increment > 0 && ...{ ignore }
155 node = parent;
117 node = parent;