Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-core/src/syntax.rs')
-rw-r--r--helix-core/src/syntax.rs52
1 files changed, 8 insertions, 44 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index 4bc177ef..1845686a 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -90,7 +90,7 @@ impl LanguageData {
Ok(Some(config))
}
- pub fn syntax_config(&self, loader: &Loader) -> Option<&SyntaxConfig> {
+ fn syntax_config(&self, loader: &Loader) -> Option<&SyntaxConfig> {
self.syntax
.get_or_init(|| {
Self::compile_syntax_config(&self.config, loader)
@@ -238,7 +238,7 @@ impl LanguageData {
}
}
-pub fn reconfigure_highlights(config: &SyntaxConfig, recognized_names: &[String]) {
+fn reconfigure_highlights(config: &SyntaxConfig, recognized_names: &[String]) {
config.configure(move |capture_name| {
let capture_parts: Vec<_> = capture_name.split('.').collect();
@@ -512,7 +512,7 @@ impl FileTypeGlobMatcher {
#[derive(Debug)]
pub struct Syntax {
- pub inner: tree_house::Syntax,
+ inner: tree_house::Syntax,
}
const PARSE_TIMEOUT: Duration = Duration::from_millis(500); // half a second is pretty generous
@@ -562,15 +562,15 @@ impl Syntax {
self.inner.tree_for_byte_range(start, end)
}
- pub fn named_descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Node<'_>> {
+ pub fn named_descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Node> {
self.inner.named_descendant_for_byte_range(start, end)
}
- pub fn descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Node<'_>> {
+ pub fn descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Node> {
self.inner.descendant_for_byte_range(start, end)
}
- pub fn walk(&self) -> TreeCursor<'_> {
+ pub fn walk(&self) -> TreeCursor {
self.inner.walk()
}
@@ -1073,7 +1073,7 @@ fn node_is_visible(node: &Node) -> bool {
node.is_missing() || (node.is_named() && node.grammar().node_kind_is_visible(node.kind_id()))
}
-fn format_anonymous_node_kind(kind: &str) -> Cow<'_, str> {
+fn format_anonymous_node_kind(kind: &str) -> Cow<str> {
if kind.contains('"') {
Cow::Owned(kind.replace('"', "\\\""))
} else {
@@ -1130,6 +1130,7 @@ fn pretty_print_tree_impl<W: fmt::Write>(
}
/// Finds the child of `node` which contains the given byte range.
+
pub fn child_for_byte_range<'a>(node: &Node<'a>, range: ops::Range<u32>) -> Option<Node<'a>> {
for child in node.children() {
let child_range = child.byte_range();
@@ -1203,24 +1204,7 @@ mod test {
);
let language = LOADER.language_for_name("rust").unwrap();
- dbg!(language);
let grammar = LOADER.get_config(language).unwrap().grammar;
- dbg!(grammar);
- let syntax = Syntax::new(source.slice(..), language, &LOADER).unwrap();
- let mut h = syntax.highlighter(
- "fn main() { 4 + 2; }".into(),
- &LOADER,
- 0.."fn main() { 4 + 2; }".len() as u32,
- );
-
- for n in 0..5 {
- dbg!(h.active_highlights().collect::<Vec<_>>());
- dbg!(h.next_event_offset());
- let (e, h) = h.advance();
- dbg!(h.collect::<Vec<_>>(), e);
- // panic!()
- }
-
let query = Query::new(grammar, query_str, |_, _| Ok(())).unwrap();
let textobject = TextObjectQuery::new(query);
let syntax = Syntax::new(source.slice(..), language, &LOADER).unwrap();
@@ -1385,24 +1369,4 @@ mod test {
source.len(),
);
}
- #[test]
- fn highlight() {
- let source = Rope::from_str(r#"assert_eq!(0, Some(0));"#);
- let loader = crate::config::default_lang_loader();
- loader.set_scopes(vec!["punctuation".to_string()]);
- let language = loader.language_for_name("rust").unwrap();
-
- let syntax = Syntax::new(source.slice(..), language, &loader).unwrap();
- println!(
- "{}",
- tree_house::fixtures::highlighter_fixture(
- "",
- &loader,
- |_| "punct".to_string(),
- &syntax.inner,
- source.slice(..),
- ..,
- )
- );
- }
}