Skip to content

Commit

Permalink
Merge pull request #1546 from dodona-edu/fix/large-file-invalid-argument
Browse files Browse the repository at this point in the history
Fix invalid argument error for large files since tree-sitter 0.21
  • Loading branch information
rien authored Jun 3, 2024
2 parents ee652a0 + 7162223 commit 67fbf1c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
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);
});

0 comments on commit 67fbf1c

Please sign in to comment.