Commit Graph

137 Commits

Author SHA1 Message Date
Martin Nordholts a3ea798246
Credit syntax definition and theme authors with new `--acknowledgements` option (#1971)
The text that is printed is generated when building assets, by analyzing LICENSE
and NOTICE files that comes with syntaxes and themes.

We take this opportunity to also add a NOTICE file as defined by Apache License 2.0.
2021-12-11 14:00:45 +01:00
Martin Nordholts e250da8aaa Run `cargo clippy --fix --all-targets --all-features` with Rust 1.57
Clippy in the newly released Rust 1.57 found some new lints. Conveniently, all
of them were fixable with `--fix`.
2021-12-08 08:45:04 +01:00
Martin Nordholts 7fceb4878f
Load themes lazily for improved startup time (#1969)
This is for #951. Syntax lazy-loading will come later and have a much bigger
impact, but lazy-loading of themes does not have negligible impact.
2021-12-06 09:14:15 +01:00
Martin Nordholts dd0925a946 Replace lazycell with once_cell
We started to use lazycell because syntect already used it. But syntect has
changed to use once_cell. So we should also do that to prepare for using the
upcoming version of syntect.
2021-11-22 22:03:03 +01:00
Martin Nordholts d7671fa8e3 Remove the code related to minimal_syntaxes.bin
To get fast startup, syntect will instead start to lazy-load syntaxes. See
https://github.com/trishume/syntect/pull/393 and discussions in linked PRs.
2021-11-22 20:42:01 +01:00
Martin Nordholts e79b07bf5e HighlightingAssets::get_syntax_set(): Make private
Was forgotten in aefc8fd824.
2021-11-22 20:42:01 +01:00
Bojan Đurđević d6ed5e6746
Support for ignored-suffix CLI arguments (#1892) 2021-11-19 17:05:23 +01:00
cbolgiano 7fe4fdf33d
Introduce MapExtensionToUnknown MappingTarget (#1889)
Co-authored-by: Martin Nordholts <enselic@gmail.com>
2021-10-25 17:59:12 +02:00
Martin Nordholts aefc8fd824 src/printer.rs: Simplify Plain Text fallback code
By forwarding the task to find the `Plain Text` syntax to `assets`. Not only does
the code become simpler; we also get rid of a call to `self.get_syntax_set()`
which is beneficial to the long term goal of replacing `syntaxes.bin` with
`minimal_syntaxes.bin`.

Note that the use of `.expect()` is not a regression in error handling. It was
previously hidden in `.find_syntax_plain_text()`.
2021-09-29 17:54:45 +02:00
Martin Nordholts 405a80f3ee HighlightingAssets: Turn get_syntax_for_path() into public API 2021-09-28 07:26:20 +02:00
Martin Nordholts ad98d35a48 HighlightingAssets: Implement get_syntax_for_file_name() with get_syntax_for_path()
We can do this since the file_name() of a file_name is file_name.
2021-09-28 07:26:20 +02:00
Martin Nordholts b69ab219d7 HighlightingAssets: Extract get_syntax_for_path() method
To make the code easier to refactor further.
2021-09-28 07:26:20 +02:00
Martin Nordholts dc8225f682 src/assets.rs: Extract helper method OpenedInput::path() 2021-09-27 08:00:58 +02:00
Martin Nordholts 0994f3783f HighlightingAssets: Move common get_extension_syntax() code into find_syntax_by_extension() 2021-09-22 06:03:24 +02:00
Martin Nordholts 974dec38e3 HighlightingAssets: Inline find_syntax_by_file_name() and find_syntax_by_file_name_extension()
There is no benefit to keeping separate functions.
2021-09-22 06:03:24 +02:00
Martin Nordholts a0c363647f src/assets.rs: Use /// not // for COMPRESS_* consts 2021-09-18 07:05:04 +02:00
Martin Nordholts d989224a8a HighlightingAssets: Inline absolute_path
Its name is confusing, because it does not always hold an absolute path. Get rid
of this problem by inlining it.
2021-09-18 06:19:52 +02:00
Martin Nordholts 82f439e715 HighlightingAssets: Simplify absolute_path with .map_or_else() 2021-09-18 06:19:52 +02:00
Martin Nordholts b034879eae HighlightingAssets: No need for both path and path_str 2021-09-18 06:19:52 +02:00
Martin Nordholts 9ed9a6fc3d
Simplify HighlightingAssets::get_syntax() first_line logic (#1852)
And make self.get_first_line_syntax() be called lazily.
2021-09-16 17:01:12 +02:00
Martin Nordholts e84b702309
Extract some private submodules from 'bat::assets' (#1850) 2021-09-15 07:59:33 +02:00
Martin Nordholts 6226eba52a HighlightingAssets: Add find_syntax_by_extension() helper 2021-09-14 07:38:36 +02:00
Martin Nordholts 9e0ea06435 HighlightingAssets: Add find_syntax_by_name() helper 2021-09-14 07:38:36 +02:00
Marcin Puc 7956485e37 Improve iterator usage 2021-09-12 15:50:10 +02:00
Marcin Puc 372e42f350 Reduce nesting in if blocks by short circuiting 2021-09-12 15:50:10 +02:00
Martin Nordholts 9124271eaf
Load independent and minimal syntax sets when using --language (#1787)
This significantly speeds up the startup time of bat, since only a single
linked SyntaxDefinition is loaded for each file. The size increase of the
binary is just ~400 kB.

In order for startup time to be improved, the --language arg must be used, and
it must match one of the following names:

"Plain Text", "ActionScript", "AppleScript", "Batch File", "NAnt Build File",
"C#", "C", "CSS", "D", "Diff", "Erlang", "Go", "Haskell", "JSON", "Java
Properties", "BibTeX", "LaTeX Log", "TeX", "Lisp", "Lua", "MATLAB", "Pascal",
"R", "Regular Expression", "Rust", "SQL", "Scala", "Tcl", "XML", "YAML", "Apache
Conf", "ARM Assembly", "Assembly (x86_64)", "CMakeCache", "Comma Separated
Values", "Cabal", "CoffeeScript", "CpuInfo", "Dart Analysis Output", "Dart",
"Dockerfile", "DotENV", "F#", "Friendly Interactive Shell (fish)", "Fortran
(Fixed Form)", "Fortran (Modern)", "Fortran Namelist", "fstab", "GLSL",
"GraphQL", "Groff/troff", "group", "hosts", "INI", "Jinja2", "jsonnet",
"Kotlin", "Less", "LLVM", "Lean", "MemInfo", "Nim", "Ninja", "Nix", "passwd",
"PowerShell", "Protocol Buffer (TEXT)", "Puppet", "Rego", "resolv", "Robot
Framework", "SML", "Strace", "Stylus", "Solidity", "Vyper", "Swift",
"SystemVerilog", "TOML", "Terraform", "TypeScript", "TypeScriptReact",
"Verilog", "VimL", "Zig", "gnuplot", "log", "requirements.txt", "Highlight
non-printables", "Private Key", "varlink"

Later commits will improve startup time for more code paths.

* fix some typos and misspellings

* CHANGELOG.md: Add Performance section (preliminary)

* Add a CHANGELOG.md entry for this PR
2021-09-09 20:52:33 +02:00
Martin Nordholts 87978e7755
Make asset compression optional at compile time (#1825)
This will be needed to later support zero-copy deserialization of independent
syntax sets, but is interesting and useful on its own.

Instead of deferring serialization and deserialization to syntect, we implement it
ourselves in the same way, but make compression optional.
2021-09-07 17:21:48 +02:00
Ville Skyttä 7c41bd72da assets: add Debian ucf backups to ignored suffixes
Refs https://manpages.debian.org/bullseye/ucf/ucf.1.en.html
2021-08-29 19:55:00 +02:00
Martin Nordholts 19c3e82abf
Replace deprecated 'error-chain' with 'thiserror' (#1820)
We can't use #[from] on Error::Msg(String) because String does not implement Error.
(Which it shouldn't; see e.g. https://internals.rust-lang.org/t/impl-error-for-string/8881.)
So we implement From manually for Error::Msg, since our current code was written
in that way for error-chain.
2021-08-26 13:12:21 +02:00
Martin Nordholts f1c0fd7343
Don't take a HighlightingAssets detour to build assets (#1802)
Move code to build assets to its own file. That results in better modularity and flexibility.

It also allows us to simplify HighlightingAssets a lot, since it will now always
be initialized with a SerializedSyntaxSet.
2021-08-24 07:58:03 +02:00
Martin Nordholts ed09f90e5e Fix all lints that are new with Rust 1.54
They are all of the following type:
https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
2021-08-19 07:19:12 +02:00
Martin Nordholts 25fa577cd0 Make 'build-assets' an optional capability for application
Also structure features a bit more clever to avoid duplication of
feature dependency declarations.
2021-08-17 10:58:21 +02:00
Martin Nordholts deddc81426 src/assets.rs: Use ThemeSet::new() instead of BTreeMap::new() 2021-08-17 10:58:21 +02:00
Martin Nordholts d8b813c0bf
When returning a SyntaxReference, also return the SyntaxSet that contains it (#1776)
To improve startup performance, we will later load smaller `SyntaxSet`s instead
of one giant one. However, the current API assumes only one `SyntaxSet` is ever used,
and that that implicitly is the `SyntaxSet` from which returned `SyntaxReference`s
comes.

This change changes the API to reflect that `SyntaxSet` and `SyntaxReference`
are tightly coupled, and enables the use of several `SyntaxSet`.
2021-08-08 08:26:17 +02:00
Martin Nordholts 47d955a2ab Add code for analyzing dependencies between syntaxes
And also to generate independent SyntaxSets. This will later be used
to improve bat startup time.
2021-08-07 22:38:39 +02:00
Martin Nordholts 0331d28ee4 cargo fmt 2021-08-05 20:21:18 +02:00
Keith Hall 3b020fd95a
Merge pull request #1771 from sharkdp/warn_when_missing_contexts
Warn when building assets from files if some referenced contexts are missing
2021-08-02 22:55:37 +03:00
Keith Hall 50e1c6074f Warn when building assets from files if some referenced contexts are missing 2021-08-02 21:22:01 +03:00
Martin Nordholts a610987ef7 assets::tests: Add get_syntax_name() helper
And instead of taking a get_syntax_set() detour to return a
name that represents "no syntax", return such a string directly.
2021-08-02 19:23:14 +02:00
Martin Nordholts ffdf349a96 HighlightingAssets: Encapsulate theme_set behind a getter
Mainly to prepare for potential lazy-loading in the future to
improve startup performance. Like we did for syntax_set.
2021-07-29 21:30:03 +02:00
Martin Nordholts 6acec2c074 Reduce startup time in loop-through mode with 80%-90%
Instead of 100 ms - 50 ms, startup takes 10 ms - 5 ms.

HighlightingAssets::get_syntax_set() is never called when e.g. piping the bat
output to a file (see Config::loop_through), so by loading the SyntaxSet only
when needed, we radically improve startup time when it is not needed.
2021-07-29 20:36:05 +02:00
Martin Nordholts 1bac3750df HighlightingAssets: Move out fn get_integrated_*set() to module scope
They are just a way to get access to data embedded in the binary, so they don't
conceptually belong inside HighlightingAssets.

This has the nice side effect of getting HighlightingAssets::from_cache() and
::from_binary(), that are highly related, next to each other.
2021-07-29 20:36:05 +02:00
Martin Nordholts a81009607a HighlightingAssets: Make .syntaxes() and syntax_for_file_name() failable
Or rather, introduce new versions of these methods and deprecate the old ones.

This is preparation to enable robust and user-friendly support for lazy-loading.
With lazy-loading, we don't know if the SyntaxSet is valid until after we try to
use it, so wherever we try to use it, we need to return a Result. See discussion
about panics in #1747.
2021-07-29 08:26:18 +02:00
Martin Nordholts c0e09662b4 HighlightingAssets::get_extension_syntax(): Split up into smaller methods
To make the code easier to understand and change.
2021-07-28 08:42:18 +02:00
Martin Nordholts ccf4563573 Make loading of cached assets closer in performance to integrated assets
Using BufReader makes sense for large files, but assets are never large enough
to require buffering. It is significantly faster to load the file contents in
one go, so let's do that instead.

Closes #1753
2021-07-27 14:53:59 +02:00
Martin Nordholts f6fc826dc6 HighlightingAssets: Introduce private fn new() helper
It already now reduces code duplication slightly, but will become even more
useful in the future when we add more complicated logic such as lazy-loading.
2021-07-20 06:34:32 +02:00
Martin Nordholts 375d55aa5d HighlightingAssets: Encapsulate syntax_set behind a getter
Since we only modify `pub(crate)` items, the stable bat-as-a-library API is not
affected.

This takes us one step closer to making SyntaxSet lazy-loaded, which in turn
takes us one step closer to solving #951.
2021-07-19 05:27:12 +02:00
Martin Nordholts 6ef2bb3283 De-duplicate some themes.bin and syntaxes.bin related code 2021-07-15 16:22:35 +02:00
David Peter 33c11d64f0 Run cargo fmt 2021-07-13 08:19:59 +02:00
David Peter 21338ed789 Abort ignored filename suffix stripping early on unworkable filenames 2021-07-09 06:34:11 +02:00