Skip to content

Commit

Permalink
fix(syntect): switch back to oniguruma while investigating parsing is…
Browse files Browse the repository at this point in the history
…sues
  • Loading branch information
alexpasmantier committed Jan 20, 2025
1 parent 3d97394 commit a9ad15a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 51 deletions.
49 changes: 23 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
8 changes: 4 additions & 4 deletions crates/television-previewers/src/previewers/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -188,7 +188,7 @@ pub fn try_preview(
.collect::<Vec<_>>(),
syntax_set,
syntax_theme,
cached_lines,
&cached_lines,
) {
let total_lines = content.total_lines();
let preview = Arc::new(Preview::new(
Expand All @@ -210,7 +210,7 @@ pub fn try_preview(
.collect::<Vec<_>>(),
syntax_set,
syntax_theme,
cached_lines,
&cached_lines,
) {
let total_lines = content.total_lines();
let preview = Arc::new(Preview::new(
Expand Down Expand Up @@ -250,7 +250,7 @@ fn compute_highlighted_text_preview(
lines: &[String],
syntax_set: &SyntaxSet,
syntax_theme: &Theme,
previous_lines: Option<HighlightedLines>,
previous_lines: &Option<HighlightedLines>,
) -> Option<PreviewContent> {
debug!(
"Computing highlights in the background for {:?}",
Expand Down
2 changes: 1 addition & 1 deletion crates/television-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
39 changes: 22 additions & 17 deletions crates/television-utils/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,6 +49,7 @@ impl<'a> LineHighlighter<'a> {
}
}

#[allow(dead_code)]
pub fn from_state(
state: HighlightingState,
theme: &'a Theme,
Expand Down Expand Up @@ -119,15 +121,15 @@ fn set_syntax_set<'a>(
#[derive(Debug, Clone)]
pub struct HighlightedLines {
pub lines: Vec<Vec<(Style, String)>>,
pub state: Option<HighlightingState>,
//pub state: Option<HighlightingState>,
}

impl HighlightedLines {
pub fn new(
lines: Vec<Vec<(Style, String)>>,
state: Option<HighlightingState>,
_state: &Option<HighlightingState>,
) -> Self {
Self { lines, state }
Self { lines, /*state*/ }
}
}

Expand All @@ -136,23 +138,26 @@ pub fn compute_highlights_incremental(
lines: &[String],
syntax_set: &SyntaxSet,
syntax_theme: &Theme,
cached_lines: Option<HighlightedLines>,
_cached_lines: &Option<HighlightedLines>,
) -> Result<HighlightedLines> {
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)?;
Expand All @@ -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(),
)),
Expand Down

0 comments on commit a9ad15a

Please sign in to comment.