Commit graph

716 commits

Author SHA1 Message Date
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
9d77561c43
Merge pull request #1150 from ahlinc/fix/panic-on-broken-pipe
Stylistic fix for #1135 - Panic on broken pipe
2021-06-08 11:21:04 -07:00
Andrew Hlynskyi
8bbf27b82b chore(cli): Panic on broken pipe; stylistic fix 2021-06-08 21:04:26 +03: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
dbdda25224 fix(cli): Panic on broken pipe; use conditional match arm with ErrorKind 2021-06-07 20:22:12 +03:00
Max Brunsfeld
f3ea60e23f Merge branch 'master' into query-cursor-api 2021-06-02 11:51:26 -07:00
Douglas Creager
cd96552448 query: Allow configurable match limit
The default is now a whopping 64K matches, which "should be enough for
everyone".  You can use the new `ts_query_cursor_set_match_limit`
function to set this to a lower limit, such as the previous default of
32.
2021-06-02 11:30:55 -04: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
Max Brunsfeld
851f55afce Report non-rooted matches that intersect cursor's range restriction
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
2021-05-28 11:58:38 -07:00
Max Brunsfeld
919e9745a6 Add ts_tree_cursor_goto_first_child_for_point function
This function (and the similar `ts_tree_cursor_goto_first_child_for_byte`)
allows you to efficiently seek the tree cursor to a given position,
exploiting the tree's internal balancing, without having to visit
all of the preceding siblings of each node.
2021-05-27 12:30:19 -07:00
Max Brunsfeld
fda35894d4 Stop matching new patterns past the end of QueryCursor's range
This restores the original signatures of the `set_byte_range` and
`set_point_range` functions. Now, the QueryCursor will properly report
matches that intersect, but are not fully contained by its range.

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
2021-05-25 18:02:35 -07:00
Max Brunsfeld
f597cc6a75 Preserve matches that contain the QueryCursor's start byte
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
2021-05-25 13:06:24 -07:00
Max Brunsfeld
a61f25bc58 Add APIs for advancing a QueryCursor to an arbitrary position 2021-05-24 21:07:59 -07:00
Douglas Creager
78010722a4 query: Allow unlimited pending matches
Well, not completely unlimited — we're still using a 16-bit counter to
keep track of them.  But we longer have a static maximum of 32 pending
matches when executing a query.
2021-05-24 11:02:58 -04:00
Max Brunsfeld
8c3d1466ec Allow QueryCursor's text callback to return an iterator 2021-05-23 21:05:26 -07:00
Andrew Hlynskyi
0ae70289ae fix(cli): Correct fallback on docker compilation for all platforms, fixes #1124 2021-05-23 17:04:34 +03:00
Niranjan Hasabnis
c0e2b43d34 Fixing Rust formatting issue 2021-05-21 15:43:10 +00:00
Niranjan Hasabnis
c31acb8fec Changing API name; Adding unit test and Rust bindings 2021-05-21 01:50:10 +00:00
Max Brunsfeld
8d8690538e 0.19.5 2021-05-20 15:02:46 -07:00
Andrew Hlynskyi
3c0152a331 chore(fmt): Apply 'cargo fmt' to the whole code base 2021-05-19 23:21:43 +03:00
Markus F.X.J. Oberhumer
cc519b3121 cli: Improve const-correctness of the generated parsers (part 2 of 2).
This is a follow-up to my previous commit 1badd131f9 .

I've made this an extra patch as it requires a minor
API change in <tree_sitter/parser.h>.

This commit moves the remaining generated tables into
the read-only segment.

Before:
  $ for f in bash c cpp go html java javascript jsdoc json php python ruby rust; do \
       gcc -o $f.o -O2 -Ilib/include -c test/fixtures/grammars/$f/src/parser.c; \
    done
  $ size --totals *.o
      text    data     bss     dec     hex filename
   5353477   24472       0 5377949  520f9d (TOTALS)

After:
  $ for f in bash c cpp go html java javascript jsdoc json php python ruby rust; do \
       gcc -o $f.o -O2 -Ilib/include -c test/fixtures/grammars/$f/src/parser.c; \
    done
  $ size --totals *.o
   5378147       0       0 5378147  521063 (TOTALS)
2021-05-19 12:49:57 +02:00
Max Brunsfeld
fe5a29a1c6
Merge pull request #1081 from ahlinc/feat/fail-ci-on-compiler-warnings
feat: Fail CI on compiler warnings
2021-05-01 09:26:44 -07:00
Andrew Hlynskyi
b856f7e1bd Remove unneeded dead_code annotations 2021-04-30 06:55:00 +03:00
Douglas Creager
108679ffdc
Merge pull request #1076 from tree-sitter/cli-match-limit-warning
cli: Warn about queries that exceed match limit
2021-04-28 15:37:43 -04:00
Douglas Creager
850007718a cli: Warn about queries that exceed match limit 2021-04-27 09:38:43 -04:00
Markus F.X.J. Oberhumer
1badd131f9 cli: Improve const-correctness of the generated parsers.
This moves most of the generated tables from the data segment into
the text segment (read-only memory) so that it can be shared between
different processes.

As a bonus side effect we can also remove all casts in the generated parsers.

Before:
  size --totals target/scratch/*.so
      text    data     bss     dec     hex filename
    853623 4684560    2160 5540343  5489f7 (TOTALS)

After:
  size --totals target/scratch/*.so
      text    data     bss     dec     hex filename
   5472086   68616     480 5541182  548d3e (TOTALS)
2021-04-27 09:22:18 +02:00
Max Brunsfeld
347b3eb243
Merge pull request #1069 from ahlinc/fix/package-json-generation
package.json generation improvements
2021-04-22 14:27:36 -07:00
Andrew Hlynskyi
b57266cbb8 test(binding_rust): Use some redundancy to trigger more clear comliler error on the master 2021-04-22 21:00:58 +03:00
Andrew Hlynskyi
2d9a2a1855 test(binding_rust): test query captures/matches lifetime is separate from nodes lifetime 2021-04-22 21:00:58 +03:00
Andrew Hlynskyi
7aa538dd97 fix(cli): use dashed language name in generated package.json and Cargo.toml files 2021-04-22 16:29:48 +03:00
Andrew Hlynskyi
9416f975d3 fix(cli): set actual cli version in generated package.json 2021-04-22 16:29:48 +03:00
an-kumar
aabe6100d0
Update generated Cargo.toml's tree-sitter dependency
tree-sitter 0.19.0 bumped the language version from 12 to 13. `npm install tree-sitter-cli` gets a recent version of tree-sitter, which generates languages with language version 13. However, the Cargo.toml generated from `tree-sitter generate` still has a an old tree-sitter as a dependency. This causes the rust bindings to not work out of the box, as the tree-sitter library expects language version 12.

It would be nice to add a test for this in CI.  `tree-sitter generate` already creates a test for the rust binding, and that test fails out of the box due to the language mismatch.
2021-04-09 10:59:51 -07:00
Amin Yahyaabadi
90c9a3a2f8 Refactor get_emcc_path and use PathBuf 2021-04-04 21:16:53 -05:00
Amin Yahyaabadi
919eab023f Fix build-wasm on Windows 2021-04-04 19:07:16 -05:00
Max Brunsfeld
c3eb5daa31 Include has_preceding_inherited_fields in Item's hash impl 2021-03-27 10:08:24 -07:00
Max Brunsfeld
72143b17ff Fix handling of queries with field names at the roots of patterns
Fixes #1018
2021-03-27 09:36:13 -07:00
Max Brunsfeld
89e1157a29 Fix handling of repetitions in query analysis
Fixes #1007
2021-03-19 11:00:31 -07:00
Max Brunsfeld
810d10fa26 0.19.4 2021-03-18 10:36:05 -07:00
Max Brunsfeld
a440e11197
Merge pull request #996 from ahlinc/fix/test-precondition
fix: assertion in highlight::tests::test_parse_style test
2021-03-18 10:25:02 -07:00
Andrew Hlynskyi
192f51324e Added more test for byte and point ranges 2021-03-17 19:11:20 +02:00
Andrew Hlynskyi
148680b3b9 fix: assertion in highlight::tests::test_parse_style test 2021-03-17 15:52:21 +02: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
Jonas Hübotter
5e9c3c69e2 fix type of prec in dsl 2021-03-13 13:10:12 +01:00
Max Brunsfeld
bc0ef5f373 Add negated field patterns to queries 2021-03-12 14:38:02 -08:00
Max Brunsfeld
08d17e33bd Fix unused import warning on windows 2021-03-11 16:43:20 -08:00
Max Brunsfeld
a40045a419 When editing, properly invalidate trees that depend on get_column 2021-03-11 14:46:13 -08:00