Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid argument error for large files since tree-sitter 0.21 #1546

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
- name: Build 🔧
run: |
cd cli/
npm run build --force
npm run build -- --force

cli-lint:
name: "CLI 💻️ - lint 📏"
Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:
run: |
cd core/
npm run build
npm run test -v --serial
npm run test -- -v --serial

core-lint:
name: "Core ❤️ - lint 📏"
Expand Down Expand Up @@ -282,7 +282,7 @@ jobs:
run: |
cd lib/
npm run build
npm run test -v --serial
npm run test -- -v --serial

parsers-build:
name: "Parsers 👓 - build 🔧"
Expand Down Expand Up @@ -587,7 +587,7 @@ jobs:
- name: Build CLI 🔧
run: |
cd cli/
npm run build --force
npm run build -- --force

- name: Build web 🔧
run: |
Expand Down
4 changes: 2 additions & 2 deletions lib/src/lib/tokenizer/codeTokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class CodeTokenizer extends Tokenizer {
* @param text The text string to parse
*/
public tokenize(text: string): string {
const tree = this.parser.parse(text);
const tree = this.parser.parse(text, undefined, { bufferSize: Math.max(32 * 1024, text.length * 2) });
return tree.rootNode.toString();
}

Expand All @@ -39,7 +39,7 @@ export class CodeTokenizer extends Tokenizer {
* @param text The text string to parse
*/
public *generateTokens(text: string): IterableIterator<Token> {
const tree = this.parser.parse(text);
const tree = this.parser.parse(text, undefined, { bufferSize: Math.max(32 * 1024, text.length * 2) });
yield* this.tokenizeNode(tree.rootNode);
}

Expand Down
11 changes: 11 additions & 0 deletions lib/src/test/tokenizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,14 @@ test("should be able to use external tree-sitter parsers (tree-sitter-json)", as
const { tokens } = tokenizer.tokenizeFile(file);
t.truthy(tokens);
});

test("should be able to parse larger files", async t => {
const file = new File("long.js", "var test = 1;\n".repeat(10000));
const language = await (new LanguagePicker().findLanguage("javascript"));

const tokenizer = await language.createTokenizer();
t.truthy(tokenizer);

const { tokens } = tokenizer.tokenizeFile(file);
t.truthy(tokens);
});