Commit graph

166 commits

Author SHA1 Message Date
Max Brunsfeld 0e2af0d8d1
Allow using Tree-sitter rust lib in multi-threaded web apps compiled to wasm32-unknown-unknown (#5851)
* feat(wasm): make syntax trees sendable

* test(wasm): transfer trees across workers

* test(wasm): use JSON grammar for tree transfer

* test(wasm): edit trees across workers

* test(wasm): share dlmalloc with tree-sitter

* test(wasm): simplify worker tree exchange

* test(wasm): drive tree exchange from Rust

* test(wasm): split sendable-tree xtask

* test(wasm): generalize Rust web fixture

* test(wasm): exercise parallel Rust tree access

* fix(wasm): use Rust global allocator for C core

* test(wasm): use default Rust allocator

* feat(wasm): support external scanners in Rust web apps

* Simplify example further, add a readme

* Regenerate wasm-stdlib

* Fix wasm_stdlib check script

* Vendor the Wasm standard library subset

* Test Unicode Ruby scanner behavior in Wasm

* Make Wasm tree languages instance-aware

* Test multi-threaded use of queries in wasm32-unknown

* Refactor reference-counted language storage

* Check ABI version compat before loading rest of language

* 🎨 Remove redundant #ifdef block

* Reject unsupported Rust Wasm builds on 0.26
2026-08-14 17:05:42 -07:00
Will Lillis 7bf4a10995 fix(lib)!: make lookahead iterator exhaustion sticky and retain its language
Track the iterator's phase so exhaustion is sticky, and gate the symbol name on
it, so `NULL` means "not positioned on a symbol".

`ts_lookahead_iterator_new` was also the only language consuming constructor
that did not `ts_language_copy`, so an iterator outliving a wasm language read
freed memory. Retain in `_new` and `_reset`, release in `_delete`.

Previously:
- `ts_lookahead_iterator__next` left a small parse state's cursor one past its
group end, so re-advancing an exhausted iterator resumed returning `true` and
walked through the rest of `ts_small_parse_table` and off the end of it.

- `ts_lookahead_iterator_current_symbol_name` returned `NULL` only when the
exhausted symbol index happened to fall outside the names table, so a grammar
with aliases returned a real but wrong name instead.
2026-08-14 00:13:54 -04:00
Jason Boatman 18cc71a6d9 feat(lib): add state to missing nodes.
This allows them to return possible missing values from a `LookaheadIterator`.
2026-08-12 23:39:44 -04:00
Michael Davis 9991c0f46f Add ts_query_copy for cloning queries
This allows duplicating a query so that it can be modified by using
disable_capture or disable_pattern, without re-parsing the query. The
new `ts_query_copy` creates a deep copy of the entire query object.

A motivation for this is tags.scm code navigation queries. You might
want to have one version of the compiled query capture only definitions
and the other only capture references, since references are much much
more common than definitions in a typical codebase. Instead of
re-parsing and analyzing the query and then calling
`ts_query_disable_capture`, we can clone the built query all-at-once and
then disable captures / patterns.
2026-06-27 17:53:13 -04:00
Will Lillis 17125cefa6 fix(lib): update doc comment for ts_parser_parse 2026-05-30 04:11:53 -04:00
Will Lillis 8d737aa238 docs: note zero point unbounded behavior in query functions 2026-04-30 04:28:59 -04:00
Will Lillis 0535b0ca37 fix(lib): correct various typos 2026-03-28 05:23:10 -04:00
Will Lillis 08d676b417 fix(lib): document invariants that must be upheld for TSInputEdit 2026-03-22 23:17:01 -04:00
Bertie Wheen 39f407e3ff
fix(lib): correct ts_parser_parse docstring (#5295) 2026-02-04 00:49:54 -05:00
Piotr Osiewicz c0b1710f8a Add containing range APIs to query cursor
Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
Co-authored-by: John Tur <john-tur@outlook.com>
Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
Co-authored-by: Will Lillis <will.lillis24@gmail.com>
2025-12-03 18:06:16 -05:00
Amaan Qureshi a69367f739 feat: add API for editing points and ranges 2025-09-19 17:40:26 -04:00
Amaan Qureshi 821cf797f2 feat(lib)!: remove deprecated functions 2025-09-12 02:50:30 -04:00
ObserverOfTime b75196bb81 feat(c): rename DecodeFunction to TSDecodeFunction
Keep a typedef for backwards compatibility until ABI 16.
2025-09-01 03:17:44 -04:00
ObserverOfTime 88e0b4cea4 docs: change WASM/wasm to Wasm
That is the official capitalisation.
2025-08-21 09:56:32 +03:00
NOT XVilka a00fab7dc4
fix(lib): remove duplicate TSLanguageMetadata typedef (#4268) 2025-03-06 14:14:25 -08:00
Allan Clements cda634a1c4 feat: add error information in the progress callback
This allows users to bail parsing if an error was *definitely* detected
using the progress callback, as all possible stack versions have a
non-zero error cost.

Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
2025-01-25 02:47:39 -05:00
Amaan Qureshi 8bb1448a6f feat: add the semantic version to TSLanguage, and expose an API for retrieving it 2025-01-25 01:14:30 -05:00
Amaan Qureshi 344a88c4fb feat(lib)!: remove ts_node_child_containing_descendant
It was marked deprecated in 0.24
2025-01-12 22:11:30 -05:00
Amaan Qureshi f941277a9d docs(lib): improve documentation on ts_tree_get_changed_ranges and ts_query_cursor_set_{byte,point}_range 2025-01-12 14:56:22 -05:00
Amaan Qureshi 95fd37ecf8 docs: add information about the scoping of cursors 2025-01-11 02:33:48 -05:00
Riley Bruins 19482834bd feat: add Supertype API
Introduces a new function that takes in a supertype symbol and returns
all associated subtypes. Can be used by query.c to give better errors
for invalid subtypes, as well as downstream applications like the query
LSP to give better diagnostics.
2025-01-05 00:14:09 -05:00
Amaan Qureshi 5d99014bb8 style: rephrase extends beyond to contains or starts after
Some checks failed
CI / checks (push) Waiting to run
CI / sanitize (push) Failing after 14s
CI / build (push) Failing after 15s
Check Bindgen Output / check-bindgen (push) Has been cancelled
Deploy Docs / deploy-docs (push) Has been cancelled
2024-12-28 18:53:08 -05:00
Will Lillis 2a63077cac
style: correct typos 2024-12-23 02:11:09 -05:00
WillLillis 5b5cf5a5e5 fix(lib): check point, byte ranges in ts_query_cursor_set
range functions
2024-11-02 03:06:07 -04:00
Amaan Qureshi 500f4326d5 feat: add the ability to specify a custom decode function 2024-10-31 22:51:40 -04:00
Amaan Qureshi 8d68980aa8 feat(lib): add ts_query_cursor_exec_with_options
Currently, this allows users to pass in a callback that should be
invoked to check whether or not to halt query execution
2024-10-31 21:58:35 -04:00
Amaan Qureshi 26b89da9bb feat(lib): add ts_parser_parse_with_options
Currently, this allows users to pass in a callback that should be
invoked to check whether or not to halt parsing
2024-10-31 21:58:35 -04:00
ObserverOfTime c5ee0ac070 feat(lib): add the language name 2024-10-26 23:53:58 +00:00
Amaan Qureshi ce93d8fd9b feat!: bump internal abi to 15 2024-10-26 17:02:00 +00:00
Amaan Qureshi 8943983df6 feat!: properly handle UTF-16 endianness encoding 2024-10-05 21:12:48 -04:00
Riley Bruins 0683136ca0 feat(api): expose function to check if symbol represents a supertype
Some checks failed
CI / checks (push) Waiting to run
CI / sanitize (push) Failing after 11s
CI / build (push) Failing after 12s
2024-09-30 14:44:13 -04:00
Amaan Qureshi 934a2814fd fix: deprecate child_containing_descendant and add child_with_descendant instead 2024-09-30 13:57:28 -04:00
Amaan Qureshi 7e3f572655 feat: add field_name_for_named_child
Some checks failed
CI / sanitize (push) Failing after 12s
CI / build (push) Failing after 12s
CI / checks (push) Has been cancelled
2024-09-09 11:05:29 -04:00
Amaan Qureshi 3f424c0121 feat: add an API to time out query executions
Currently, if a predicate is hard to match on the Rust side, a sizable
query against a very large file can take forever, and ends up hanging.
This commit adds an API function `ts_query_cursor_set_timeout_micros` to
limit how long query execution is allowed to take, thereby negating the
chance of a hang to occur.
2024-08-31 14:33:28 -04:00
Matt Guerrette 3c7c17b00b
fix(lib): fix api header C++ interop (#3534)
Some checks failed
CI / sanitize (push) Failing after 12s
CI / build (push) Failing after 13s
CI / checks (push) Has been cancelled
2024-08-18 12:01:13 +03:00
ibrahim Sağıroğlu 76456919ae
docs: fix tree cursor documentation (#3324)
- ts_tree_cursor_current_depth
- ts_tree_cursor_reset
2024-07-28 10:36:06 +03:00
Amaan Qureshi 25c7189180 feat(lib): add ts_query_end_byte_for_pattern
Some checks failed
CI / sanitize (push) Failing after 12s
CI / build (push) Failing after 12s
CI / checks (push) Has been cancelled
2024-07-07 20:29:09 -04:00
vanaigr 90e0e28b95
feat: reverse iteration through node parents (#3214) 2024-04-23 15:19:57 +01:00
Amaan Qureshi 09d2b23a64 fix(lib): account for the root node of a tree cursor being an alias 2024-03-20 19:23:08 -04:00
ObserverOfTime 4bbaee2f56 fix(lib): allow hiding symbols 2024-03-17 07:21:06 -04:00
Matthew Smith 15e6cd1c35
refactor: name anonymous types in api.h
Anonymous structs cannot be forward declared.  This change names anonymous
types in api.h so that consumers can forward declare them.
2024-02-17 13:55:11 +01:00
dundargoc df1fe842eb docs: various fixes
Closes https://github.com/tree-sitter/tree-sitter/issues/1317.
Closes https://github.com/tree-sitter/tree-sitter/issues/1752.
Closes https://github.com/tree-sitter/tree-sitter/issues/2439.

Co-authored-by: Simon Hengel <sol@typeful.net>
Co-authored-by: Akash Yadav <itsaky01@gmail.com>
Co-authored-by: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com>
Co-authored-by: Laytan Laats <laytanlaats@hotmail.com>
2024-02-08 00:08:59 +01:00
Amaan Qureshi f4c40f6098
fix: do not install parser.h 2024-02-02 11:30:24 -05:00
Max Brunsfeld d351f81b4a Release stale instances from wasm store when languages are dropped 2024-01-29 10:17:49 -08:00
Max Brunsfeld da16cb1459 Introduce language ref-count management C APIs, remove Copy impl for Language in Rust 2023-12-27 14:59:16 -08:00
Andrew Hlynskyi d56b51a11d
Revert "Alt #2454" 2023-11-29 11:20:05 +02:00
Max Brunsfeld 13dd76e444 Return an informative error on failing to construct a WasmStore 2023-11-27 17:48:29 -08:00
Max Brunsfeld 6fd7a1e44e Return informative error when load_language fails 2023-11-26 12:15:05 -08:00
Max Brunsfeld f4e2f68f14 Merge branch 'master' into wasm-language 2023-10-27 12:11:43 +01:00
Andrew Hlynskyi f9117a0221 doc: Add internal links for api.h funcs 2023-08-28 23:09:37 +03:00