Commit Graph

710 Commits

Author SHA1 Message Date
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
b69ab219d7 HighlightingAssets: Extract get_syntax_for_path() method
To make the code easier to refactor further.
2021-09-28 07:26:20 +02:00
dc8225f682 src/assets.rs: Extract helper method OpenedInput::path() 2021-09-27 08:00:58 +02:00
9d9b266f54 build_assets.rs: Enable dump of syntax dependencies to Graphviz dot file 2021-09-24 20:07:55 +02:00
b9d01c1a61 build_assets.rs: Ignore explicit contexts when tracking dependencies 2021-09-24 20:07:55 +02:00
122cae7902 build_assets.rs: Sort first to make dependencies.dedup() actually useful 2021-09-24 20:07:55 +02:00
5143f3ad43 build_assets.rs: Add code to track dependents of each syntax
This information is useful when you want to build several SyntaxSets, but
without having to duplicate SyntaxDefinitions. For example:

"Rust" has no dependencies. But "Markdown" depends on "Rust". With the data
structures this code adds, we know that "Rust" is a dependent syntax for
"Markdown", and can construct a SyntaxSet that takes that into account.

Note that code has a temporary environment flag to ignore any information about
dependents when constructing SyntaxSets. Code that makes use of the new data
structure will be added later.
2021-09-22 09:14:19 +02:00
a6dc25a216 build_assets.rs: Make OtherSyntaxLookup come before SyntaxToDependencies
It makes more sense structurally when we later introduce SyntaxToDependents.
2021-09-22 09:14:19 +02:00
f04d2a9d6a build_assets.rs: Rename 'Dependency' to 'OtherSyntax'
So that we later can use it for not only information about dependencies, but
also for information about dependents.
2021-09-22 09:14:19 +02:00
eb3b3b9f8d src/printer.rs: Add HighlighterFromSet helper
The main benefit is that we get rid of a call to `assets.get_syntax_set()`,
which in turn makes it easier to later get rid of `syntaxes.bin`.
2021-09-22 06:11:32 +02:00
0994f3783f HighlightingAssets: Move common get_extension_syntax() code into find_syntax_by_extension() 2021-09-22 06:03:24 +02:00
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
a0c363647f src/assets.rs: Use /// not // for COMPRESS_* consts 2021-09-18 07:05:04 +02:00
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
82f439e715 HighlightingAssets: Simplify absolute_path with .map_or_else() 2021-09-18 06:19:52 +02:00
b034879eae HighlightingAssets: No need for both path and path_str 2021-09-18 06:19:52 +02:00
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
e84b702309 Extract some private submodules from 'bat::assets' (#1850) 2021-09-15 07:59:33 +02:00
6226eba52a HighlightingAssets: Add find_syntax_by_extension() helper 2021-09-14 07:38:36 +02:00
9e0ea06435 HighlightingAssets: Add find_syntax_by_name() helper 2021-09-14 07:38:36 +02:00
863d9cacd0 Add various other code refactorings 2021-09-12 15:50:10 +02:00
4baa346aae Use deref coercion to simplify some argument passing 2021-09-12 15:50:10 +02:00
7956485e37 Improve iterator usage 2021-09-12 15:50:10 +02:00
372e42f350 Reduce nesting in if blocks by short circuiting 2021-09-12 15:50:10 +02:00
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
156dec2737 Add context to .ino configuration
This allows a user to search the README or the entire repository for "Arduino" to find the necessary configuration.
2021-09-07 20:21:12 +02:00
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
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
27fa55d274 src/build_assets.rs: Refactor into smaller functions (#1822)
To make the code easier to work with.
2021-08-27 09:56:20 +02:00
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
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
c86a179412 PR comments addressed for line range +delta syntax 2021-08-23 19:55:41 +02:00
0748783404 Support for line range plus syntax 2021-08-23 19:55:41 +02:00
ba8a694314 Add LANG and LC_ALL to --diagnostics output
To make it easier to debug problems like #1806 in the future.
2021-08-22 18:31:39 +02:00
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
f5c1cb2dff Run 'cargo fmt' 2021-08-19 07:18:05 +02:00
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
deddc81426 src/assets.rs: Use ThemeSet::new() instead of BTreeMap::new() 2021-08-17 10:58:21 +02:00
bf78288e9e feat(config): added recognition of $BAT_CONFIG_DIR 2021-08-14 22:02:58 +02:00
89217e0d58 Make --no-paging and --no-pager work again 2021-08-09 13:37:56 +02:00
905902d811 bin: Allow to build without bugreport 2021-08-08 11:18:26 +02:00
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
5236ed135e Fix typo in unreachable!(..) message for --wrap 2021-08-08 06:40:18 +02:00
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
8ecd23eab4 Make --style docs reflect that 'full' is default
Closes #1742
2021-08-07 09:51:36 +02:00
0331d28ee4 cargo fmt 2021-08-05 20:21:18 +02:00
28eca6a2be Use assert!(..) instead of assert_eq!(true, ..)
This fixes all of these lint warnings:
https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison

They only appear in recent versions of clippy. Not on our MSRV.
2021-08-02 22:35:50 +02:00
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
50e1c6074f Warn when building assets from files if some referenced contexts are missing 2021-08-02 21:22:01 +03:00
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