tree-sitter / tree-sitter

An incremental parsing system for programming tools

Home Page:https://tree-sitter.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`setTimeoutMicros` doesn't appear to work in the latest versions of `web-tree-sitter`

alexr00 opened this issue · comments

Problem

The last version where setTimeoutMicros works in the web-tree-sitter package is 0.22.2. I've tested with version 0.22.3-0.22.6 and none of them seem to respect the timeout set by setTimeoutMicros

Steps to reproduce

Here's an example. When I run it with 0.22.2, I can see that several rounds are run (for my sample source it's 19), but newer versions I only see 1 round get run.

Parser.init().then(async () => {
    const parser = new Parser();
    const ts = await Parser.Language.load('./src/tree-sitter-typescript.wasm');
    parser.setLanguage(ts);
    parser.setTimeoutMicros(50000);

    let error = true;
    let timeoutTree;
    let rounds = 0;
    while (error) {
        rounds++;
        try {
            timeoutTree = parser.parse(source);
            if (timeoutTree) {
                error = false;
            }
        } catch (e) {
            // expected because we've set a timeout that will be hit
        }
    }
    console.log('rounds:', rounds);
});

Expected behavior

The timeout set with setTimeoutMicros is respected.

Tree-sitter version (tree-sitter --version)

0.22.6

Operating system/version

Windows 11

Is this also an issue in Node or Rust?

The node bindings are on version 0.21.1, which I tested and it worked as expected (setTimeoutMicros is respected).