From 8bbebf7e57600d9f03c607a000188a784728ca11 Mon Sep 17 00:00:00 2001 From: Alex Pasmantier <47638216+alexpasmantier@users.noreply.github.com> Date: Mon, 20 Jan 2025 12:09:00 +0100 Subject: [PATCH] fix(syntect): switch back to oniguruma while investigating parsing issues (#292) Temp fix for #289 --- Cargo.lock | 49 +++++++++---------- Cargo.toml | 4 +- .../src/previewers/files.rs | 8 +-- crates/television-utils/Cargo.toml | 2 +- crates/television-utils/src/syntax.rs | 39 ++++++++------- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 178aee9..8d36fb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -223,21 +223,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bit-set" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - [[package]] name = "bitflags" version = "1.3.2" @@ -964,16 +949,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "fancy-regex" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2" -dependencies = [ - "bit-set", - "regex", -] - [[package]] name = "faster-hex" version = "0.9.0" @@ -2235,6 +2210,28 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "onig" +version = "6.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c4b31c8722ad9171c6d77d3557db078cab2bd50afcc9d09c8b315c59df8ca4f" +dependencies = [ + "bitflags 1.3.2", + "libc", + "once_cell", + "onig_sys", +] + +[[package]] +name = "onig_sys" +version = "69.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b829e3d7e9cc74c7e315ee8edb185bf4190da5acde74afd7fc59c35b1f086e7" +dependencies = [ + "cc", + "pkg-config", +] + [[package]] name = "oorandom" version = "11.1.4" @@ -2982,10 +2979,10 @@ checksum = "874dcfa363995604333cf947ae9f751ca3af4522c60886774c4963943b4746b1" dependencies = [ "bincode", "bitflags 1.3.2", - "fancy-regex", "flate2", "fnv", "once_cell", + "onig", "plist", "regex-syntax 0.8.5", "serde", diff --git a/Cargo.toml b/Cargo.toml index d885837..0a31cd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,9 +63,7 @@ tokio = { version = "1.41.1", features = ["full"] } tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] } rustc-hash = "2.1.0" -syntect = { version = "5.2.0", default-features = false, features = [ - "default-fancy", -] } +syntect = { version = "5.2.0" } unicode-width = "0.2.0" clap = { version = "4.5.20", features = ["derive", "cargo", "string"] } serde = { version = "1.0.214", features = ["derive"] } diff --git a/crates/television-previewers/src/previewers/files.rs b/crates/television-previewers/src/previewers/files.rs index cf48128..d8854b7 100644 --- a/crates/television-previewers/src/previewers/files.rs +++ b/crates/television-previewers/src/previewers/files.rs @@ -139,7 +139,7 @@ impl FilePreviewer { /// The size of the buffer used to read the file in bytes. /// This ends up being the max size of partial previews. -const PARTIAL_BUFREAD_SIZE: usize = 16 * 1024; +const PARTIAL_BUFREAD_SIZE: usize = 64 * 1024; pub fn try_preview( entry: &entry::Entry, @@ -188,7 +188,7 @@ pub fn try_preview( .collect::>(), syntax_set, syntax_theme, - cached_lines, + &cached_lines, ) { let total_lines = content.total_lines(); let preview = Arc::new(Preview::new( @@ -210,7 +210,7 @@ pub fn try_preview( .collect::>(), syntax_set, syntax_theme, - cached_lines, + &cached_lines, ) { let total_lines = content.total_lines(); let preview = Arc::new(Preview::new( @@ -250,7 +250,7 @@ fn compute_highlighted_text_preview( lines: &[String], syntax_set: &SyntaxSet, syntax_theme: &Theme, - previous_lines: Option, + previous_lines: &Option, ) -> Option { debug!( "Computing highlights in the background for {:?}", diff --git a/crates/television-utils/Cargo.toml b/crates/television-utils/Cargo.toml index ae45317..77c4a3b 100644 --- a/crates/television-utils/Cargo.toml +++ b/crates/television-utils/Cargo.toml @@ -24,7 +24,7 @@ tokio = { workspace = true } ignore = "0.4.23" bat = { version = "0.24.0", default-features = false, features = [ - "regex-fancy", + "regex-onig", ] } gag = "1.0.0" diff --git a/crates/television-utils/src/syntax.rs b/crates/television-utils/src/syntax.rs index 31b4ec7..f18e1b3 100644 --- a/crates/television-utils/src/syntax.rs +++ b/crates/television-utils/src/syntax.rs @@ -9,6 +9,7 @@ use syntect::highlighting::{ use syntect::parsing::{ParseState, ScopeStack, SyntaxReference, SyntaxSet}; use tracing::warn; +#[allow(dead_code)] #[derive(Debug, Clone)] pub struct HighlightingState { parse_state: ParseState, @@ -48,6 +49,7 @@ impl<'a> LineHighlighter<'a> { } } + #[allow(dead_code)] pub fn from_state( state: HighlightingState, theme: &'a Theme, @@ -119,15 +121,15 @@ fn set_syntax_set<'a>( #[derive(Debug, Clone)] pub struct HighlightedLines { pub lines: Vec>, - pub state: Option, + //pub state: Option, } impl HighlightedLines { pub fn new( lines: Vec>, - state: Option, + _state: &Option, ) -> Self { - Self { lines, state } + Self { lines, /*state*/ } } } @@ -136,23 +138,26 @@ pub fn compute_highlights_incremental( lines: &[String], syntax_set: &SyntaxSet, syntax_theme: &Theme, - cached_lines: Option, + _cached_lines: &Option, ) -> Result { let mut highlighted_lines: Vec<_>; let mut highlighter: LineHighlighter; - if let Some(HighlightedLines { - lines: c_lines, - state: Some(s), - }) = cached_lines - { - highlighter = LineHighlighter::from_state(s, syntax_theme); - highlighted_lines = c_lines; - } else { - let syntax = set_syntax_set(syntax_set, file_path); - highlighter = LineHighlighter::new(syntax, syntax_theme); - highlighted_lines = Vec::new(); - }; + //if let Some(HighlightedLines { + // lines: c_lines, + // state: Some(s), + //}) = cached_lines + //{ + // highlighter = LineHighlighter::from_state(s, syntax_theme); + // highlighted_lines = c_lines; + //} else { + // let syntax = set_syntax_set(syntax_set, file_path); + // highlighter = LineHighlighter::new(syntax, syntax_theme); + // highlighted_lines = Vec::new(); + //}; + let syntax = set_syntax_set(syntax_set, file_path); + highlighter = LineHighlighter::new(syntax, syntax_theme); + highlighted_lines = Vec::with_capacity(lines.len()); for line in lines { let hl_regions = highlighter.highlight_line(line, syntax_set)?; @@ -166,7 +171,7 @@ pub fn compute_highlights_incremental( Ok(HighlightedLines::new( highlighted_lines, - Some(HighlightingState::new( + &Some(HighlightingState::new( highlighter.parse_state.clone(), highlighter.highlight_state.clone(), )),