aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/syntax.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src/syntax.rs')
-rw-r--r--helix-core/src/syntax.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index 6414f3ce..78abc0b0 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -1,3 +1,5 @@
+mod tree_cursor;
+
use crate::{
auto_pairs::AutoPairs,
chars::char_is_line_ending,
@@ -32,6 +34,8 @@ use serde::{ser::SerializeSeq, Deserialize, Serialize};
use helix_loader::grammar::{get_language, load_runtime_file};
+pub use tree_cursor::TreeCursor;
+
fn deserialize_regex<'de, D>(deserializer: D) -> Result<Option<Regex>, D::Error>
where
D: serde::Deserializer<'de>,
@@ -1495,6 +1499,12 @@ impl Syntax {
.descendant_for_byte_range(start, end)
}
+ pub fn walk(&self) -> TreeCursor<'_> {
+ // data structure to find the smallest range that contains a point
+ // when some of the ranges in the structure can overlap.
+ TreeCursor::new(&self.layers, self.root)
+ }
+
// Commenting
// comment_strings_for_pos
// is_commented
@@ -1723,7 +1733,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::{iter, mem, ops, str, usize};
use tree_sitter::{
Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError,
- QueryMatch, Range, TextProvider, Tree, TreeCursor,
+ QueryMatch, Range, TextProvider, Tree,
};
const CANCELLATION_CHECK_INTERVAL: usize = 100;
@@ -2657,7 +2667,7 @@ pub fn pretty_print_tree<W: fmt::Write>(fmt: &mut W, node: Node) -> fmt::Result
fn pretty_print_tree_impl<W: fmt::Write>(
fmt: &mut W,
- cursor: &mut TreeCursor,
+ cursor: &mut tree_sitter::TreeCursor,
depth: usize,
) -> fmt::Result {
let node = cursor.node();
@@ -2967,7 +2977,7 @@ mod test {
// rule but `name` and `body` belong to an unnamed helper `_method_rest`.
// This can cause a bug with a pretty-printing implementation that
// uses `Node::field_name_for_child` to determine field names but is
- // fixed when using `TreeCursor::field_name`.
+ // fixed when using `tree_sitter::TreeCursor::field_name`.
let source = "def self.method_name
true
end";