@kreuzberg/tree-sitter-language-pack-wasm 1.0.0 → 1.1.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/README.md CHANGED
@@ -30,19 +30,23 @@
30
30
  </a>
31
31
  <!-- Project Info -->
32
32
  <a href="https://github.com/kreuzberg-dev/tree-sitter-language-pack/actions">
33
- <img src="https://img.shields.io/github/actions/workflow/status/kreuzberg-dev/tree-sitter-language-pack/ci-rust.yaml?branch=main&label=CI" alt="CI">
33
+ <img src="https://img.shields.io/github/actions/workflow/status/kreuzberg-dev/tree-sitter-language-pack/ci-rust.yaml?branch=main&label=CI&color=007ec6" alt="CI">
34
34
  </a>
35
35
  <a href="https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/LICENSE">
36
- <img src="https://img.shields.io/badge/License-MIT%20%7C%20Apache--2.0-blue.svg" alt="License">
36
+ <img src="https://img.shields.io/badge/License-MIT-007ec6.svg" alt="License">
37
37
  </a>
38
38
  <a href="https://github.com/kreuzberg-dev/homebrew-tap">
39
- <img src="https://img.shields.io/badge/homebrew-ts--pack-FBB040?logo=homebrew" alt="Homebrew">
39
+ <img src="https://img.shields.io/badge/homebrew-ts--pack-007ec6?logo=homebrew" alt="Homebrew">
40
40
  </a>
41
41
  <a href="https://docs.tree-sitter-language-pack.kreuzberg.dev">
42
- <img src="https://img.shields.io/badge/docs-kreuzberg.dev-blue" alt="Docs">
42
+ <img src="https://img.shields.io/badge/docs-kreuzberg.dev-007ec6" alt="Docs">
43
43
  </a>
44
44
  </div>
45
45
 
46
+ <div align="center">
47
+ <img width="3384" height="573" alt="Banner" src="https://github.com/user-attachments/assets/478a83da-237b-446b-b3a8-e564c13e00a8" />
48
+ </div>
49
+
46
50
  <div align="center">
47
51
  <a href="https://discord.gg/xt9WY3GnKR">
48
52
  <img height="22" src="https://img.shields.io/badge/Discord-Join%20our%20community-7289da?logo=discord&logoColor=white" alt="Discord">
@@ -95,6 +99,12 @@ download(["python", "javascript"]);
95
99
  - `has_language(name)` -- check if a language is available
96
100
  - `language_count()` -- total number of supported languages
97
101
 
102
+ ### Language Detection
103
+
104
+ - `detect_language(path)` -- detect language from file path
105
+ - `detect_language_from_content(content)` -- detect language from shebang line
106
+ - `extension_ambiguity(ext)` -- check if an extension is ambiguous (returns assigned language + alternatives)
107
+
98
108
  ### Parsing
99
109
 
100
110
  - `get_parser(name)` / `parse_string(source, language)` -- parse source code into a syntax tree
@@ -108,7 +118,13 @@ download(["python", "javascript"]);
108
118
 
109
119
  - `process(source, config)` -- extract structured analysis (functions, classes, imports, comments, chunks) from source code
110
120
 
111
- For detailed API documentation, see the [WebAssembly package](https://github.com/kreuzberg-dev/tree-sitter-language-pack/tree/main/crates/ts-pack-wasm).
121
+ ### Syntax Highlighting Queries
122
+
123
+ - `get_highlights_query(language)` -- get bundled highlights.scm query for a language
124
+ - `get_injections_query(language)` -- get bundled injections.scm query
125
+ - `get_locals_query(language)` -- get bundled locals.scm query
126
+
127
+ For full documentation, see [kreuzberg.dev](https://docs.tree-sitter-language-pack.kreuzberg.dev).
112
128
 
113
129
  ## License
114
130
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@kreuzberg/tree-sitter-language-pack-wasm",
3
3
  "type": "module",
4
4
  "description": "WebAssembly bindings for tree-sitter language pack",
5
- "version": "1.0.0",
5
+ "version": "1.1.1",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
package/ts_pack_wasm.d.ts CHANGED
@@ -29,6 +29,18 @@ export function cleanCache(): void;
29
29
  */
30
30
  export function configure(_config: string): void;
31
31
 
32
+ /**
33
+ * Detect language name from a file path or extension.
34
+ * Returns null if the extension is not recognized.
35
+ */
36
+ export function detectLanguage(path: string): string | undefined;
37
+
38
+ /**
39
+ * Detect language name from file content (shebang-based detection).
40
+ * Returns null if the content does not contain a recognized shebang.
41
+ */
42
+ export function detectLanguageFromContent(content: string): string | undefined;
43
+
32
44
  /**
33
45
  * Download specific languages (not supported in WASM).
34
46
  */
@@ -45,11 +57,28 @@ export function downloadAll(): number;
45
57
  */
46
58
  export function downloadedLanguages(): Array<any>;
47
59
 
60
+ /**
61
+ * Returns extension ambiguity information for the given file extension as a JSON string.
62
+ * Returns null if the extension is not ambiguous.
63
+ * When non-null, parses to an object with "assigned" (string) and "alternatives" (string[]) fields.
64
+ */
65
+ export function extensionAmbiguity(ext: string): string | undefined;
66
+
48
67
  /**
49
68
  * Free the tree handle (called automatically by JS GC, but can be called manually).
50
69
  */
51
70
  export function freeTree(_tree: WasmTree): void;
52
71
 
72
+ /**
73
+ * Returns the bundled highlights query for the given language, or null.
74
+ */
75
+ export function getHighlightsQuery(language: string): string | undefined;
76
+
77
+ /**
78
+ * Returns the bundled injections query for the given language, or null.
79
+ */
80
+ export function getInjectionsQuery(language: string): string | undefined;
81
+
53
82
  /**
54
83
  * Returns the raw TSLanguage pointer as a u32 for wasm32 interop.
55
84
  *
@@ -57,6 +86,11 @@ export function freeTree(_tree: WasmTree): void;
57
86
  */
58
87
  export function getLanguagePtr(name: string): number;
59
88
 
89
+ /**
90
+ * Returns the bundled locals query for the given language, or null.
91
+ */
92
+ export function getLocalsQuery(language: string): string | undefined;
93
+
60
94
  /**
61
95
  * Checks whether a language with the given name is available.
62
96
  */
@@ -123,10 +157,15 @@ export interface InitOutput {
123
157
  readonly cacheDir: (a: number) => void;
124
158
  readonly cleanCache: (a: number) => void;
125
159
  readonly configure: (a: number, b: number, c: number) => void;
160
+ readonly detectLanguage: (a: number, b: number, c: number) => void;
161
+ readonly detectLanguageFromContent: (a: number, b: number, c: number) => void;
126
162
  readonly download: (a: number, b: number) => void;
127
163
  readonly downloadAll: (a: number) => void;
128
164
  readonly downloadedLanguages: (a: number) => void;
165
+ readonly extensionAmbiguity: (a: number, b: number, c: number) => void;
129
166
  readonly freeTree: (a: number) => void;
167
+ readonly getHighlightsQuery: (a: number, b: number, c: number) => void;
168
+ readonly getInjectionsQuery: (a: number, b: number, c: number) => void;
130
169
  readonly getLanguagePtr: (a: number, b: number, c: number) => void;
131
170
  readonly hasLanguage: (a: number, b: number) => number;
132
171
  readonly init: (a: number, b: number, c: number) => void;
@@ -141,6 +180,7 @@ export interface InitOutput {
141
180
  readonly treeHasErrorNodes: (a: number, b: number) => void;
142
181
  readonly treeRootChildCount: (a: number, b: number) => void;
143
182
  readonly treeRootNodeType: (a: number, b: number) => void;
183
+ readonly getLocalsQuery: (a: number, b: number, c: number) => void;
144
184
  readonly languageCount: () => number;
145
185
  readonly __wbindgen_export: (a: number, b: number) => number;
146
186
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
package/ts_pack_wasm.js CHANGED
@@ -107,6 +107,56 @@ export function configure(_config) {
107
107
  }
108
108
  }
109
109
 
110
+ /**
111
+ * Detect language name from a file path or extension.
112
+ * Returns null if the extension is not recognized.
113
+ * @param {string} path
114
+ * @returns {string | undefined}
115
+ */
116
+ export function detectLanguage(path) {
117
+ try {
118
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
119
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
120
+ const len0 = WASM_VECTOR_LEN;
121
+ wasm.detectLanguage(retptr, ptr0, len0);
122
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
123
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
124
+ let v2;
125
+ if (r0 !== 0) {
126
+ v2 = getStringFromWasm0(r0, r1).slice();
127
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
128
+ }
129
+ return v2;
130
+ } finally {
131
+ wasm.__wbindgen_add_to_stack_pointer(16);
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Detect language name from file content (shebang-based detection).
137
+ * Returns null if the content does not contain a recognized shebang.
138
+ * @param {string} content
139
+ * @returns {string | undefined}
140
+ */
141
+ export function detectLanguageFromContent(content) {
142
+ try {
143
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
144
+ const ptr0 = passStringToWasm0(content, wasm.__wbindgen_export, wasm.__wbindgen_export2);
145
+ const len0 = WASM_VECTOR_LEN;
146
+ wasm.detectLanguageFromContent(retptr, ptr0, len0);
147
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
148
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
149
+ let v2;
150
+ if (r0 !== 0) {
151
+ v2 = getStringFromWasm0(r0, r1).slice();
152
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
153
+ }
154
+ return v2;
155
+ } finally {
156
+ wasm.__wbindgen_add_to_stack_pointer(16);
157
+ }
158
+ }
159
+
110
160
  /**
111
161
  * Download specific languages (not supported in WASM).
112
162
  * @param {Array<any>} _languages
@@ -169,6 +219,32 @@ export function downloadedLanguages() {
169
219
  }
170
220
  }
171
221
 
222
+ /**
223
+ * Returns extension ambiguity information for the given file extension as a JSON string.
224
+ * Returns null if the extension is not ambiguous.
225
+ * When non-null, parses to an object with "assigned" (string) and "alternatives" (string[]) fields.
226
+ * @param {string} ext
227
+ * @returns {string | undefined}
228
+ */
229
+ export function extensionAmbiguity(ext) {
230
+ try {
231
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
232
+ const ptr0 = passStringToWasm0(ext, wasm.__wbindgen_export, wasm.__wbindgen_export2);
233
+ const len0 = WASM_VECTOR_LEN;
234
+ wasm.extensionAmbiguity(retptr, ptr0, len0);
235
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
236
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
237
+ let v2;
238
+ if (r0 !== 0) {
239
+ v2 = getStringFromWasm0(r0, r1).slice();
240
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
241
+ }
242
+ return v2;
243
+ } finally {
244
+ wasm.__wbindgen_add_to_stack_pointer(16);
245
+ }
246
+ }
247
+
172
248
  /**
173
249
  * Free the tree handle (called automatically by JS GC, but can be called manually).
174
250
  * @param {WasmTree} _tree
@@ -179,6 +255,54 @@ export function freeTree(_tree) {
179
255
  wasm.freeTree(ptr0);
180
256
  }
181
257
 
258
+ /**
259
+ * Returns the bundled highlights query for the given language, or null.
260
+ * @param {string} language
261
+ * @returns {string | undefined}
262
+ */
263
+ export function getHighlightsQuery(language) {
264
+ try {
265
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
266
+ const ptr0 = passStringToWasm0(language, wasm.__wbindgen_export, wasm.__wbindgen_export2);
267
+ const len0 = WASM_VECTOR_LEN;
268
+ wasm.getHighlightsQuery(retptr, ptr0, len0);
269
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
270
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
271
+ let v2;
272
+ if (r0 !== 0) {
273
+ v2 = getStringFromWasm0(r0, r1).slice();
274
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
275
+ }
276
+ return v2;
277
+ } finally {
278
+ wasm.__wbindgen_add_to_stack_pointer(16);
279
+ }
280
+ }
281
+
282
+ /**
283
+ * Returns the bundled injections query for the given language, or null.
284
+ * @param {string} language
285
+ * @returns {string | undefined}
286
+ */
287
+ export function getInjectionsQuery(language) {
288
+ try {
289
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
290
+ const ptr0 = passStringToWasm0(language, wasm.__wbindgen_export, wasm.__wbindgen_export2);
291
+ const len0 = WASM_VECTOR_LEN;
292
+ wasm.getInjectionsQuery(retptr, ptr0, len0);
293
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
294
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
295
+ let v2;
296
+ if (r0 !== 0) {
297
+ v2 = getStringFromWasm0(r0, r1).slice();
298
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
299
+ }
300
+ return v2;
301
+ } finally {
302
+ wasm.__wbindgen_add_to_stack_pointer(16);
303
+ }
304
+ }
305
+
182
306
  /**
183
307
  * Returns the raw TSLanguage pointer as a u32 for wasm32 interop.
184
308
  *
@@ -204,6 +328,30 @@ export function getLanguagePtr(name) {
204
328
  }
205
329
  }
206
330
 
331
+ /**
332
+ * Returns the bundled locals query for the given language, or null.
333
+ * @param {string} language
334
+ * @returns {string | undefined}
335
+ */
336
+ export function getLocalsQuery(language) {
337
+ try {
338
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
339
+ const ptr0 = passStringToWasm0(language, wasm.__wbindgen_export, wasm.__wbindgen_export2);
340
+ const len0 = WASM_VECTOR_LEN;
341
+ wasm.getLocalsQuery(retptr, ptr0, len0);
342
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
343
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
344
+ let v2;
345
+ if (r0 !== 0) {
346
+ v2 = getStringFromWasm0(r0, r1).slice();
347
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
348
+ }
349
+ return v2;
350
+ } finally {
351
+ wasm.__wbindgen_add_to_stack_pointer(16);
352
+ }
353
+ }
354
+
207
355
  /**
208
356
  * Checks whether a language with the given name is available.
209
357
  * @param {string} name
Binary file