aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/indent.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-12-03 04:12:40 +0000
committerGitHub2020-12-03 04:12:40 +0000
commitb7a3e525ed7fed5ed79e8580df2e3496bd994419 (patch)
treed202637047759b0510a16d8c59fdbbde62b50617 /helix-core/src/indent.rs
parent2e12fc9a7cd221bb7b5f4b5c1ece599089770ccb (diff)
parent39bf1ca82514e1dc56dfebdce2558cce662367d1 (diff)
Merge pull request #5 from helix-editor/lsp
LSP: mk1
Diffstat (limited to 'helix-core/src/indent.rs')
-rw-r--r--helix-core/src/indent.rs29
1 files changed, 17 insertions, 12 deletions
diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs
index 2e1a095e..6b9a1ab1 100644
--- a/helix-core/src/indent.rs
+++ b/helix-core/src/indent.rs
@@ -111,17 +111,17 @@ fn find_first_non_whitespace_char(state: &State, line_num: usize) -> usize {
start
}
-fn suggested_indent_for_line(state: &State, line_num: usize) -> usize {
+fn suggested_indent_for_line(syntax: Option<&Syntax>, state: &State, line_num: usize) -> usize {
let line = state.doc.line(line_num);
let current = indent_level_for_line(line);
let start = find_first_non_whitespace_char(state, line_num);
- suggested_indent_for_pos(state, start)
+ suggested_indent_for_pos(syntax, state, start)
}
-pub fn suggested_indent_for_pos(state: &State, pos: usize) -> usize {
- if let Some(syntax) = &state.syntax {
+pub fn suggested_indent_for_pos(syntax: Option<&Syntax>, state: &State, pos: usize) -> usize {
+ if let Some(syntax) = syntax {
let byte_start = state.doc.char_to_byte(pos);
let node = get_highest_syntax_node_at_bytepos(syntax, byte_start);
@@ -163,13 +163,18 @@ mod test {
",
);
- let mut state = State::new(doc);
- state.set_language("source.rust", &[]);
-
- assert_eq!(suggested_indent_for_line(&state, 0), 0); // mod
- assert_eq!(suggested_indent_for_line(&state, 1), 1); // fn
- assert_eq!(suggested_indent_for_line(&state, 2), 2); // 1 + 1
- assert_eq!(suggested_indent_for_line(&state, 4), 1); // }
- assert_eq!(suggested_indent_for_line(&state, 5), 0); // }
+ let state = State::new(doc);
+ // TODO: set_language
+ let language_config = crate::syntax::LOADER
+ .language_config_for_scope("source.rust")
+ .unwrap();
+ let highlight_config = language_config.highlight_config(&[]).unwrap().unwrap();
+ let syntax = Syntax::new(&state.doc, highlight_config.clone());
+
+ assert_eq!(suggested_indent_for_line(Some(&syntax), &state, 0), 0); // mod
+ assert_eq!(suggested_indent_for_line(Some(&syntax), &state, 1), 1); // fn
+ assert_eq!(suggested_indent_for_line(Some(&syntax), &state, 2), 2); // 1 + 1
+ assert_eq!(suggested_indent_for_line(Some(&syntax), &state, 4), 1); // }
+ assert_eq!(suggested_indent_for_line(Some(&syntax), &state, 5), 0); // }
}
}