aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-04-14 05:28:31 +0000
committerBlaž Hrastnik2021-04-14 05:28:31 +0000
commit9445b24b883b9b78d2f0f2ba1e2151e92ac787f5 (patch)
treeb2405dec7189a46851da3685519cbe8b46a14672 /helix-core
parent180521fefec8923bd4082c4a1e9beca599a44d07 (diff)
Simplify calculate_indentation.
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/indent.rs52
1 files changed, 7 insertions, 45 deletions
diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs
index ed5a8a47..4ea920cc 100644
--- a/helix-core/src/indent.rs
+++ b/helix-core/src/indent.rs
@@ -48,7 +48,6 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
// Hardcoded for rust for now
let indent_scopes = &[
- // indent except first or block?
"while_expression",
"for_expression",
"loop_expression",
@@ -56,14 +55,9 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
"if_let_expression",
// "match_expression",
// "match_arm",
- ];
- // this is for multiline things, such as:
- // self.method()
- // .chain()
- // .chain()
- // where the first line isn't indented
- let indent_except_first_scopes = &[
+ // indent_except_first_scopes
+ "use_list",
"block",
"match_block",
"arguments",
@@ -74,10 +68,7 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
// "closure_expression",
"binary_expression",
"field_expression",
- //
"where_clause",
- //
- "use_list",
];
let outdent = &["where", "}", "]", ")"];
@@ -92,36 +83,20 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
// if we're calculating indentation for a brand new line then the current node will become the
// parent node. We need to take it's indentation level into account too.
let node_kind = node.kind();
- if newline
- && (indent_scopes.contains(&node_kind) || indent_except_first_scopes.contains(&node_kind))
- {
+ if newline && indent_scopes.contains(&node_kind) {
increment += 1;
}
while let Some(parent) = node.parent() {
- let not_first_sibling = node.prev_sibling().is_some();
- let not_last_sibling = node.next_sibling().is_some();
- let not_first_or_last_sibling = not_first_sibling && not_last_sibling;
-
let parent_kind = parent.kind();
let start = parent.start_position().row;
// detect deeply nested indents in the same line
+ // .map(|a| { <-- ({ is two scopes
+ // let len = 1; <-- indents one level
+ // }) <-- }) is two scopes
let starts_same_line = start == prev_start;
- // log::error!(
- // "name: {}\tparent: {}\trange:\t{} {}\tfirst={:?}\tlast={:?} start={} prev={} same_line={}",
- // node.kind(),
- // parent.kind(),
- // node.range().start_point,
- // node.range().end_point,
- // node.prev_sibling().is_none(),
- // node.next_sibling().is_none(),
- // node.start_position(),
- // prev_start,
- // starts_same_line
- // );
-
if outdent.contains(&node.kind()) && !starts_same_line {
// we outdent by skipping the rules for the current level and jumping up
// node = parent;
@@ -129,15 +104,7 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
// continue;
}
- // TODO: problem seems to be, ({ is two scopes that merge into one.
- // so when seeing } we're supposed to jump all the way out of both scopes, but we only do
- // so for one.
- // .map(|a| {
- // let len = 1;
- // })
-
- if (indent_scopes.contains(&parent_kind) // && not_first_or_last_sibling
- || indent_except_first_scopes.contains(&parent_kind))
+ if indent_scopes.contains(&parent_kind) // && not_first_or_last_sibling
&& !starts_same_line
{
// println!("is_scope {}", parent_kind);
@@ -145,11 +112,6 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
increment += 1
}
- // TODO: detect deeply nested indents in same line:
- // std::panic::set_hook(Box::new(move |info| {
- // hook(info); <-- indent here is 1
- // }));
-
// if last_scope && increment > 0 && ...{ ignore }
node = parent;