on master help sign in
Bump to syntect 5.0.0 to e.g. start lazy-loading syntaxes (#2181)

* Bump to syntect 5.0.0 to e.g. start lazy-loading themes Closes #915 Closes #951 Closes #1846 Closes #1854 * Typo fix formated -> formatted * Update CHANGELOG.md

commit7334ab45422882686212ed31df2d95c02e7585f1 authorMartin Nordholts <enselic@gmail.com> dateSat 7 May 2022, 13:43 (5 years ago) parent719248f
13 files changed+56−21
CHANGELOG.md+11−1 Cargo.lock+4−9 Cargo.toml+2−3 assets/acknowledgements.bin assets/syntaxes.bin assets/themes.bin src/assets.rs+14−4 src/error.rs+4−1 src/printer.rs+1−1 tests/syntax-tests/highlighted/Svelte/App.svelte+5−1 tests/syntax-tests/highlighted/Vue/example.vue+5 tests/syntax-tests/source/Svelte/App.svelte+5−1 tests/syntax-tests/source/Vue/example.vue+5
CHANGELOG.md+11−1
@@ -5,15 +5,21 @@
55- Correctly render tab stops in --show-all, see #2038 (@Synthetica9)
66- Add a `--style=default` option, less verbose than `full`, see #2061 (@IsaacHorvath)
77- Enable BusyBox less as pager, see #2162 (@nfisher1226)
8+- File extensions are now matched without taking case into account. See #1854, #2181 (@Enselic)
89
910## Bugfixes
1011
1112- Bump `regex` dependency from 1.5.4 to 1.5.5 to fix [CVE-2022-24713](https://blog.rust-lang.org/2022/03/08/cve-2022-24713.html), see #2145, #2139 (@Enselic)
13+- `bat` no longer crashes when encountering files that references missing syntaxes. See #915, #2181 (@Enselic)
14+
15+## Performance
16+
17+- Skip syntax highlighting on long lines (> 16384 chars) to help improve performance. See #2165 (@keith-hall)
18+- Vastly improve startup time by lazy-loading syntaxes via syntect 5.0.0. This makes bat display small files ~75% faster than before. See #951, #2181 (@Enselic)
1219
1320## Other
1421
1522- Include info about custom assets in `--diagnostics` if used. See #2107, #2144 (@Enselic)
16−- Skip syntax highlighting on long lines (> 16384 chars) to help improve performance. See #2165 (@keith-hall)
1723
1824## Syntaxes
1925
@@ -28,6 +34,10 @@
2834## `bat` as a library
2935
3036- Allow configuration of `show_nonprintable` with `PrettyPrinter`, see #2142
37+- The binary format of syntaxes.bin has been changed due to syntaxes now being lazy-loaded via syntect 5.0.0. See #2181 (@Enselic)
38+- Mark `bat::error::Error` enum as `#[non_exhaustive]` to allow adding new variants without future semver breakage. See #2181 (@Enselic)
39+- Change `Error::SyntectError(syntect::LoadingError)` to `Error::SyntectError(syntect::Error)`. See #2181 (@Enselic)
40+- Add `Error::SyntectLoadingError(syntect::LoadingError)` enum variant. See #2181 (@Enselic)
3141
3242# v0.20.0
3343
Cargo.lock+4−9
@@ -580,12 +580,6 @@ version = "1.4.0"
580580source = "registry+https://github.com/rust-lang/crates.io-index"
581581checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
582582
583−[[package]]
584−name = "lazycell"
585−version = "1.3.0"
586−source = "registry+https://github.com/rust-lang/crates.io-index"
587−checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
588−
589583[[package]]
590584name = "libc"
591585version = "0.2.125"
@@ -1071,9 +1065,9 @@ dependencies = [
10711065
10721066[[package]]
10731067name = "syntect"
1074−version = "4.6.0"
1068+version = "5.0.0"
10751069source = "registry+https://github.com/rust-lang/crates.io-index"
1076−checksum = "8b20815bbe80ee0be06e6957450a841185fcf690fe0178f14d77a05ce2caa031"
1070+checksum = "c6c454c27d9d7d9a84c7803aaa3c50cd088d2906fe3c6e42da3209aa623576a8"
10771071dependencies = [
10781072 "bincode",
10791073 "bitflags",
@@ -1081,13 +1075,14 @@ dependencies = [
10811075 "flate2",
10821076 "fnv",
10831077 "lazy_static",
1084− "lazycell",
1078+ "once_cell",
10851079 "onig",
10861080 "plist",
10871081 "regex-syntax",
10881082 "serde",
10891083 "serde_derive",
10901084 "serde_json",
1085+ "thiserror",
10911086 "walkdir",
10921087 "yaml-rust",
10931088]
Cargo.toml+2−3
@@ -33,8 +33,7 @@ minimal-application = [
3333]
3434git = ["git2"] # Support indicating git modifications
3535paging = ["shell-words", "grep-cli"] # Support applying a pager on the output
36−# Add "syntect/plist-load" when https://github.com/trishume/syntect/pull/345 reaches us
37−build-assets = ["syntect/yaml-load", "syntect/dump-create", "regex", "walkdir"]
36+build-assets = ["syntect/yaml-load", "syntect/plist-load", "regex", "walkdir"]
3837
3938# You need to use one of these if you depend on bat as a library:
4039regex-onig = ["syntect/regex-onig"] # Use the "oniguruma" regex engine
@@ -73,7 +72,7 @@ optional = true
7372default-features = false
7473
7574[dependencies.syntect]
76−version = "4.6.0"
75+version = "5.0.0"
7776default-features = false
7877features = ["parsing"]
7978
assets/acknowledgements.bin

Binary file not shown.

assets/syntaxes.bin

Binary file not shown.

assets/themes.bin

Binary file not shown.

src/assets.rs+14−4
@@ -43,8 +43,9 @@ pub struct SyntaxReferenceInSet<'a> {
4343 pub syntax_set: &'a SyntaxSet,
4444}
4545
46−/// Compress for size of ~700 kB instead of ~4600 kB at the cost of ~30% longer deserialization time
47−pub(crate) const COMPRESS_SYNTAXES: bool = true;
46+/// Lazy-loaded syntaxes are already compressed, and we don't want to compress
47+/// already compressed data.
48+pub(crate) const COMPRESS_SYNTAXES: bool = false;
4849
4950/// We don't want to compress our [LazyThemeSet] since the lazy-loaded themes
5051/// within it are already compressed, and compressing another time just makes
@@ -581,13 +582,22 @@ mod tests {
581582 }
582583
583584 #[test]
584− fn syntax_detection_is_case_sensitive() {
585+ fn syntax_detection_is_case_insensitive() {
585586 let mut test = SyntaxDetectionTest::new();
586587
587− assert_ne!(test.syntax_for_file("README.MD"), "Markdown");
588+ assert_eq!(test.syntax_for_file("README.md"), "Markdown");
589+ assert_eq!(test.syntax_for_file("README.mD"), "Markdown");
590+ assert_eq!(test.syntax_for_file("README.Md"), "Markdown");
591+ assert_eq!(test.syntax_for_file("README.MD"), "Markdown");
592+
593+ // Adding a mapping for "MD" in addition to "md" should not break the mapping
588594 test.syntax_mapping
589595 .insert("*.MD", MappingTarget::MapTo("Markdown"))
590596 .ok();
597+
598+ assert_eq!(test.syntax_for_file("README.md"), "Markdown");
599+ assert_eq!(test.syntax_for_file("README.mD"), "Markdown");
600+ assert_eq!(test.syntax_for_file("README.Md"), "Markdown");
591601 assert_eq!(test.syntax_for_file("README.MD"), "Markdown");
592602 }
593603
src/error.rs+4−1
@@ -2,11 +2,14 @@ use std::io::Write;
22use thiserror::Error;
33
44#[derive(Error, Debug)]
5+#[non_exhaustive]
56pub enum Error {
67 #[error(transparent)]
78 Io(#[from] ::std::io::Error),
89 #[error(transparent)]
9− SyntectError(#[from] ::syntect::LoadingError),
10+ SyntectError(#[from] ::syntect::Error),
11+ #[error(transparent)]
12+ SyntectLoadingError(#[from] ::syntect::LoadingError),
1013 #[error(transparent)]
1114 ParseIntError(#[from] ::std::num::ParseIntError),
1215 #[error(transparent)]
src/printer.rs+1−1
@@ -453,7 +453,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
453453
454454 let mut highlighted_line = highlighter_from_set
455455 .highlighter
456− .highlight(for_highlighting, highlighter_from_set.syntax_set);
456+ .highlight_line(for_highlighting, highlighter_from_set.syntax_set)?;
457457
458458 if too_long {
459459 highlighted_line[0].1 = &line;
tests/syntax-tests/highlighted/Svelte/App.svelte+5−1
@@ -27,9 +27,13 @@
2727</script>
2828
2929<script type="text/livescript">
30− // This block is a regression test for a bat panic when a LiveScript syntax definition is missing
30+ // This block is a regression test for a bat panic when a LiveScript syntax definition is missing
3131</script>
3232
33+<style lang="text/postcss">
34+ /* This block is a regression test for a bat panic when a PostCSS syntax definition is missing */
35+</style>
36+
3337<style>
3438 main {
3539 position: relative;
tests/syntax-tests/highlighted/Vue/example.vue+5
@@ -8,6 +8,11 @@
88 </div>
99</template>
1010
11+<template lang='pug'>
12+ #container.col
13+ p This shall be formatted as Plain Text as long as a Pug syntax definition is missing
14+</template>
15+
1116<script>
1217import AppHeader from "@/components/AppHeader";
1318import AppLoadingIndicator from "@/components/AppLoadingIndicator";
tests/syntax-tests/source/Svelte/App.svelte+5−1
@@ -27,9 +27,13 @@
2727</script>
2828
2929<script type="text/livescript">
30− // This block is a regression test for a bat panic when a LiveScript syntax definition is missing
30+ // This block is a regression test for a bat panic when a LiveScript syntax definition is missing
3131</script>
3232
33+<style lang="text/postcss">
34+ /* This block is a regression test for a bat panic when a PostCSS syntax definition is missing */
35+</style>
36+
3337<style>
3438 main {
3539 position: relative;
tests/syntax-tests/source/Vue/example.vue+5
@@ -8,6 +8,11 @@
88 </div>
99</template>
1010
11+<template lang='pug'>
12+ #container.col
13+ p This shall be formatted as Plain Text as long as a Pug syntax definition is missing
14+</template>
15+
1116<script>
1217import AppHeader from "@/components/AppHeader";
1318import AppLoadingIndicator from "@/components/AppLoadingIndicator";