Skip to content

Commit

Permalink
Bump to syntect 5.0.0 to e.g. start lazy-loading themes
Browse files Browse the repository at this point in the history
  • Loading branch information
Enselic committed Apr 28, 2022
1 parent 3ae0533 commit 9c487fb
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 19 deletions.
14 changes: 4 additions & 10 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
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,8 @@ optional = true
default-features = false

[dependencies.syntect]
version = "4.6.0"
git = "https://github.com/trishume/syntect.git"
branch = "master"
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
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
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
Expand Up @@ -447,7 +447,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
};
highlighter_from_set
.highlighter
.highlight(&line, highlighter_from_set.syntax_set)
.highlight_line(&line, highlighter_from_set.syntax_set)?
};

if out_of_range {
Expand Down

0 comments on commit 9c487fb

Please sign in to comment.