Commit graph

28 commits

Author SHA1 Message Date
Andrew Hlynskyi
e966c5ad5b fix: use SIGINT instead of stdin for interruption to don't mess up piped commands 2023-05-02 10:43:46 +03:00
Patrick Thomson
f5d1c0b860 Support @module as a highlight key.
Some languages have the notion of modules, and to represent those
we've started to use a `@module` tag, as discussed in
https://github.com/elixir-lang/tree-sitter-elixir/issues/15.
Because historically we've used the constructor highlight color for
modules in JS/Ruby, it's defined to map to the same color.
2021-12-15 17:33:57 -05:00
Amin Yahyaabadi
8a5620ce15 Use serde's derive feature 2021-10-05 02:38:18 -05:00
Douglas Creager
e841fcfa1b cli: Extract CLI configuration into separate crate
This patch adds the `tree-sitter-config` crate, which manages
tree-sitter's configuration file.  This new setup allows different
components to define their own serializable configuration types, instead
of having to create a single monolithic configuration type.  But the
configuration itself is still stored in a single JSON file.

Before, the default location for the configuration file was
`~/.tree-sitter/config.json`.  This patch updates the default location
to follow the XDG Base Directory spec (or other relevant platform-
specific spec).  So on Linux, for instance, the new default location is
`~/.config/tree-sitter/config.json`.  We will look in the new location
_first_, and fall back on reading from the legacy location if we can't
find anything.
2021-06-10 10:21:22 -04:00
Douglas Creager
66c30648c2 rust: Extract runtime language detection into separate crate
This patch adds a new `tree-sitter-loader` crate, which holds the CLI's
logic for finding and building local grammar definitions at runtime.
This allows other command-line tools to use this logic too!
2021-06-09 17:42:30 -04:00
Douglas Creager
d2d01e77e3 cli: Use anyhow and thiserror for errors
This patch updates the CLI to use anyhow and thiserror for error
management.  The main feature that our custom `Error` type was providing
was a _list_ of messages, which would allow us to annotate "lower-level"
errors with more contextual information.  This is exactly what's
provided by anyhow's `Context` trait.

(This is setup work for a future PR that will pull the `config` and
`loader` modules out into separate crates; by using `anyhow` we wouldn't
have to deal with a circular dependency between with the new crates.)
2021-06-09 16:17:23 -04:00
Andrew Hlynskyi
148680b3b9 fix: assertion in highlight::tests::test_parse_style test 2021-03-17 15:52:21 +02:00
lazytype
0c4ea79e2e Slightly improve highlight test hygiene 2021-03-01 14:13:02 -05:00
lazytype
5de649b7aa Support highlighting in truecolor, falling back to the closest xterm color if the terminal does not support it
Fixes #758
2021-02-28 16:22:45 -05:00
Max Brunsfeld
b972a7158d Tweak cancellation logic for CLI commands
In 'parse' and 'highlight' cancel on stdin if stdin is a tty.
2020-10-23 12:15:44 -07:00
Max Brunsfeld
783c087aec tags: Handle cancellation 2020-03-25 11:26:52 -07:00
Max Brunsfeld
709ddfebe9 docs: Add explanation of syntax highlighting configuration for CLI 2020-02-21 11:39:27 -08:00
Max Brunsfeld
360b188644 cli: Handle 'underline' styling when highlighting w/ HTML output 2020-02-20 09:35:46 -08:00
Max Brunsfeld
6dbfbaed07 Start work on a system for testing syntax highlighting 2019-12-05 09:45:54 -08:00
Max Brunsfeld
084406148b Tweak highlight name matching semantics, add doc comments 2019-10-17 12:03:34 -07:00
Max Brunsfeld
7c8216c692 highlight: Handle injections correctly, using a separate query cursor 2019-10-14 12:30:22 -07:00
Max Brunsfeld
f4903578f8 Start reimplementing highlight crate with tree queries 2019-10-14 12:30:22 -07:00
Max Brunsfeld
62538ed410 highlight iterator: Return byte offset ranges instead of string slices
Refs #443
2019-09-04 17:29:31 -07:00
Max Brunsfeld
bd466febb4 highlight: Fix panic when cancelled before parsing a nested document 2019-07-16 14:34:24 -07:00
Max Brunsfeld
d274e81d0d Overhaul CLI error handling to allow multiple levels of context 2019-05-30 16:52:55 -07:00
Max Brunsfeld
a7d02e7276 Add support for highlight properties that track local variables 2019-05-09 20:34:34 -07:00
Max Brunsfeld
d78ac581f3 Rename scope -> highlight in highlighting property sheets
We need to use the word `scope` for a different purpose: tracking local 
scopes.
2019-05-09 09:42:40 -07:00
Max Brunsfeld
abcac40f2d cli: Add a --time flag to highlight subcommand 2019-03-13 15:52:29 -07:00
Max Brunsfeld
1bad6dc41e Add ~/.tree-sitter/config.json file, init-config command
Right now this is just used for two things:
* Specifying folders for locarting parsers to use with `tree-sitter 
parse` and `tree-sitter highlight`
* Specifying colors to use for `tree-sitter-highlight`
2019-02-25 12:33:24 -08:00
Max Brunsfeld
e239aa8229 highlight: don't include scope in ScopeEnd events
When there are embedded documents, multiple scopes can start or
end at the same position. Previously, there was no guarantee that
the ScopeEnd events would always occur in the reverse order of the
ScopeStart events. The easiest way to avoid exposing inconsistency
is to not surface the scopes being ended.
2019-02-20 16:45:51 -08:00
Max Brunsfeld
2ee5cbbc1d highlight: take callback parameters by value 2019-02-20 10:27:08 -08:00
Max Brunsfeld
a46515b80f Replace LanguageRegistry trait with a simple callback 2019-02-19 17:07:12 -08:00
Max Brunsfeld
e89b6b2402 Add a highlight subcommand 2019-02-19 12:32:03 -08:00