Commit graph

124 commits

Author SHA1 Message Date
Michael Davis
3e499d675a
CLI: Re-use highlight cancellation flag for HTML highlights
The `html` highlight function created its own cancellation flag which
conflicts with the Ctrl-c handler set up in the CLI's `main` block
for `tree-sitter highlight`. We can re-use the cancellation flag from
that block to avoid a panic that happens when using `tree-sitter
highlight -H <file>`

    thread 'main' panicked at 'Error setting Ctrl-C handler: MultipleHandlers', cli/src/util.rs:31:6

This change also aligns the parameters that `highlight::ansi` and
`highlight::html` take.
2023-08-02 08:56:26 -05:00
Andrew Hlynskyi
a2f834d846 More error contexts + conv panics to errors with context 2023-07-30 21:16:45 +03:00
Patrick Thomson
cb58bc593f
Add --check flag to tree-sitter highlight.
Recently I've been pulling a lot of grammars into GitHub's highlighting backend,
replacing legacy language support with tree-sitter highlighting queries.
Our backend systems have a standard set of highlight captures we expect, very
similar to the standard tagging captures we expect. Though end-user applications
are free to choose whatever tagging nomenclature they want, I think it's nice to
include a checking stage that will help us ensure that we know whether a capture
might be recognized or not. It will also help us figure out where we need to
expand our standard set of captures (see #1539).
2023-07-15 20:49:03 -04:00
Amaan Qureshi
9d669abac4 feat: add encoding flag and automatically check if a file might be utf-16 2023-07-10 16:43:35 -04:00
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
Max Brunsfeld
ff2436a6f8 Add --row-range, --quiet, and --time flags to query subcommand 2023-02-14 14:41:25 -08:00
Max Brunsfeld
97fd990822 Add --dot flag to parse subcommand, for printing tree as DOT graph 2023-02-13 12:33:34 -08:00
Andrew Hlynskyi
c7d431b53e Add setting TREE_SITTER_DEBUG in the test subcommand
Were asked in #1218
2023-01-10 10:47:24 +02:00
Andrew Hlynskyi
108d0ecede loader: add TREE_SITTER_LIBDIR; cli: add --libdir to tree-sitter generate
Closes #1336
2023-01-06 10:28:47 +02:00
Andrew Hlynskyi
5088781ef9 cli: add -b, --build flags for tree-sitter generate 2023-01-06 10:28:47 +02:00
Andrew Hlynskyi
ad45f5cd2c Remove unused no-minimize arg for the generate command 2023-01-06 10:28:47 +02:00
Max Brunsfeld
e2fe380a08 Generate parsers with ABI version 14 by default 2022-09-02 12:31:29 -07:00
Max Brunsfeld
5eb0a3090f
Merge pull request #1547 from the-mikedavis/md-test-tags
test tags queries in 'tree-sitter test'
2022-02-24 15:22:15 -08:00
Max Brunsfeld
516fd6f6de Add --abi flag to generate command, generate version 13 by default 2022-01-17 14:50:47 -08:00
Michael Davis
067f742ad3
run test_tag in 'tree-sitter test' when tags test dir exists 2021-12-18 11:07:18 -06:00
Jostein Kjønigsen
d0559ca43f Fix whitespace issues when using paths-file. 2021-10-25 23:51:01 +02:00
Andrew Hlynskyi
16470bc0b1 chore(cli): Rename all internal web_ui stuff to playground 2021-09-22 04:28:08 +03:00
Andrew Hlynskyi
62d79b80e1 feat(cli): add a flag to compile a parser in debug mode with -O0 C/C++ compiler flag 2021-09-13 13:48:02 +03:00
Kolja Lampe
99243ddaf2 Correct quiet description for playground 2021-08-06 01:58:24 +03:00
Max Brunsfeld
59cd1c3962
Merge pull request #1235 from ahlinc/feat/cli-help-messages
feat(cli): Add a lot of help messages for CLI options
2021-07-19 11:32:32 -07:00
Andrew Hlynskyi
b4208ee307 feat(cli): Add a lot of help messages for CLI options 2021-07-03 16:14:57 +03:00
Andrew Hlynskyi
bc94c0cc2f fix(cli): fix theme key loading from config.json, closes #1232 2021-07-03 03:38:24 +03:00
Andrew Hlynskyi
60f0953b65 feat(cli): Set TREE_SITTER_DEBUG env var on 'tree-sitter parse -d' 2021-06-30 18:51:43 +03:00
Andrew Hlynskyi
202a37f1a1 chore(cli): Use DeriveDisplayOrder Clap's setting
To show sub commands in the defined order that looks more accurate
and have more meaning for sub commands use order.
2021-06-27 03:37:56 +03:00
Andrew Hlynskyi
2e2b239c42 fix(cli): Don't silently overwrite existing config file 2021-06-27 03:15:35 +03:00
Vladimir Panteleev
5adf7bdcde
cli/src/main.rs: Fix panic with empty file list to parse
E.g.: tree-sitter parse --paths /dev/null
2021-06-26 18:11:30 +00:00
Andrew Hlynskyi
bd0e60240e fix(cli): Change -h -> -H for the highlight subcommand to don't clash with the help flag 2021-06-24 12:09:00 +03:00
Andrew Hlynskyi
650ee94800 fix(cli): disable help subcommand, -h, --help are enough 2021-06-24 12:04:12 +03:00
Andrew Hlynskyi
1220ec3852 feat(cli): Rename web-ui -> playground with fallback alias 2021-06-24 12:04:12 +03:00
Andrew Hlynskyi
80ee33b073 feat(cli): Add short aliases for frequent subcommands 2021-06-24 11:55:50 +03:00
Andrew Hlynskyi
04badf8a8e feat(cli): Enable clap colored help 2021-06-24 11:55:50 +03:00
Andrew Hlynskyi
421815a68d feat(cli): Make more clearer sub command selection 2021-06-23 10:51:55 +03:00
Andrew Hlynskyi
318b00e437 fix(cli): Don't print 'Error:' prefix 2021-06-14 10:46:39 +03:00
Douglas Creager
b44270efab cli: Missing config file shouldn't be an error
Just fall back on the default values for each configuration option.
2021-06-10 10:22:20 -04: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
75da247317 cli: Ignore BrokenPipe errors again
With the change to anyhow in the previous commit, we stopped ignoring
BrokenPipe errors.  Now we do again, not as a core part of our error
type, but as part of the `main` functions reaction to any error that
occurs.
2021-06-09 16:17:23 -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
Max Brunsfeld
22620dee73
Merge pull request #1135 from ahlinc/fix/panic-on-broken-pipe
fix(cli): Panic on broken pipe
2021-06-07 11:15:37 -07:00
Andrew Hlynskyi
ce2bb561b4 chore(cli): Panic on broken pipe; review fixes 2021-06-07 21:11:49 +03:00
Andrew Hlynskyi
65dc922944 fix(cli): Panic on broken pipe for: 'tree-sitter parse ... | head'
Introduce a concept of ignored errors when the Error wrapper struct
contains None instead of Vec of String messages.
2021-05-31 18:34:09 +03:00
Max Brunsfeld
d72771a19f Make ::set_{byte,point}_range methods take a Range
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
2021-05-28 14:21:11 -07:00
Andrew Hlynskyi
3c0152a331 chore(fmt): Apply 'cargo fmt' to the whole code base 2021-05-19 23:21:43 +03:00
pbug90
9d04efda94 update wording 2021-03-13 19:55:04 +01:00
pbug90
9a833d165e update test command filter help 2021-03-13 19:53:10 +01:00
pbug90
858160172f update test command help outputs 2021-03-13 19:45:55 +01:00
Max Brunsfeld
8e894ff3f1 Add --no-bindings flag to generate subcommand 2021-03-08 12:01:45 -08:00
Yijun Yu
9e08712773 Add --xml option to save the parsed code into XML, using node.start_byte() and node.end_byte() 2021-01-04 22:07:38 +00:00
Max Brunsfeld
026231e93d Merge branch 'master' into HEAD 2020-12-03 09:44:33 -08:00
Patrick Thomson
938eae8536 Merge remote-tracking branch 'origin/master' into query-testy 2020-10-27 09:16:58 -04:00