aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/indent.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-08-13 04:15:36 +0000
committerBlaž Hrastnik2021-08-13 04:15:53 +0000
commitfd1eaafff57fb40dd0e504c3d5fd5e8abe14b5f5 (patch)
tree9ba95a477b7558ca5cdbf443b4229e801ef45df9 /helix-core/src/indent.rs
parent88cc0f85a57252c2fc008c3efd65c2dda7023bdc (diff)
Add :tree-sitter-scopes, useful when developing indents.toml
Diffstat (limited to 'helix-core/src/indent.rs')
-rw-r--r--helix-core/src/indent.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs
index d272dd68..9489baa7 100644
--- a/helix-core/src/indent.rs
+++ b/helix-core/src/indent.rs
@@ -313,6 +313,27 @@ pub fn suggested_indent_for_pos(
}
}
+pub fn get_scopes(syntax: Option<&Syntax>, text: RopeSlice, pos: usize) -> Vec<&'static str> {
+ let mut scopes = Vec::new();
+ if let Some(syntax) = syntax {
+ let byte_start = text.char_to_byte(pos);
+ let node = match get_highest_syntax_node_at_bytepos(syntax, byte_start) {
+ Some(node) => node,
+ None => return scopes,
+ };
+
+ scopes.push(node.kind());
+
+ while let Some(parent) = node.parent() {
+ scopes.push(parent.kind())
+ }
+ }
+
+ scopes.reverse();
+
+ return scopes;
+}
+
#[cfg(test)]
mod test {
use super::*;