mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-06 03:25:23 +00:00
fix(syntect): switch back to oniguruma while investigating parsing issues (#292)
Temp fix for #289
This commit is contained in:
parent
3d973947ab
commit
8bbebf7e57
49
Cargo.lock
generated
49
Cargo.lock
generated
@ -223,21 +223,6 @@ dependencies = [
|
|||||||
"serde",
|
"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]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@ -964,16 +949,6 @@ dependencies = [
|
|||||||
"once_cell",
|
"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]]
|
[[package]]
|
||||||
name = "faster-hex"
|
name = "faster-hex"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@ -2235,6 +2210,28 @@ version = "1.20.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
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]]
|
[[package]]
|
||||||
name = "oorandom"
|
name = "oorandom"
|
||||||
version = "11.1.4"
|
version = "11.1.4"
|
||||||
@ -2982,10 +2979,10 @@ checksum = "874dcfa363995604333cf947ae9f751ca3af4522c60886774c4963943b4746b1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"fancy-regex",
|
|
||||||
"flate2",
|
"flate2",
|
||||||
"fnv",
|
"fnv",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"onig",
|
||||||
"plist",
|
"plist",
|
||||||
"regex-syntax 0.8.5",
|
"regex-syntax 0.8.5",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -63,9 +63,7 @@ tokio = { version = "1.41.1", features = ["full"] }
|
|||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] }
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] }
|
||||||
rustc-hash = "2.1.0"
|
rustc-hash = "2.1.0"
|
||||||
syntect = { version = "5.2.0", default-features = false, features = [
|
syntect = { version = "5.2.0" }
|
||||||
"default-fancy",
|
|
||||||
] }
|
|
||||||
unicode-width = "0.2.0"
|
unicode-width = "0.2.0"
|
||||||
clap = { version = "4.5.20", features = ["derive", "cargo", "string"] }
|
clap = { version = "4.5.20", features = ["derive", "cargo", "string"] }
|
||||||
serde = { version = "1.0.214", features = ["derive"] }
|
serde = { version = "1.0.214", features = ["derive"] }
|
||||||
|
@ -139,7 +139,7 @@ impl FilePreviewer {
|
|||||||
|
|
||||||
/// The size of the buffer used to read the file in bytes.
|
/// The size of the buffer used to read the file in bytes.
|
||||||
/// This ends up being the max size of partial previews.
|
/// 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(
|
pub fn try_preview(
|
||||||
entry: &entry::Entry,
|
entry: &entry::Entry,
|
||||||
@ -188,7 +188,7 @@ pub fn try_preview(
|
|||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
syntax_set,
|
syntax_set,
|
||||||
syntax_theme,
|
syntax_theme,
|
||||||
cached_lines,
|
&cached_lines,
|
||||||
) {
|
) {
|
||||||
let total_lines = content.total_lines();
|
let total_lines = content.total_lines();
|
||||||
let preview = Arc::new(Preview::new(
|
let preview = Arc::new(Preview::new(
|
||||||
@ -210,7 +210,7 @@ pub fn try_preview(
|
|||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
syntax_set,
|
syntax_set,
|
||||||
syntax_theme,
|
syntax_theme,
|
||||||
cached_lines,
|
&cached_lines,
|
||||||
) {
|
) {
|
||||||
let total_lines = content.total_lines();
|
let total_lines = content.total_lines();
|
||||||
let preview = Arc::new(Preview::new(
|
let preview = Arc::new(Preview::new(
|
||||||
@ -250,7 +250,7 @@ fn compute_highlighted_text_preview(
|
|||||||
lines: &[String],
|
lines: &[String],
|
||||||
syntax_set: &SyntaxSet,
|
syntax_set: &SyntaxSet,
|
||||||
syntax_theme: &Theme,
|
syntax_theme: &Theme,
|
||||||
previous_lines: Option<HighlightedLines>,
|
previous_lines: &Option<HighlightedLines>,
|
||||||
) -> Option<PreviewContent> {
|
) -> Option<PreviewContent> {
|
||||||
debug!(
|
debug!(
|
||||||
"Computing highlights in the background for {:?}",
|
"Computing highlights in the background for {:?}",
|
||||||
|
@ -24,7 +24,7 @@ tokio = { workspace = true }
|
|||||||
|
|
||||||
ignore = "0.4.23"
|
ignore = "0.4.23"
|
||||||
bat = { version = "0.24.0", default-features = false, features = [
|
bat = { version = "0.24.0", default-features = false, features = [
|
||||||
"regex-fancy",
|
"regex-onig",
|
||||||
] }
|
] }
|
||||||
gag = "1.0.0"
|
gag = "1.0.0"
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ use syntect::highlighting::{
|
|||||||
use syntect::parsing::{ParseState, ScopeStack, SyntaxReference, SyntaxSet};
|
use syntect::parsing::{ParseState, ScopeStack, SyntaxReference, SyntaxSet};
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HighlightingState {
|
pub struct HighlightingState {
|
||||||
parse_state: ParseState,
|
parse_state: ParseState,
|
||||||
@ -48,6 +49,7 @@ impl<'a> LineHighlighter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn from_state(
|
pub fn from_state(
|
||||||
state: HighlightingState,
|
state: HighlightingState,
|
||||||
theme: &'a Theme,
|
theme: &'a Theme,
|
||||||
@ -119,15 +121,15 @@ fn set_syntax_set<'a>(
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HighlightedLines {
|
pub struct HighlightedLines {
|
||||||
pub lines: Vec<Vec<(Style, String)>>,
|
pub lines: Vec<Vec<(Style, String)>>,
|
||||||
pub state: Option<HighlightingState>,
|
//pub state: Option<HighlightingState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HighlightedLines {
|
impl HighlightedLines {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
lines: Vec<Vec<(Style, String)>>,
|
lines: Vec<Vec<(Style, String)>>,
|
||||||
state: Option<HighlightingState>,
|
_state: &Option<HighlightingState>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { lines, state }
|
Self { lines, /*state*/ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,23 +138,26 @@ pub fn compute_highlights_incremental(
|
|||||||
lines: &[String],
|
lines: &[String],
|
||||||
syntax_set: &SyntaxSet,
|
syntax_set: &SyntaxSet,
|
||||||
syntax_theme: &Theme,
|
syntax_theme: &Theme,
|
||||||
cached_lines: Option<HighlightedLines>,
|
_cached_lines: &Option<HighlightedLines>,
|
||||||
) -> Result<HighlightedLines> {
|
) -> Result<HighlightedLines> {
|
||||||
let mut highlighted_lines: Vec<_>;
|
let mut highlighted_lines: Vec<_>;
|
||||||
let mut highlighter: LineHighlighter;
|
let mut highlighter: LineHighlighter;
|
||||||
|
|
||||||
if let Some(HighlightedLines {
|
//if let Some(HighlightedLines {
|
||||||
lines: c_lines,
|
// lines: c_lines,
|
||||||
state: Some(s),
|
// state: Some(s),
|
||||||
}) = cached_lines
|
//}) = cached_lines
|
||||||
{
|
//{
|
||||||
highlighter = LineHighlighter::from_state(s, syntax_theme);
|
// highlighter = LineHighlighter::from_state(s, syntax_theme);
|
||||||
highlighted_lines = c_lines;
|
// highlighted_lines = c_lines;
|
||||||
} else {
|
//} else {
|
||||||
let syntax = set_syntax_set(syntax_set, file_path);
|
// let syntax = set_syntax_set(syntax_set, file_path);
|
||||||
highlighter = LineHighlighter::new(syntax, syntax_theme);
|
// highlighter = LineHighlighter::new(syntax, syntax_theme);
|
||||||
highlighted_lines = Vec::new();
|
// 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 {
|
for line in lines {
|
||||||
let hl_regions = highlighter.highlight_line(line, syntax_set)?;
|
let hl_regions = highlighter.highlight_line(line, syntax_set)?;
|
||||||
@ -166,7 +171,7 @@ pub fn compute_highlights_incremental(
|
|||||||
|
|
||||||
Ok(HighlightedLines::new(
|
Ok(HighlightedLines::new(
|
||||||
highlighted_lines,
|
highlighted_lines,
|
||||||
Some(HighlightingState::new(
|
&Some(HighlightingState::new(
|
||||||
highlighter.parse_state.clone(),
|
highlighter.parse_state.clone(),
|
||||||
highlighter.highlight_state.clone(),
|
highlighter.highlight_state.clone(),
|
||||||
)),
|
)),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user