Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to syntect 5.0.0 to e.g. start lazy-loading syntaxes #2181

Merged
merged 4 commits into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
- Correctly render tab stops in --show-all, see #2038 (@Synthetica9)
- Add a `--style=default` option, less verbose than `full`, see #2061 (@IsaacHorvath)
- Enable BusyBox less as pager, see #2162 (@nfisher1226)
- File extensions are now matched without taking case into account. See #1854, #2181 (@Enselic)

## Bugfixes

- 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)
- `bat` no longer crashes when encountering files that references missing syntaxes. See #915, #2181 (@Enselic)

## Performance

- Skip syntax highlighting on long lines (> 16384 chars) to help improve performance. See #2165 (@keith-hall)
- 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)

## Other

- Include info about custom assets in `--diagnostics` if used. See #2107, #2144 (@Enselic)
- Skip syntax highlighting on long lines (> 16384 chars) to help improve performance. See #2165 (@keith-hall)

## Syntaxes

Expand All @@ -28,6 +34,10 @@
## `bat` as a library

- Allow configuration of `show_nonprintable` with `PrettyPrinter`, see #2142
- The binary format of syntaxes.bin has been changed due to syntaxes now being lazy-loaded via syntect 5.0.0. See #2181 (@Enselic)
- Mark `bat::error::Error` enum as `#[non_exhaustive]` to allow adding new variants without future semver breakage. See #2181 (@Enselic)
- Change `Error::SyntectError(syntect::LoadingError)` to `Error::SyntectError(syntect::Error)`. See #2181 (@Enselic)
- Add `Error::SyntectLoadingError(syntect::LoadingError)` enum variant. See #2181 (@Enselic)

# v0.20.0

Expand Down
13 changes: 4 additions & 9 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ minimal-application = [
]
git = ["git2"] # Support indicating git modifications
paging = ["shell-words", "grep-cli"] # Support applying a pager on the output
# Add "syntect/plist-load" when https://github.com/trishume/syntect/pull/345 reaches us
build-assets = ["syntect/yaml-load", "syntect/dump-create", "regex", "walkdir"]
build-assets = ["syntect/yaml-load", "syntect/plist-load", "regex", "walkdir"]

# You need to use one of these if you depend on bat as a library:
regex-onig = ["syntect/regex-onig"] # Use the "oniguruma" regex engine
Expand Down Expand Up @@ -73,7 +72,7 @@ optional = true
default-features = false

[dependencies.syntect]
version = "4.6.0"
version = "5.0.0"
default-features = false
features = ["parsing"]

Expand Down
Binary file modified assets/acknowledgements.bin
Binary file not shown.
Binary file modified assets/syntaxes.bin
Binary file not shown.
Binary file modified assets/themes.bin
Binary file not shown.
18 changes: 14 additions & 4 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ pub struct SyntaxReferenceInSet<'a> {
pub syntax_set: &'a SyntaxSet,
}

/// Compress for size of ~700 kB instead of ~4600 kB at the cost of ~30% longer deserialization time
pub(crate) const COMPRESS_SYNTAXES: bool = true;
/// Lazy-loaded syntaxes are already compressed, and we don't want to compress
/// already compressed data.
pub(crate) const COMPRESS_SYNTAXES: bool = false;

/// We don't want to compress our [LazyThemeSet] since the lazy-loaded themes
/// within it are already compressed, and compressing another time just makes
Expand Down Expand Up @@ -581,13 +582,22 @@ mod tests {
}

#[test]
fn syntax_detection_is_case_sensitive() {
fn syntax_detection_is_case_insensitive() {
let mut test = SyntaxDetectionTest::new();

assert_ne!(test.syntax_for_file("README.MD"), "Markdown");
assert_eq!(test.syntax_for_file("README.md"), "Markdown");
assert_eq!(test.syntax_for_file("README.mD"), "Markdown");
assert_eq!(test.syntax_for_file("README.Md"), "Markdown");
assert_eq!(test.syntax_for_file("README.MD"), "Markdown");

// Adding a mapping for "MD" in addition to "md" should not break the mapping
test.syntax_mapping
.insert("*.MD", MappingTarget::MapTo("Markdown"))
.ok();

assert_eq!(test.syntax_for_file("README.md"), "Markdown");
assert_eq!(test.syntax_for_file("README.mD"), "Markdown");
assert_eq!(test.syntax_for_file("README.Md"), "Markdown");
assert_eq!(test.syntax_for_file("README.MD"), "Markdown");
}

Expand Down
5 changes: 4 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ use std::io::Write;
use thiserror::Error;

#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
Io(#[from] ::std::io::Error),
#[error(transparent)]
SyntectError(#[from] ::syntect::LoadingError),
SyntectError(#[from] ::syntect::Error),
#[error(transparent)]
SyntectLoadingError(#[from] ::syntect::LoadingError),
#[error(transparent)]
ParseIntError(#[from] ::std::num::ParseIntError),
#[error(transparent)]
Expand Down
2 changes: 1 addition & 1 deletion src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ impl<'a> Printer for InteractivePrinter<'a> {

let mut highlighted_line = highlighter_from_set
.highlighter
.highlight(for_highlighting, highlighter_from_set.syntax_set);
.highlight_line(for_highlighting, highlighter_from_set.syntax_set)?;

if too_long {
highlighted_line[0].1 = &line;
Expand Down
6 changes: 5 additions & 1 deletion tests/syntax-tests/highlighted/Svelte/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
</script>

<script type="text/livescript">
 // This block is a regression test for a bat panic when a LiveScript syntax definition is missing
 // This block is a regression test for a bat panic when a LiveScript syntax definition is missing
</script>

<style lang="text/postcss">
 /* This block is a regression test for a bat panic when a PostCSS syntax definition is missing */
</style>

<style>
 main {
 position: relative;
Expand Down
5 changes: 5 additions & 0 deletions tests/syntax-tests/highlighted/Vue/example.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
 </div>
</template>

<template lang='pug'>
 #container.col
 p This shall be formatted as Plain Text as long as a Pug syntax definition is missing
</template>

<script>
import AppHeader from "@/components/AppHeader";
import AppLoadingIndicator from "@/components/AppLoadingIndicator";
Expand Down
6 changes: 5 additions & 1 deletion tests/syntax-tests/source/Svelte/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
</script>

<script type="text/livescript">
// This block is a regression test for a bat panic when a LiveScript syntax definition is missing
// This block is a regression test for a bat panic when a LiveScript syntax definition is missing
</script>

<style lang="text/postcss">
/* This block is a regression test for a bat panic when a PostCSS syntax definition is missing */
</style>

<style>
main {
position: relative;
Expand Down
5 changes: 5 additions & 0 deletions tests/syntax-tests/source/Vue/example.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
</div>
</template>

<template lang='pug'>
#container.col
p This shall be formatted as Plain Text as long as a Pug syntax definition is missing
</template>

<script>
import AppHeader from "@/components/AppHeader";
import AppLoadingIndicator from "@/components/AppLoadingIndicator";
Expand Down