@kreuzberg/tree-sitter-language-pack-wasm 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kreuzberg/tree-sitter-language-pack-wasm",
3
3
  "description": "Pre-compiled tree-sitter grammars for 305 programming languages",
4
- "version": "1.8.0",
4
+ "version": "1.8.1",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,12 +1,25 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /**
5
+ * A byte range — start (inclusive) to end (exclusive).
6
+ */
7
+ export class WasmByteRange {
8
+ free(): void;
9
+ [Symbol.dispose](): void;
10
+ static default(): WasmByteRange;
11
+ constructor(start: number, end: number);
12
+ end: number;
13
+ start: number;
14
+ }
15
+
4
16
  /**
5
17
  * Metadata for a single chunk of source code.
6
18
  */
7
19
  export class WasmChunkContext {
8
20
  free(): void;
9
21
  [Symbol.dispose](): void;
22
+ static default(): WasmChunkContext;
10
23
  constructor(language?: string | null, chunk_index?: number | null, total_chunks?: number | null, node_types?: string[] | null, context_path?: string[] | null, symbols_defined?: string[] | null, comments?: WasmCommentInfo[] | null, docstrings?: WasmDocstringInfo[] | null, has_error_nodes?: boolean | null);
11
24
  chunkIndex: number;
12
25
  comments: WasmCommentInfo[];
@@ -25,6 +38,7 @@ export class WasmChunkContext {
25
38
  export class WasmCodeChunk {
26
39
  free(): void;
27
40
  [Symbol.dispose](): void;
41
+ static default(): WasmCodeChunk;
28
42
  constructor(content?: string | null, start_byte?: number | null, end_byte?: number | null, start_line?: number | null, end_line?: number | null, metadata?: WasmChunkContext | null);
29
43
  content: string;
30
44
  endByte: number;
@@ -40,10 +54,12 @@ export class WasmCodeChunk {
40
54
  export class WasmCommentInfo {
41
55
  free(): void;
42
56
  [Symbol.dispose](): void;
57
+ static default(): WasmCommentInfo;
43
58
  constructor(text?: string | null, kind?: WasmCommentKind | null, span?: WasmSpan | null, associated_node?: string | null);
44
59
  get associatedNode(): string | undefined;
45
60
  set associatedNode(value: string | null | undefined);
46
- kind: WasmCommentKind;
61
+ get kind(): string;
62
+ set kind(value: WasmCommentKind);
47
63
  span: WasmSpan;
48
64
  text: string;
49
65
  }
@@ -66,9 +82,11 @@ export enum WasmCommentKind {
66
82
  export class WasmDiagnostic {
67
83
  free(): void;
68
84
  [Symbol.dispose](): void;
85
+ static default(): WasmDiagnostic;
69
86
  constructor(message?: string | null, severity?: WasmDiagnosticSeverity | null, span?: WasmSpan | null);
70
87
  message: string;
71
- severity: WasmDiagnosticSeverity;
88
+ get severity(): string;
89
+ set severity(value: WasmDiagnosticSeverity);
72
90
  span: WasmSpan;
73
91
  }
74
92
 
@@ -90,6 +108,7 @@ export enum WasmDiagnosticSeverity {
90
108
  export class WasmDocSection {
91
109
  free(): void;
92
110
  [Symbol.dispose](): void;
111
+ static default(): WasmDocSection;
93
112
  constructor(kind?: string | null, description?: string | null, name?: string | null);
94
113
  description: string;
95
114
  kind: string;
@@ -118,10 +137,12 @@ export enum WasmDocstringFormat {
118
137
  export class WasmDocstringInfo {
119
138
  free(): void;
120
139
  [Symbol.dispose](): void;
140
+ static default(): WasmDocstringInfo;
121
141
  constructor(text?: string | null, format?: WasmDocstringFormat | null, span?: WasmSpan | null, parsed_sections?: WasmDocSection[] | null, associated_item?: string | null);
122
142
  get associatedItem(): string | undefined;
123
143
  set associatedItem(value: string | null | undefined);
124
- format: WasmDocstringFormat;
144
+ get format(): string;
145
+ set format(value: WasmDocstringFormat);
125
146
  parsedSections: WasmDocSection[];
126
147
  span: WasmSpan;
127
148
  text: string;
@@ -133,8 +154,10 @@ export class WasmDocstringInfo {
133
154
  export class WasmExportInfo {
134
155
  free(): void;
135
156
  [Symbol.dispose](): void;
157
+ static default(): WasmExportInfo;
136
158
  constructor(name?: string | null, kind?: WasmExportKind | null, span?: WasmSpan | null);
137
- kind: WasmExportKind;
159
+ get kind(): string;
160
+ set kind(value: WasmExportKind);
138
161
  name: string;
139
162
  span: WasmSpan;
140
163
  }
@@ -156,6 +179,7 @@ export enum WasmExportKind {
156
179
  export class WasmFileMetrics {
157
180
  free(): void;
158
181
  [Symbol.dispose](): void;
182
+ static default(): WasmFileMetrics;
159
183
  constructor(total_lines?: number | null, code_lines?: number | null, comment_lines?: number | null, blank_lines?: number | null, total_bytes?: number | null, node_count?: number | null, error_count?: number | null, max_depth?: number | null);
160
184
  blankLines: number;
161
185
  codeLines: number;
@@ -173,6 +197,7 @@ export class WasmFileMetrics {
173
197
  export class WasmImportInfo {
174
198
  free(): void;
175
199
  [Symbol.dispose](): void;
200
+ static default(): WasmImportInfo;
176
201
  constructor(source?: string | null, items?: string[] | null, is_wildcard?: boolean | null, span?: WasmSpan | null, alias?: string | null);
177
202
  get alias(): string | undefined;
178
203
  set alias(value: string | null | undefined);
@@ -271,6 +296,102 @@ export class WasmLanguageRegistry {
271
296
  static withLibsDir(libs_dir: string): WasmLanguageRegistry;
272
297
  }
273
298
 
299
+ /**
300
+ * A single syntax node within a [`Tree`].
301
+ *
302
+ * Nodes hold a strong reference to their parent tree so they remain valid
303
+ * regardless of how the tree is moved or stored at the FFI boundary.
304
+ */
305
+ export class WasmNode {
306
+ private constructor();
307
+ free(): void;
308
+ [Symbol.dispose](): void;
309
+ /**
310
+ * Return the node's byte range as a [`ByteRange`].
311
+ *
312
+ * Callers should slice their own source bytes — this is a zero-copy
313
+ * text accessor.
314
+ */
315
+ byteRange(): WasmByteRange;
316
+ /**
317
+ * Return the i-th child of this node, if any.
318
+ */
319
+ child(index: number): WasmNode | undefined;
320
+ /**
321
+ * Look up a child by its grammar-defined field name.
322
+ */
323
+ childByFieldName(name: string): WasmNode | undefined;
324
+ /**
325
+ * Total number of children (including unnamed).
326
+ */
327
+ childCount(): number;
328
+ clone(): WasmNode;
329
+ /**
330
+ * Return the exclusive end byte offset of this node.
331
+ */
332
+ endByte(): number;
333
+ /**
334
+ * Return the end [`Point`] (row, column).
335
+ */
336
+ endPosition(): WasmPoint;
337
+ /**
338
+ * True when this node or any descendant is an error.
339
+ */
340
+ hasError(): boolean;
341
+ /**
342
+ * True when this is an error node.
343
+ */
344
+ isError(): boolean;
345
+ /**
346
+ * True when this is an "extra" node (e.g. a comment).
347
+ */
348
+ isExtra(): boolean;
349
+ /**
350
+ * True when this is a missing-token node.
351
+ */
352
+ isMissing(): boolean;
353
+ /**
354
+ * True when this node is named (not punctuation/whitespace).
355
+ */
356
+ isNamed(): boolean;
357
+ /**
358
+ * Return the node's kind name (e.g. `"function_definition"`).
359
+ */
360
+ kind(): string;
361
+ /**
362
+ * Return the node's numeric kind ID.
363
+ */
364
+ kindId(): number;
365
+ /**
366
+ * Return the i-th named child of this node, if any.
367
+ */
368
+ namedChild(index: number): WasmNode | undefined;
369
+ /**
370
+ * Number of named children of this node.
371
+ */
372
+ namedChildCount(): number;
373
+ /**
374
+ * Return this node's parent, if any.
375
+ */
376
+ parent(): WasmNode | undefined;
377
+ /**
378
+ * Return the inclusive start byte offset of this node.
379
+ */
380
+ startByte(): number;
381
+ /**
382
+ * Return the start [`Point`] (row, column).
383
+ */
384
+ startPosition(): WasmPoint;
385
+ /**
386
+ * Return the S-expression form of this node's subtree.
387
+ */
388
+ toSexp(): string;
389
+ /**
390
+ * Return a [`TreeCursor`] positioned at this node.
391
+ */
392
+ walk(): WasmTreeCursor;
393
+ }
394
+
274
395
  /**
275
396
  * Configuration for the tree-sitter language pack.
276
397
  *
@@ -293,6 +414,7 @@ export class WasmLanguageRegistry {
293
414
  export class WasmPackConfig {
294
415
  free(): void;
295
416
  [Symbol.dispose](): void;
417
+ static default(): WasmPackConfig;
296
418
  /**
297
419
  * Discover configuration by searching for `language-pack.toml` in:
298
420
  *
@@ -339,10 +461,66 @@ export class WasmPackConfig {
339
461
  set languages(value: string[] | null | undefined);
340
462
  }
341
463
 
464
+ /**
465
+ * A tree-sitter parser configured for one language at a time.
466
+ *
467
+ * # Example
468
+ *
469
+ * ```no_run
470
+ * use tree_sitter_language_pack::Parser;
471
+ *
472
+ * let mut parser = Parser::new();
473
+ * parser.set_language("python")?;
474
+ * let tree = parser.parse("def hello(): pass").expect("parse failed");
475
+ * assert_eq!(tree.root_node().kind(), "module");
476
+ * # Ok::<(), tree_sitter_language_pack::Error>(())
477
+ * ```
478
+ */
342
479
  export class WasmParser {
343
480
  private constructor();
344
481
  free(): void;
345
482
  [Symbol.dispose](): void;
483
+ static default(): WasmParser;
484
+ /**
485
+ * Parse a UTF-8 source string. Returns `None` if parsing was cancelled
486
+ * or no language is set.
487
+ */
488
+ parse(source: string): WasmTree | undefined;
489
+ /**
490
+ * Parse a raw byte slice. Returns `None` if parsing was cancelled or
491
+ * no language is set.
492
+ */
493
+ parseBytes(source: Uint8Array): WasmTree | undefined;
494
+ /**
495
+ * Reset internal state. The next call to [`parse`](Self::parse) will
496
+ * not be incremental.
497
+ */
498
+ reset(): void;
499
+ /**
500
+ * Configure the parser to use the language identified by name (e.g. `"python"`).
501
+ *
502
+ * Resolves the language through the global registry — auto-downloading
503
+ * if necessary, when the `download` feature is enabled.
504
+ *
505
+ * # Errors
506
+ *
507
+ * Returns [`Error::LanguageNotFound`] if the language is not recognized,
508
+ * or [`Error::ParserSetup`] if the language ABI is incompatible.
509
+ */
510
+ setLanguage(name: string): void;
511
+ }
512
+
513
+ /**
514
+ * A source position — row + column, zero-indexed.
515
+ */
516
+ export class WasmPoint {
517
+ free(): void;
518
+ [Symbol.dispose](): void;
519
+ static default(): WasmPoint;
520
+ static from(p: WasmPoint): WasmPoint;
521
+ constructor(row: number, column: number);
522
+ column: number;
523
+ row: number;
346
524
  }
347
525
 
348
526
  /**
@@ -417,6 +595,7 @@ export class WasmProcessConfig {
417
595
  export class WasmProcessResult {
418
596
  free(): void;
419
597
  [Symbol.dispose](): void;
598
+ static default(): WasmProcessResult;
420
599
  constructor(language?: string | null, metrics?: WasmFileMetrics | null, structure?: WasmStructureItem[] | null, imports?: WasmImportInfo[] | null, exports?: WasmExportInfo[] | null, comments?: WasmCommentInfo[] | null, docstrings?: WasmDocstringInfo[] | null, symbols?: WasmSymbolInfo[] | null, diagnostics?: WasmDiagnostic[] | null, chunks?: WasmCodeChunk[] | null);
421
600
  chunks: WasmCodeChunk[];
422
601
  comments: WasmCommentInfo[];
@@ -439,6 +618,7 @@ export class WasmProcessResult {
439
618
  export class WasmSpan {
440
619
  free(): void;
441
620
  [Symbol.dispose](): void;
621
+ static default(): WasmSpan;
442
622
  constructor(start_byte?: number | null, end_byte?: number | null, start_line?: number | null, start_column?: number | null, end_line?: number | null, end_column?: number | null);
443
623
  endByte: number;
444
624
  endColumn: number;
@@ -454,6 +634,7 @@ export class WasmSpan {
454
634
  export class WasmStructureItem {
455
635
  free(): void;
456
636
  [Symbol.dispose](): void;
637
+ static default(): WasmStructureItem;
457
638
  constructor(kind?: WasmStructureKind | null, span?: WasmSpan | null, children?: WasmStructureItem[] | null, decorators?: string[] | null, name?: string | null, visibility?: string | null, doc_comment?: string | null, signature?: string | null, body_span?: WasmSpan | null);
458
639
  get bodySpan(): WasmSpan | undefined;
459
640
  set bodySpan(value: WasmSpan | null | undefined);
@@ -461,7 +642,8 @@ export class WasmStructureItem {
461
642
  decorators: string[];
462
643
  get docComment(): string | undefined;
463
644
  set docComment(value: string | null | undefined);
464
- kind: WasmStructureKind;
645
+ get kind(): string;
646
+ set kind(value: WasmStructureKind);
465
647
  get name(): string | undefined;
466
648
  set name(value: string | null | undefined);
467
649
  get signature(): string | undefined;
@@ -498,10 +680,12 @@ export enum WasmStructureKind {
498
680
  export class WasmSymbolInfo {
499
681
  free(): void;
500
682
  [Symbol.dispose](): void;
683
+ static default(): WasmSymbolInfo;
501
684
  constructor(name?: string | null, kind?: WasmSymbolKind | null, span?: WasmSpan | null, type_annotation?: string | null, doc?: string | null);
502
685
  get doc(): string | undefined;
503
686
  set doc(value: string | null | undefined);
504
- kind: WasmSymbolKind;
687
+ get kind(): string;
688
+ set kind(value: WasmSymbolKind);
505
689
  name: string;
506
690
  span: WasmSpan;
507
691
  get typeAnnotation(): string | undefined;
@@ -526,10 +710,53 @@ export enum WasmSymbolKind {
526
710
  Other = 8,
527
711
  }
528
712
 
713
+ /**
714
+ * A parsed syntax tree. Cheap to clone (refcount bump).
715
+ */
529
716
  export class WasmTree {
530
717
  private constructor();
531
718
  free(): void;
532
719
  [Symbol.dispose](): void;
720
+ /**
721
+ * Return the root [`Node`] of this tree.
722
+ */
723
+ rootNode(): WasmNode;
724
+ /**
725
+ * Return a [`TreeCursor`] positioned at the root.
726
+ */
727
+ walk(): WasmTreeCursor;
728
+ }
729
+
730
+ /**
731
+ * A cursor for traversing a [`Tree`].
732
+ */
733
+ export class WasmTreeCursor {
734
+ private constructor();
735
+ free(): void;
736
+ [Symbol.dispose](): void;
737
+ /**
738
+ * Return the field name for the current node, if any.
739
+ */
740
+ fieldName(): string | undefined;
741
+ /**
742
+ * Move the cursor to the first child of the current node.
743
+ * Returns `true` if a child existed.
744
+ */
745
+ gotoFirstChild(): boolean;
746
+ /**
747
+ * Move the cursor to the next sibling of the current node.
748
+ * Returns `true` if a sibling existed.
749
+ */
750
+ gotoNextSibling(): boolean;
751
+ /**
752
+ * Move the cursor to the parent of the current node.
753
+ * Returns `true` if a parent existed.
754
+ */
755
+ gotoParent(): boolean;
756
+ /**
757
+ * Return the [`Node`] at the cursor's current position.
758
+ */
759
+ node(): WasmNode;
533
760
  }
534
761
 
535
762
  /**
@@ -667,14 +894,14 @@ export function getInjectionsQuery(language: string): string | undefined;
667
894
  * # Example
668
895
  *
669
896
  * ```no_run
670
- * use tree_sitter_language_pack::get_language;
897
+ * use tree_sitter_language_pack::{get_language, Parser};
671
898
  *
672
- * let lang = get_language("python").unwrap();
673
- * // Use the Language with a tree-sitter Parser
674
- * let mut parser = tree_sitter::Parser::new();
675
- * parser.set_language(&lang).unwrap();
676
- * let tree = parser.parse("x = 1", None).unwrap();
899
+ * let _lang = get_language("python")?;
900
+ * let mut parser = Parser::new();
901
+ * parser.set_language("python")?;
902
+ * let tree = parser.parse("x = 1").expect("parse failed");
677
903
  * assert_eq!(tree.root_node().kind(), "module");
904
+ * # Ok::<(), tree_sitter_language_pack::Error>(())
678
905
  * ```
679
906
  */
680
907
  export function getLanguage(name: string): WasmLanguage;
@@ -699,7 +926,7 @@ export function getLanguage(name: string): WasmLanguage;
699
926
  export function getLocalsQuery(language: string): string | undefined;
700
927
 
701
928
  /**
702
- * Get a tree-sitter [`Parser`] pre-configured for the given language.
929
+ * Get a [`Parser`] pre-configured for the given language.
703
930
  *
704
931
  * This is a convenience function that calls [`get_language`] and configures
705
932
  * a new parser in one step.
@@ -714,9 +941,10 @@ export function getLocalsQuery(language: string): string | undefined;
714
941
  * ```no_run
715
942
  * use tree_sitter_language_pack::get_parser;
716
943
  *
717
- * let mut parser = get_parser("rust").unwrap();
718
- * let tree = parser.parse("fn main() {}", None).unwrap();
944
+ * let mut parser = get_parser("rust")?;
945
+ * let tree = parser.parse("fn main() {}").expect("parse failed");
719
946
  * assert!(!tree.root_node().has_error());
947
+ * # Ok::<(), tree_sitter_language_pack::Error>(())
720
948
  * ```
721
949
  */
722
950
  export function getParser(name: string): WasmParser;