@kreuzberg/tree-sitter-language-pack 1.8.0 → 1.9.0-rc.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 +189 -0
- package/index.d.ts +296 -377
- package/index.js +7 -3
- package/package.json +6 -21
- package/ts-pack-core-node.darwin-arm64.node +0 -0
- package/ts-pack-core-node.darwin-x64.node +0 -0
- package/ts-pack-core-node.linux-arm64-gnu.node +0 -0
- package/ts-pack-core-node.linux-x64-gnu.node +0 -0
- package/ts-pack-core-node.win32-arm64-msvc.node +0 -0
- package/ts-pack-core-node.win32-x64-msvc.node +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# TypeScript / Node.js
|
|
2
|
+
|
|
3
|
+
<div
|
|
4
|
+
align="center"
|
|
5
|
+
style="display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 20px 0"
|
|
6
|
+
>
|
|
7
|
+
<a href="https://github.com/kreuzberg-dev/alef">
|
|
8
|
+
<img
|
|
9
|
+
src="https://img.shields.io/badge/Bindings-alef%20%D7%90-007ec6"
|
|
10
|
+
alt="Bindings"
|
|
11
|
+
/>
|
|
12
|
+
</a>
|
|
13
|
+
<!-- Language Bindings -->
|
|
14
|
+
<a href="https://crates.io/crates/tree-sitter-language-pack">
|
|
15
|
+
<img
|
|
16
|
+
src="https://img.shields.io/crates/v/tree-sitter-language-pack?label=Rust&color=007ec6"
|
|
17
|
+
alt="Rust"
|
|
18
|
+
/>
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://pypi.org/project/tree-sitter-language-pack/">
|
|
21
|
+
<img
|
|
22
|
+
src="https://img.shields.io/pypi/v/tree-sitter-language-pack?label=Python&color=007ec6"
|
|
23
|
+
alt="Python"
|
|
24
|
+
/>
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://www.npmjs.com/package/@kreuzberg/tree-sitter-language-pack">
|
|
27
|
+
<img
|
|
28
|
+
src="https://img.shields.io/npm/v/@kreuzberg/tree-sitter-language-pack?label=Node.js&color=007ec6"
|
|
29
|
+
alt="Node.js"
|
|
30
|
+
/>
|
|
31
|
+
</a>
|
|
32
|
+
<a href="https://www.npmjs.com/package/@kreuzberg/tree-sitter-language-pack-wasm">
|
|
33
|
+
<img
|
|
34
|
+
src="https://img.shields.io/npm/v/@kreuzberg/tree-sitter-language-pack-wasm?label=WASM&color=007ec6"
|
|
35
|
+
alt="WASM"
|
|
36
|
+
/>
|
|
37
|
+
</a>
|
|
38
|
+
<a
|
|
39
|
+
href="https://central.sonatype.com/artifact/dev.kreuzberg.treesitterlanguagepack/tree-sitter-language-pack"
|
|
40
|
+
>
|
|
41
|
+
<img
|
|
42
|
+
src="https://img.shields.io/maven-central/v/dev.kreuzberg.treesitterlanguagepack/tree-sitter-language-pack?label=Java&color=007ec6"
|
|
43
|
+
alt="Java"
|
|
44
|
+
/>
|
|
45
|
+
</a>
|
|
46
|
+
<a href="https://pkg.go.dev/github.com/kreuzberg-dev/tree-sitter-language-pack/packages/go">
|
|
47
|
+
<img
|
|
48
|
+
src="https://img.shields.io/github/v/tag/kreuzberg-dev/tree-sitter-language-pack?label=Go&color=007ec6"
|
|
49
|
+
alt="Go"
|
|
50
|
+
/>
|
|
51
|
+
</a>
|
|
52
|
+
<a href="https://www.nuget.org/packages/TreeSitterLanguagePack/">
|
|
53
|
+
<img
|
|
54
|
+
src="https://img.shields.io/nuget/v/TreeSitterLanguagePack?label=C%23&color=007ec6"
|
|
55
|
+
alt="C#"
|
|
56
|
+
/>
|
|
57
|
+
</a>
|
|
58
|
+
<a href="https://packagist.org/packages/kreuzberg/tree-sitter-language-pack">
|
|
59
|
+
<img
|
|
60
|
+
src="https://img.shields.io/packagist/v/kreuzberg/tree-sitter-language-pack?label=PHP&color=007ec6"
|
|
61
|
+
alt="PHP"
|
|
62
|
+
/>
|
|
63
|
+
</a>
|
|
64
|
+
<a href="https://rubygems.org/gems/tree_sitter_language_pack">
|
|
65
|
+
<img
|
|
66
|
+
src="https://img.shields.io/gem/v/tree_sitter_language_pack?label=Ruby&color=007ec6"
|
|
67
|
+
alt="Ruby"
|
|
68
|
+
/>
|
|
69
|
+
</a>
|
|
70
|
+
<a href="https://hex.pm/packages/tree_sitter_language_pack">
|
|
71
|
+
<img
|
|
72
|
+
src="https://img.shields.io/hexpm/v/tree_sitter_language_pack?label=Elixir&color=007ec6"
|
|
73
|
+
alt="Elixir"
|
|
74
|
+
/>
|
|
75
|
+
</a>
|
|
76
|
+
<a href="https://pub.dev/packages/tree_sitter_language_pack">
|
|
77
|
+
<img
|
|
78
|
+
src="https://img.shields.io/pub/v/tree_sitter_language_pack?label=Dart&color=007ec6"
|
|
79
|
+
alt="Dart"
|
|
80
|
+
/>
|
|
81
|
+
</a>
|
|
82
|
+
<a
|
|
83
|
+
href="https://central.sonatype.com/artifact/dev.kreuzberg.tslp.android/tree-sitter-language-pack-android"
|
|
84
|
+
>
|
|
85
|
+
<img
|
|
86
|
+
src="https://img.shields.io/maven-central/v/dev.kreuzberg.tslp.android/tree-sitter-language-pack-android?label=Kotlin&color=007ec6"
|
|
87
|
+
alt="Kotlin"
|
|
88
|
+
/>
|
|
89
|
+
</a>
|
|
90
|
+
<a href="https://github.com/kreuzberg-dev/tree-sitter-language-pack/tree/main/packages/swift">
|
|
91
|
+
<img src="https://img.shields.io/badge/Swift-SPM-007ec6" alt="Swift" />
|
|
92
|
+
</a>
|
|
93
|
+
<a href="https://github.com/kreuzberg-dev/tree-sitter-language-pack/tree/main/packages/zig">
|
|
94
|
+
<img src="https://img.shields.io/badge/Zig-package-007ec6" alt="Zig" />
|
|
95
|
+
</a>
|
|
96
|
+
<a href="https://github.com/kreuzberg-dev/tree-sitter-language-pack/releases">
|
|
97
|
+
<img src="https://img.shields.io/badge/C-FFI-007ec6" alt="C FFI" />
|
|
98
|
+
</a>
|
|
99
|
+
|
|
100
|
+
<!-- Project Info -->
|
|
101
|
+
<a href="https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/LICENSE">
|
|
102
|
+
<img src="https://img.shields.io/badge/License-MIT-007ec6" alt="License" />
|
|
103
|
+
</a>
|
|
104
|
+
<a href="https://docs.tree-sitter-language-pack.kreuzberg.dev">
|
|
105
|
+
<img src="https://img.shields.io/badge/Docs-tree--sitter--language--pack-007ec6" alt="Documentation" />
|
|
106
|
+
</a>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<div align="center" style="margin: 24px 0 0">
|
|
110
|
+
<a href="https://kreuzberg.dev">
|
|
111
|
+
<img alt="tree-sitter-language-pack" src="https://github.com/user-attachments/assets/478a83da-237b-446b-b3a8-e564c13e00a8" />
|
|
112
|
+
</a>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<div
|
|
116
|
+
align="center"
|
|
117
|
+
style="display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 28px 0 24px"
|
|
118
|
+
>
|
|
119
|
+
<a href="https://discord.gg/xt9WY3GnKR">
|
|
120
|
+
<img
|
|
121
|
+
height="22"
|
|
122
|
+
src="https://img.shields.io/badge/Discord-Chat-007ec6?logo=discord&logoColor=white"
|
|
123
|
+
alt="Join Discord"
|
|
124
|
+
/>
|
|
125
|
+
</a>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
Pre-compiled tree-sitter grammars for 305 programming languages with TypeScript types.
|
|
129
|
+
|
|
130
|
+
## What This Package Provides
|
|
131
|
+
|
|
132
|
+
- **Parser access** — load a tree-sitter language parser by name without wiring individual grammar crates or packages.
|
|
133
|
+
- **Code intelligence primitives** — parse trees, functions, classes, imports, exports, symbols, docstrings, diagnostics, and syntax-aware chunks.
|
|
134
|
+
- **Shared cache model** — parsers are fetched and cached once, then reused by every call in the process.
|
|
135
|
+
- **Same catalog as every binding** — Rust, Python, Node.js, Go, Java, PHP, Ruby, .NET, Elixir, WASM, Dart, Kotlin Android, Swift, Zig, and C FFI use the same grammar set.
|
|
136
|
+
- **Node-first TypeScript API** — native NAPI package with typed parser and query helpers.
|
|
137
|
+
|
|
138
|
+
## Installation
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
npm install @kreuzberg/tree-sitter-language-pack
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
## Quick Start
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { getParser } from "@kreuzberg/tree-sitter-language-pack";
|
|
151
|
+
|
|
152
|
+
const parser = getParser("python");
|
|
153
|
+
const tree = parser.parse("def hello(): pass");
|
|
154
|
+
console.log(tree.rootNode.toString());
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## Features
|
|
159
|
+
|
|
160
|
+
- **300+ languages** — pre-compiled tree-sitter grammars covering every major programming language and many minor ones.
|
|
161
|
+
- **On-demand download + cache** — parsers fetched at first use; subsequent runs hit the local cache.
|
|
162
|
+
- **Code intelligence** — extract functions, classes, imports, exports, symbols, docstrings, and diagnostics with one API.
|
|
163
|
+
- **Syntax-aware chunking** — semantic chunks for RAG/LLM pipelines.
|
|
164
|
+
- **Polyglot bindings** — Rust core with native bindings for Python, TypeScript, Go, Java, C#, Ruby, PHP, Elixir, and WebAssembly via [alef](https://github.com/kreuzberg-dev/alef).
|
|
165
|
+
|
|
166
|
+
## Documentation
|
|
167
|
+
|
|
168
|
+
- **[Documentation](https://docs.tree-sitter-language-pack.kreuzberg.dev)** -- Full docs and API reference
|
|
169
|
+
- **[GitHub Repository](https://github.com/kreuzberg-dev/tree-sitter-language-pack)** -- Source, issues, and discussions
|
|
170
|
+
|
|
171
|
+
## Part of Kreuzberg.dev
|
|
172
|
+
|
|
173
|
+
- [Kreuzberg](https://github.com/kreuzberg-dev/kreuzberg) — document intelligence: text, tables, metadata from 90+ formats with optional OCR.
|
|
174
|
+
- [Kreuzberg Cloud](https://github.com/kreuzberg-dev/kreuzberg-cloud) — managed extraction API with SDKs, dashboards, and observability.
|
|
175
|
+
- [kreuzcrawl](https://github.com/kreuzberg-dev/kreuzcrawl) — web crawling and scraping with HTML→Markdown and headless-Chrome fallback.
|
|
176
|
+
- [html-to-markdown](https://github.com/kreuzberg-dev/html-to-markdown) — fast, lossless HTML→Markdown engine.
|
|
177
|
+
- [liter-llm](https://github.com/kreuzberg-dev/liter-llm) — universal LLM API client with native bindings for 14 languages and 143 providers.
|
|
178
|
+
- [alef](https://github.com/kreuzberg-dev/alef) — the polyglot binding generator that produces this README and all per-language bindings.
|
|
179
|
+
- [Discord](https://discord.gg/xt9WY3GnKR) — community, roadmap, announcements.
|
|
180
|
+
|
|
181
|
+
## Contributing
|
|
182
|
+
|
|
183
|
+
Contributions are welcome! See [CONTRIBUTING.md](https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/CONTRIBUTING.md) for guidelines.
|
|
184
|
+
|
|
185
|
+
Join our [Discord community](https://discord.gg/xt9WY3GnKR) for questions and discussion.
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
MIT -- see [LICENSE](https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/LICENSE) for details.
|
package/index.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
// This file is auto-generated by alef — DO NOT EDIT.
|
|
2
|
-
// alef:hash:
|
|
2
|
+
// alef:hash:eb942221e8ed2406fb12063e817b0beb5a7403bb320401b3280c538e2b34e217
|
|
3
3
|
// To regenerate: alef generate
|
|
4
4
|
// To verify freshness: alef verify --exit-code
|
|
5
5
|
// Issues & docs: https://github.com/kreuzberg-dev/alef
|
|
6
6
|
/* eslint-disable */
|
|
7
|
+
import type { Language } from "tree-sitter";
|
|
8
|
+
|
|
9
|
+
export type JsonValue =
|
|
10
|
+
| string
|
|
11
|
+
| number
|
|
12
|
+
| boolean
|
|
13
|
+
| null
|
|
14
|
+
| JsonValue[]
|
|
15
|
+
| { [key: string]: JsonValue };
|
|
7
16
|
|
|
8
17
|
/**
|
|
9
18
|
* List all available language names (sorted, deduplicated, includes aliases).
|
|
10
19
|
*
|
|
11
20
|
* Returns names of both statically compiled and dynamically loadable languages,
|
|
12
21
|
* plus any configured aliases.
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* use tree_sitter_language_pack::available_languages;
|
|
16
|
-
*
|
|
17
|
-
* let langs = available_languages();
|
|
18
|
-
* for name in &langs {
|
|
19
|
-
* println!("{}", name);
|
|
20
|
-
* }
|
|
21
|
-
* ```typescript
|
|
22
22
|
*/
|
|
23
23
|
export declare function availableLanguages(): Array<string>;
|
|
24
24
|
|
|
@@ -28,14 +28,6 @@ export declare function availableLanguages(): Array<string>;
|
|
|
28
28
|
* This is either the custom path set via [`configure`] / [`init`] or the
|
|
29
29
|
* default: `~/.cache/tree-sitter-language-pack/v{version}/libs/`.
|
|
30
30
|
* @throws Returns an error if the system cache directory cannot be determined.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* use tree_sitter_language_pack::cache_dir;
|
|
35
|
-
*
|
|
36
|
-
* let dir = cache_dir().unwrap();
|
|
37
|
-
* println!("Cache directory: {dir}");
|
|
38
|
-
* ```typescript
|
|
39
31
|
*/
|
|
40
32
|
export declare function cacheDir(): string;
|
|
41
33
|
|
|
@@ -45,14 +37,6 @@ export declare function cacheDir(): string;
|
|
|
45
37
|
* Resets the cache registration so the next call to [`get_language`] or
|
|
46
38
|
* a download function will re-register the (now empty) cache directory.
|
|
47
39
|
* @throws Returns an error if the cache directory cannot be removed.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```typescript
|
|
51
|
-
* use tree_sitter_language_pack::clean_cache;
|
|
52
|
-
*
|
|
53
|
-
* clean_cache().unwrap();
|
|
54
|
-
* println!("Cache cleared");
|
|
55
|
-
* ```typescript
|
|
56
40
|
*/
|
|
57
41
|
export declare function cleanCache(): void;
|
|
58
42
|
|
|
@@ -64,28 +48,15 @@ export declare function cleanCache(): void;
|
|
|
64
48
|
* after languages have been registered has no effect on already-loaded
|
|
65
49
|
* languages.
|
|
66
50
|
* @throws Returns an error if the lock cannot be acquired.
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```typescript
|
|
70
|
-
* use std::path::PathBuf;
|
|
71
|
-
* use tree_sitter_language_pack::{PackConfig, configure};
|
|
72
|
-
*
|
|
73
|
-
* let config = PackConfig {
|
|
74
|
-
* cache_dir: Some(PathBuf::from("/tmp/my-parsers")),
|
|
75
|
-
* languages: None,
|
|
76
|
-
* groups: None,
|
|
77
|
-
* };
|
|
78
|
-
* configure(&config).unwrap();
|
|
79
|
-
* ```typescript
|
|
80
51
|
*/
|
|
81
|
-
export declare function configure(config:
|
|
52
|
+
export declare function configure(config: PackConfig): void;
|
|
82
53
|
|
|
83
54
|
/**
|
|
84
55
|
* Detect language name from a file path or extension.
|
|
85
56
|
*
|
|
86
57
|
* This compatibility alias matches the pre-Alef Python binding API.
|
|
87
58
|
*/
|
|
88
|
-
export declare function detectLanguage(path: string): string |
|
|
59
|
+
export declare function detectLanguage(path: string): string | null;
|
|
89
60
|
|
|
90
61
|
/**
|
|
91
62
|
* Detect language name from file content using the shebang line (`#!`).
|
|
@@ -111,7 +82,7 @@ export declare function detectLanguage(path: string): string | undefined | null;
|
|
|
111
82
|
* assert_eq!(detect_language_from_content("no shebang here"), None);
|
|
112
83
|
* ```
|
|
113
84
|
*/
|
|
114
|
-
export declare function detectLanguageFromContent(content: string): string |
|
|
85
|
+
export declare function detectLanguageFromContent(content: string): string | null;
|
|
115
86
|
|
|
116
87
|
/**
|
|
117
88
|
* Detect language name from a file extension (without leading dot).
|
|
@@ -125,7 +96,7 @@ export declare function detectLanguageFromContent(content: string): string | und
|
|
|
125
96
|
* assert_eq!(detect_language_from_extension("xyz"), None);
|
|
126
97
|
* ```
|
|
127
98
|
*/
|
|
128
|
-
export declare function detectLanguageFromExtension(ext: string): string |
|
|
99
|
+
export declare function detectLanguageFromExtension(ext: string): string | null;
|
|
129
100
|
|
|
130
101
|
/**
|
|
131
102
|
* Detect language name from a file path.
|
|
@@ -140,7 +111,7 @@ export declare function detectLanguageFromExtension(ext: string): string | undef
|
|
|
140
111
|
* assert_eq!(detect_language_from_path("Makefile"), None);
|
|
141
112
|
* ```
|
|
142
113
|
*/
|
|
143
|
-
export declare function detectLanguageFromPath(path: string): string |
|
|
114
|
+
export declare function detectLanguageFromPath(path: string): string | null;
|
|
144
115
|
|
|
145
116
|
/**
|
|
146
117
|
* Download specific languages to the local cache.
|
|
@@ -149,14 +120,6 @@ export declare function detectLanguageFromPath(path: string): string | undefined
|
|
|
149
120
|
* compiled or cached languages are included in the count.
|
|
150
121
|
* @throws Returns an error if any language is not available in the manifest or if
|
|
151
122
|
* the download fails.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```typescript
|
|
155
|
-
* use tree_sitter_language_pack::download;
|
|
156
|
-
*
|
|
157
|
-
* let count = download(&["python", "rust", "typescript"]).unwrap();
|
|
158
|
-
* println!("Ensured {} languages", count);
|
|
159
|
-
* ```typescript
|
|
160
123
|
*/
|
|
161
124
|
export declare function download(names: Array<string>): number;
|
|
162
125
|
|
|
@@ -171,14 +134,6 @@ export declare function download(names: Array<string>): number;
|
|
|
171
134
|
* Returns the total number of languages now available (statically compiled
|
|
172
135
|
* plus downloaded and cached).
|
|
173
136
|
* @throws Returns an error if the manifest cannot be fetched or the bundle download fails.
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* use tree_sitter_language_pack::download_all;
|
|
178
|
-
*
|
|
179
|
-
* let count = download_all().unwrap();
|
|
180
|
-
* println!("{} languages available", count);
|
|
181
|
-
* ```typescript
|
|
182
137
|
*/
|
|
183
138
|
export declare function downloadAll(): number;
|
|
184
139
|
|
|
@@ -187,50 +142,38 @@ export declare function downloadAll(): number;
|
|
|
187
142
|
*
|
|
188
143
|
* Does not perform any network requests. Returns an empty list if the
|
|
189
144
|
* cache directory does not exist or cannot be read.
|
|
190
|
-
* @example
|
|
191
|
-
* ```typescript
|
|
192
|
-
* use tree_sitter_language_pack::downloaded_languages;
|
|
193
|
-
*
|
|
194
|
-
* let langs = downloaded_languages();
|
|
195
|
-
* println!("{} languages already cached", langs.len());
|
|
196
|
-
* ```typescript
|
|
197
145
|
*/
|
|
198
146
|
export declare function downloadedLanguages(): Array<string>;
|
|
199
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Download every language in a named group (e.g. `"web"`, `"data"`).
|
|
150
|
+
*
|
|
151
|
+
* Groups are defined in the remote manifest and let you ensure a curated
|
|
152
|
+
* set of related grammars in one call instead of listing each name to
|
|
153
|
+
* [`download`]. Already-cached languages are skipped.
|
|
154
|
+
*
|
|
155
|
+
* Returns the total number of languages now available (statically compiled
|
|
156
|
+
* plus downloaded and cached).
|
|
157
|
+
* @throws Returns an error if the manifest cannot be fetched, the group is unknown,
|
|
158
|
+
* or any constituent language fails to download.
|
|
159
|
+
*/
|
|
160
|
+
export declare function downloadGroup(name: string): number;
|
|
161
|
+
|
|
200
162
|
/**
|
|
201
163
|
* Get the highlights query for a language, if bundled.
|
|
202
164
|
*
|
|
203
165
|
* Returns the contents of `highlights.scm` as a static string, or `None`
|
|
204
166
|
* if no highlights query is bundled for this language.
|
|
205
|
-
* @example
|
|
206
|
-
* ```typescript
|
|
207
|
-
* use tree_sitter_language_pack::get_highlights_query;
|
|
208
|
-
*
|
|
209
|
-
* // Returns Some(...) for languages with bundled queries
|
|
210
|
-
* let query = get_highlights_query("python");
|
|
211
|
-
* // Returns None for languages without bundled highlights queries
|
|
212
|
-
* let missing = get_highlights_query("nonexistent_lang");
|
|
213
|
-
* assert!(missing.is_none());
|
|
214
|
-
* ```typescript
|
|
215
167
|
*/
|
|
216
|
-
export declare function getHighlightsQuery(language: string): string |
|
|
168
|
+
export declare function getHighlightsQuery(language: string): string | null;
|
|
217
169
|
|
|
218
170
|
/**
|
|
219
171
|
* Get the injections query for a language, if bundled.
|
|
220
172
|
*
|
|
221
173
|
* Returns the contents of `injections.scm` as a static string, or `None`
|
|
222
174
|
* if no injections query is bundled for this language.
|
|
223
|
-
* @example
|
|
224
|
-
* ```typescript
|
|
225
|
-
* use tree_sitter_language_pack::get_injections_query;
|
|
226
|
-
*
|
|
227
|
-
* let query = get_injections_query("markdown");
|
|
228
|
-
* // Returns None for languages without bundled injections queries
|
|
229
|
-
* let missing = get_injections_query("nonexistent_lang");
|
|
230
|
-
* assert!(missing.is_none());
|
|
231
|
-
* ```typescript
|
|
232
175
|
*/
|
|
233
|
-
export declare function getInjectionsQuery(language: string): string |
|
|
176
|
+
export declare function getInjectionsQuery(language: string): string | null;
|
|
234
177
|
|
|
235
178
|
/**
|
|
236
179
|
* Get a tree-sitter [`Language`] by name using the global registry.
|
|
@@ -240,70 +183,32 @@ export declare function getInjectionsQuery(language: string): string | undefined
|
|
|
240
183
|
* the parser from GitHub releases if not found locally.
|
|
241
184
|
* @throws Returns [`Error::LanguageNotFound`] if the language is not recognized,
|
|
242
185
|
* or [`Error::Download`] if auto-download fails.
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* ```typescript
|
|
246
|
-
* use tree_sitter_language_pack::get_language;
|
|
247
|
-
*
|
|
248
|
-
* let lang = get_language("python").unwrap();
|
|
249
|
-
* // Use the Language with a tree-sitter Parser
|
|
250
|
-
* let mut parser = tree_sitter::Parser::new();
|
|
251
|
-
* parser.set_language(&lang).unwrap();
|
|
252
|
-
* let tree = parser.parse("x = 1", None).unwrap();
|
|
253
|
-
* assert_eq!(tree.root_node().kind(), "module");
|
|
254
|
-
* ```typescript
|
|
255
186
|
*/
|
|
256
|
-
export declare function getLanguage(name: string):
|
|
187
|
+
export declare function getLanguage(name: string): Language;
|
|
257
188
|
|
|
258
189
|
/**
|
|
259
190
|
* Get the locals query for a language, if bundled.
|
|
260
191
|
*
|
|
261
192
|
* Returns the contents of `locals.scm` as a static string, or `None`
|
|
262
193
|
* if no locals query is bundled for this language.
|
|
263
|
-
* @example
|
|
264
|
-
* ```typescript
|
|
265
|
-
* use tree_sitter_language_pack::get_locals_query;
|
|
266
|
-
*
|
|
267
|
-
* let query = get_locals_query("python");
|
|
268
|
-
* // Returns None for languages without bundled locals queries
|
|
269
|
-
* let missing = get_locals_query("nonexistent_lang");
|
|
270
|
-
* assert!(missing.is_none());
|
|
271
|
-
* ```typescript
|
|
272
194
|
*/
|
|
273
|
-
export declare function getLocalsQuery(language: string): string |
|
|
195
|
+
export declare function getLocalsQuery(language: string): string | null;
|
|
274
196
|
|
|
275
197
|
/**
|
|
276
|
-
* Get a
|
|
198
|
+
* Get a [`Parser`] pre-configured for the given language.
|
|
277
199
|
*
|
|
278
200
|
* This is a convenience function that calls [`get_language`] and configures
|
|
279
201
|
* a new parser in one step.
|
|
280
202
|
* @throws Returns [`Error::LanguageNotFound`] if the language is not recognized, or
|
|
281
203
|
* [`Error::ParserSetup`] if the language cannot be applied to the parser.
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* ```typescript
|
|
285
|
-
* use tree_sitter_language_pack::get_parser;
|
|
286
|
-
*
|
|
287
|
-
* let mut parser = get_parser("rust").unwrap();
|
|
288
|
-
* let tree = parser.parse("fn main() {}", None).unwrap();
|
|
289
|
-
* assert!(!tree.root_node().has_error());
|
|
290
|
-
* ```typescript
|
|
291
204
|
*/
|
|
292
|
-
export declare function getParser(name: string):
|
|
205
|
+
export declare function getParser(name: string): Parser;
|
|
293
206
|
|
|
294
207
|
/**
|
|
295
208
|
* Check if a language is available by name or alias.
|
|
296
209
|
*
|
|
297
210
|
* Returns `true` if the language can be loaded (statically compiled,
|
|
298
211
|
* dynamically available, or a known alias for one of these).
|
|
299
|
-
* @example
|
|
300
|
-
* ```typescript
|
|
301
|
-
* use tree_sitter_language_pack::has_language;
|
|
302
|
-
*
|
|
303
|
-
* assert!(has_language("python"));
|
|
304
|
-
* assert!(has_language("shell")); // alias for "bash"
|
|
305
|
-
* assert!(!has_language("nonexistent_language"));
|
|
306
|
-
* ```typescript
|
|
307
212
|
*/
|
|
308
213
|
export declare function hasLanguage(name: string): boolean;
|
|
309
214
|
|
|
@@ -314,50 +219,46 @@ export declare function hasLanguage(name: string): boolean;
|
|
|
314
219
|
* specified in the config. This is the recommended entry point when you want
|
|
315
220
|
* to pre-warm the cache before use.
|
|
316
221
|
* @throws Returns an error if configuration cannot be applied or if downloads fail.
|
|
317
|
-
*
|
|
318
|
-
* @example
|
|
319
|
-
* ```typescript
|
|
320
|
-
* use tree_sitter_language_pack::{PackConfig, init};
|
|
321
|
-
*
|
|
322
|
-
* let config = PackConfig {
|
|
323
|
-
* cache_dir: None,
|
|
324
|
-
* languages: Some(vec!["python".to_string(), "rust".to_string()]),
|
|
325
|
-
* groups: None,
|
|
326
|
-
* };
|
|
327
|
-
* init(&config).unwrap();
|
|
328
|
-
* ```typescript
|
|
329
222
|
*/
|
|
330
|
-
export declare function init(config:
|
|
223
|
+
export declare function init(config: PackConfig): void;
|
|
224
|
+
|
|
225
|
+
/** A byte range — start (inclusive) to end (exclusive). */
|
|
226
|
+
export interface ByteRange {
|
|
227
|
+
/** Inclusive start byte offset. */
|
|
228
|
+
readonly start: number;
|
|
229
|
+
/** Exclusive end byte offset. */
|
|
230
|
+
readonly end: number;
|
|
231
|
+
}
|
|
331
232
|
|
|
332
233
|
/** Metadata for a single chunk of source code. */
|
|
333
|
-
export interface
|
|
334
|
-
language?: string;
|
|
335
|
-
chunkIndex?: number;
|
|
336
|
-
totalChunks?: number;
|
|
337
|
-
nodeTypes?: Array<string>;
|
|
338
|
-
contextPath?: Array<string>;
|
|
339
|
-
symbolsDefined?: Array<string>;
|
|
340
|
-
comments?: Array<
|
|
341
|
-
docstrings?: Array<
|
|
342
|
-
hasErrorNodes?: boolean;
|
|
234
|
+
export interface ChunkContext {
|
|
235
|
+
readonly language?: string;
|
|
236
|
+
readonly chunkIndex?: number;
|
|
237
|
+
readonly totalChunks?: number;
|
|
238
|
+
readonly nodeTypes?: Array<string>;
|
|
239
|
+
readonly contextPath?: Array<string>;
|
|
240
|
+
readonly symbolsDefined?: Array<string>;
|
|
241
|
+
readonly comments?: Array<CommentInfo>;
|
|
242
|
+
readonly docstrings?: Array<DocstringInfo>;
|
|
243
|
+
readonly hasErrorNodes?: boolean;
|
|
343
244
|
}
|
|
344
245
|
|
|
345
246
|
/** A chunk of source code with rich metadata. */
|
|
346
|
-
export interface
|
|
347
|
-
content?: string;
|
|
348
|
-
startByte?: number;
|
|
349
|
-
endByte?: number;
|
|
350
|
-
startLine?: number;
|
|
351
|
-
endLine?: number;
|
|
352
|
-
metadata?:
|
|
247
|
+
export interface CodeChunk {
|
|
248
|
+
readonly content?: string;
|
|
249
|
+
readonly startByte?: number;
|
|
250
|
+
readonly endByte?: number;
|
|
251
|
+
readonly startLine?: number;
|
|
252
|
+
readonly endLine?: number;
|
|
253
|
+
readonly metadata?: ChunkContext;
|
|
353
254
|
}
|
|
354
255
|
|
|
355
256
|
/** A comment extracted from source code. */
|
|
356
|
-
export interface
|
|
357
|
-
text?: string;
|
|
358
|
-
kind?:
|
|
359
|
-
span?:
|
|
360
|
-
associatedNode?: string;
|
|
257
|
+
export interface CommentInfo {
|
|
258
|
+
readonly text?: string;
|
|
259
|
+
readonly kind?: CommentKind;
|
|
260
|
+
readonly span?: Span;
|
|
261
|
+
readonly associatedNode?: string;
|
|
361
262
|
}
|
|
362
263
|
|
|
363
264
|
/**
|
|
@@ -366,17 +267,17 @@ export interface JsCommentInfo {
|
|
|
366
267
|
* Distinguishes between single-line comments, block (multi-line) comments,
|
|
367
268
|
* and documentation comments.
|
|
368
269
|
*/
|
|
369
|
-
export declare enum
|
|
270
|
+
export declare enum CommentKind {
|
|
370
271
|
Line = "Line",
|
|
371
272
|
Block = "Block",
|
|
372
273
|
Doc = "Doc",
|
|
373
274
|
}
|
|
374
275
|
|
|
375
276
|
/** A diagnostic (syntax error, missing node, etc.) from parsing. */
|
|
376
|
-
export interface
|
|
377
|
-
message?: string;
|
|
378
|
-
severity?:
|
|
379
|
-
span?:
|
|
277
|
+
export interface Diagnostic {
|
|
278
|
+
readonly message?: string;
|
|
279
|
+
readonly severity?: DiagnosticSeverity;
|
|
280
|
+
readonly span?: Span;
|
|
380
281
|
}
|
|
381
282
|
|
|
382
283
|
/**
|
|
@@ -385,17 +286,17 @@ export interface JsDiagnostic {
|
|
|
385
286
|
* Used to classify parse errors, warnings, and informational messages
|
|
386
287
|
* found in the syntax tree.
|
|
387
288
|
*/
|
|
388
|
-
export declare enum
|
|
289
|
+
export declare enum DiagnosticSeverity {
|
|
389
290
|
Error = "Error",
|
|
390
291
|
Warning = "Warning",
|
|
391
292
|
Info = "Info",
|
|
392
293
|
}
|
|
393
294
|
|
|
394
295
|
/** A section within a docstring (e.g., Args, Returns, Raises). */
|
|
395
|
-
export interface
|
|
396
|
-
kind?: string;
|
|
397
|
-
name?: string;
|
|
398
|
-
description?: string;
|
|
296
|
+
export interface DocSection {
|
|
297
|
+
readonly kind?: string;
|
|
298
|
+
readonly name?: string;
|
|
299
|
+
readonly description?: string;
|
|
399
300
|
}
|
|
400
301
|
|
|
401
302
|
/**
|
|
@@ -404,7 +305,7 @@ export interface JsDocSection {
|
|
|
404
305
|
* Identifies the docstring convention used, which varies by language
|
|
405
306
|
* (e.g., Python triple-quoted strings, JSDoc, Rustdoc `///` comments).
|
|
406
307
|
*/
|
|
407
|
-
export declare enum
|
|
308
|
+
export declare enum DocstringFormat {
|
|
408
309
|
PythonTripleQuote = "PythonTripleQuote",
|
|
409
310
|
JSDoc = "JSDoc",
|
|
410
311
|
Rustdoc = "Rustdoc",
|
|
@@ -414,37 +315,22 @@ export declare enum JsDocstringFormat {
|
|
|
414
315
|
}
|
|
415
316
|
|
|
416
317
|
/** A docstring extracted from source code. */
|
|
417
|
-
export interface
|
|
418
|
-
text?: string;
|
|
419
|
-
format?:
|
|
420
|
-
span?:
|
|
421
|
-
associatedItem?: string;
|
|
422
|
-
parsedSections?: Array<
|
|
318
|
+
export interface DocstringInfo {
|
|
319
|
+
readonly text?: string;
|
|
320
|
+
readonly format?: DocstringFormat;
|
|
321
|
+
readonly span?: Span;
|
|
322
|
+
readonly associatedItem?: string;
|
|
323
|
+
readonly parsedSections?: Array<DocSection>;
|
|
423
324
|
}
|
|
424
325
|
|
|
425
326
|
/** Manages downloading and caching of pre-built parser shared libraries. */
|
|
426
|
-
export declare class
|
|
327
|
+
export declare class DownloadManager {
|
|
427
328
|
/** Create a new download manager for the given version. */
|
|
428
|
-
static new(version: string):
|
|
329
|
+
static new(version: string): DownloadManager;
|
|
429
330
|
/** Create a download manager with a custom cache directory. */
|
|
430
|
-
static withCacheDir(version: string, cacheDir: string):
|
|
431
|
-
/** Default cache directory: `~/.cache/tree-sitter-language-pack/v{version}/libs/` */
|
|
432
|
-
static defaultCacheDir(version: string): string;
|
|
433
|
-
/** Return the path to the libs cache directory. */
|
|
434
|
-
cacheDir(): string;
|
|
331
|
+
static withCacheDir(version: string, cacheDir: string): DownloadManager;
|
|
435
332
|
/** List languages that are already downloaded and cached. */
|
|
436
333
|
installedLanguages(): Array<string>;
|
|
437
|
-
/**
|
|
438
|
-
* Ensure the specified languages are available in the cache.
|
|
439
|
-
* Downloads the platform bundle if any requested languages are missing.
|
|
440
|
-
*/
|
|
441
|
-
ensureLanguages(names: Array<string>): void;
|
|
442
|
-
/** Ensure all languages in a named group are available. */
|
|
443
|
-
ensureGroup(group: string): void;
|
|
444
|
-
/** Get the expected path for a language's shared library in the cache. */
|
|
445
|
-
libPath(name: string): string;
|
|
446
|
-
/** Fetch the parser manifest from GitHub Releases. */
|
|
447
|
-
fetchManifest(): JsParserManifest;
|
|
448
334
|
/**
|
|
449
335
|
* Download the platform bundle and extract every library file it contains.
|
|
450
336
|
*
|
|
@@ -456,15 +342,24 @@ export declare class JsDownloadManager {
|
|
|
456
342
|
* Returns the number of library files extracted (including those already cached).
|
|
457
343
|
*/
|
|
458
344
|
downloadAllBestEffort(): number;
|
|
459
|
-
/**
|
|
345
|
+
/**
|
|
346
|
+
* Remove all cached parser libraries.
|
|
347
|
+
*
|
|
348
|
+
* Acquires the cross-process lock so `clean_cache` cannot race a concurrent
|
|
349
|
+
* downloader (avoids Windows sharing-violation errors against an in-flight
|
|
350
|
+
* bundle write). The `.download.lock` file itself is **not** removed — it is
|
|
351
|
+
* permanent infrastructure; deleting it could allow a concurrent process that
|
|
352
|
+
* already opened the file to continue holding a stale lock handle while a new
|
|
353
|
+
* process opens a fresh inode, breaking the mutual-exclusion guarantee.
|
|
354
|
+
*/
|
|
460
355
|
cleanCache(): void;
|
|
461
356
|
}
|
|
462
357
|
|
|
463
358
|
/** An export statement extracted from source code. */
|
|
464
|
-
export interface
|
|
465
|
-
name?: string;
|
|
466
|
-
kind?:
|
|
467
|
-
span?:
|
|
359
|
+
export interface ExportInfo {
|
|
360
|
+
readonly name?: string;
|
|
361
|
+
readonly kind?: ExportKind;
|
|
362
|
+
readonly span?: Span;
|
|
468
363
|
}
|
|
469
364
|
|
|
470
365
|
/**
|
|
@@ -472,38 +367,31 @@ export interface JsExportInfo {
|
|
|
472
367
|
*
|
|
473
368
|
* Covers named exports, default exports, and re-exports from other modules.
|
|
474
369
|
*/
|
|
475
|
-
export declare enum
|
|
370
|
+
export declare enum ExportKind {
|
|
476
371
|
Named = "Named",
|
|
477
372
|
Default = "Default",
|
|
478
373
|
ReExport = "ReExport",
|
|
479
374
|
}
|
|
480
375
|
|
|
481
376
|
/** Aggregate metrics for a source file. */
|
|
482
|
-
export interface
|
|
483
|
-
totalLines?: number;
|
|
484
|
-
codeLines?: number;
|
|
485
|
-
commentLines?: number;
|
|
486
|
-
blankLines?: number;
|
|
487
|
-
totalBytes?: number;
|
|
488
|
-
nodeCount?: number;
|
|
489
|
-
errorCount?: number;
|
|
490
|
-
maxDepth?: number;
|
|
377
|
+
export interface FileMetrics {
|
|
378
|
+
readonly totalLines?: number;
|
|
379
|
+
readonly codeLines?: number;
|
|
380
|
+
readonly commentLines?: number;
|
|
381
|
+
readonly blankLines?: number;
|
|
382
|
+
readonly totalBytes?: number;
|
|
383
|
+
readonly nodeCount?: number;
|
|
384
|
+
readonly errorCount?: number;
|
|
385
|
+
readonly maxDepth?: number;
|
|
491
386
|
}
|
|
492
387
|
|
|
493
388
|
/** An import statement extracted from source code. */
|
|
494
|
-
export interface
|
|
495
|
-
source?: string;
|
|
496
|
-
items?: Array<string>;
|
|
497
|
-
alias?: string;
|
|
498
|
-
isWildcard?: boolean;
|
|
499
|
-
span?:
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
export declare class JsLanguage {}
|
|
503
|
-
|
|
504
|
-
export interface JsLanguageInfo {
|
|
505
|
-
group: string;
|
|
506
|
-
size: number;
|
|
389
|
+
export interface ImportInfo {
|
|
390
|
+
readonly source?: string;
|
|
391
|
+
readonly items?: Array<string>;
|
|
392
|
+
readonly alias?: string;
|
|
393
|
+
readonly isWildcard?: boolean;
|
|
394
|
+
readonly span?: Span;
|
|
507
395
|
}
|
|
508
396
|
|
|
509
397
|
/**
|
|
@@ -513,39 +401,8 @@ export interface JsLanguageInfo {
|
|
|
513
401
|
* Use [`LanguageRegistry::new()`] for the default registry, or access the
|
|
514
402
|
* global instance via the module-level convenience functions
|
|
515
403
|
* (`get_language`, `available_languages`, etc.).
|
|
516
|
-
* @example
|
|
517
|
-
* ```typescript
|
|
518
|
-
* use tree_sitter_language_pack::{LanguageRegistry, ProcessConfig};
|
|
519
|
-
*
|
|
520
|
-
* let registry = LanguageRegistry::new();
|
|
521
|
-
* let langs = registry.available_languages();
|
|
522
|
-
* println!("Available: {:?}", langs);
|
|
523
|
-
*
|
|
524
|
-
* let config = ProcessConfig::new("python").all();
|
|
525
|
-
* let result = registry.process("def hello(): pass", &config).unwrap();
|
|
526
|
-
* println!("Structure: {:?}", result.structure);
|
|
527
|
-
* ```typescript
|
|
528
404
|
*/
|
|
529
|
-
export declare class
|
|
530
|
-
/**
|
|
531
|
-
* Create a registry with a custom directory for dynamic libraries.
|
|
532
|
-
*
|
|
533
|
-
* Overrides the default build-time library directory. Useful when
|
|
534
|
-
* dynamic grammar shared libraries are stored in a non-standard location.
|
|
535
|
-
*/
|
|
536
|
-
static withLibsDir(libsDir: string): JsLanguageRegistry;
|
|
537
|
-
/**
|
|
538
|
-
* Add an additional directory to search for dynamic libraries.
|
|
539
|
-
*
|
|
540
|
-
* When [`get_language`](Self::get_language) cannot find a grammar in the
|
|
541
|
-
* primary library directory, it searches these extra directories in order.
|
|
542
|
-
* Typically used by the download system to register its cache directory.
|
|
543
|
-
*
|
|
544
|
-
* Takes `&self` (not `&mut self`) because `extra_lib_dirs` uses interior
|
|
545
|
-
* mutability via an `Arc<RwLock<...>>`, so the outer registry can remain
|
|
546
|
-
* immutable while the directory list is updated.
|
|
547
|
-
*/
|
|
548
|
-
addExtraLibsDir(dir: string): void;
|
|
405
|
+
export declare class LanguageRegistry {
|
|
549
406
|
/**
|
|
550
407
|
* Get a tree-sitter [`Language`] by name.
|
|
551
408
|
*
|
|
@@ -555,7 +412,7 @@ export declare class JsLanguageRegistry {
|
|
|
555
412
|
* @throws Returns [`Error::LanguageNotFound`] if the name (after alias resolution)
|
|
556
413
|
* does not match any known grammar.
|
|
557
414
|
*/
|
|
558
|
-
getLanguage(name: string):
|
|
415
|
+
getLanguage(name: string): Language;
|
|
559
416
|
/**
|
|
560
417
|
* List all available language names, sorted and deduplicated.
|
|
561
418
|
*
|
|
@@ -573,8 +430,69 @@ export declare class JsLanguageRegistry {
|
|
|
573
430
|
/** Return the total number of available languages (including aliases). */
|
|
574
431
|
languageCount(): number;
|
|
575
432
|
/** Parse source code and extract file intelligence based on config in a single pass. */
|
|
576
|
-
process(source: string, config:
|
|
577
|
-
static default():
|
|
433
|
+
process(source: string, config: ProcessConfig): ProcessResult;
|
|
434
|
+
static default(): LanguageRegistry;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* A single syntax node within a [`Tree`].
|
|
439
|
+
*
|
|
440
|
+
* Nodes hold a strong reference to their parent tree so they remain valid
|
|
441
|
+
* regardless of how the tree is moved or stored at the FFI boundary.
|
|
442
|
+
*/
|
|
443
|
+
export declare class Node {
|
|
444
|
+
clone(): Node;
|
|
445
|
+
/** Return the node's kind name (e.g. `"function_definition"`). */
|
|
446
|
+
kind(): string;
|
|
447
|
+
/**
|
|
448
|
+
* Return the node's numeric kind ID.
|
|
449
|
+
*
|
|
450
|
+
* Tree-sitter assigns a stable `u16` ID to every node kind in a grammar
|
|
451
|
+
* (e.g. `"function_definition" → 42`). Comparing `kind_id()` is cheaper
|
|
452
|
+
* than comparing the string [`kind()`](Self::kind) in tight AST loops.
|
|
453
|
+
*/
|
|
454
|
+
kindId(): number;
|
|
455
|
+
/** Return the inclusive start byte offset of this node. */
|
|
456
|
+
startByte(): number;
|
|
457
|
+
/** Return the exclusive end byte offset of this node. */
|
|
458
|
+
endByte(): number;
|
|
459
|
+
/**
|
|
460
|
+
* Return the node's byte range as a [`ByteRange`].
|
|
461
|
+
*
|
|
462
|
+
* Callers should slice their own source bytes — this is a zero-copy
|
|
463
|
+
* text accessor.
|
|
464
|
+
*/
|
|
465
|
+
byteRange(): ByteRange;
|
|
466
|
+
/** Return the start [`Point`] (row, column). */
|
|
467
|
+
startPosition(): Point;
|
|
468
|
+
/** Return the end [`Point`] (row, column). */
|
|
469
|
+
endPosition(): Point;
|
|
470
|
+
/** True when this node is named (not punctuation/whitespace). */
|
|
471
|
+
isNamed(): boolean;
|
|
472
|
+
/** True when this is an error node. */
|
|
473
|
+
isError(): boolean;
|
|
474
|
+
/** True when this is a missing-token node. */
|
|
475
|
+
isMissing(): boolean;
|
|
476
|
+
/** True when this is an "extra" node (e.g. a comment). */
|
|
477
|
+
isExtra(): boolean;
|
|
478
|
+
/** True when this node or any descendant is an error. */
|
|
479
|
+
hasError(): boolean;
|
|
480
|
+
/** Return this node's parent, if any. */
|
|
481
|
+
parent(): Node | null;
|
|
482
|
+
/** Return the i-th child of this node, if any. */
|
|
483
|
+
child(index: number): Node | null;
|
|
484
|
+
/** Total number of children (including unnamed). */
|
|
485
|
+
childCount(): number;
|
|
486
|
+
/** Return the i-th named child of this node, if any. */
|
|
487
|
+
namedChild(index: number): Node | null;
|
|
488
|
+
/** Number of named children of this node. */
|
|
489
|
+
namedChildCount(): number;
|
|
490
|
+
/** Look up a child by its grammar-defined field name. */
|
|
491
|
+
childByFieldName(name: string): Node | null;
|
|
492
|
+
/** Return the S-expression form of this node's subtree. */
|
|
493
|
+
toSexp(): string;
|
|
494
|
+
/** Return a [`TreeCursor`] positioned at this node. */
|
|
495
|
+
walk(): TreeCursor;
|
|
578
496
|
}
|
|
579
497
|
|
|
580
498
|
/**
|
|
@@ -583,87 +501,85 @@ export declare class JsLanguageRegistry {
|
|
|
583
501
|
* Controls cache directory and which languages to pre-download.
|
|
584
502
|
* Can be loaded from a TOML file, constructed programmatically,
|
|
585
503
|
* or passed as a dict/object from language bindings.
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
* use tree_sitter_language_pack::PackConfig;
|
|
589
|
-
*
|
|
590
|
-
* let config = PackConfig {
|
|
591
|
-
* cache_dir: None,
|
|
592
|
-
* languages: Some(vec!["python".to_string(), "rust".to_string()]),
|
|
593
|
-
* groups: None,
|
|
594
|
-
* };
|
|
595
|
-
* ```typescript
|
|
596
|
-
*/
|
|
597
|
-
export interface JsPackConfig {
|
|
504
|
+
*/
|
|
505
|
+
export interface PackConfig {
|
|
598
506
|
/**
|
|
599
507
|
* Override default cache directory.
|
|
600
508
|
*
|
|
601
509
|
* Default: `~/.cache/tree-sitter-language-pack/v{version}/libs/`
|
|
602
510
|
*/
|
|
603
|
-
cacheDir?: string;
|
|
511
|
+
readonly cacheDir?: string;
|
|
604
512
|
/**
|
|
605
513
|
* Languages to pre-download on init.
|
|
606
514
|
*
|
|
607
515
|
* Each entry is a language name (e.g. `"python"`, `"rust"`).
|
|
608
516
|
*/
|
|
609
|
-
languages?: Array<string>;
|
|
517
|
+
readonly languages?: Array<string>;
|
|
610
518
|
/** Language groups to pre-download (e.g. `"web"`, `"systems"`, `"scripting"`). */
|
|
611
|
-
groups?: Array<string>;
|
|
519
|
+
readonly groups?: Array<string>;
|
|
612
520
|
}
|
|
613
521
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
522
|
+
/** A tree-sitter parser configured for one language at a time. */
|
|
523
|
+
export declare class Parser {
|
|
524
|
+
/**
|
|
525
|
+
* Configure the parser to use the language identified by name (e.g. `"python"`).
|
|
526
|
+
*
|
|
527
|
+
* Resolves the language through the global registry — auto-downloading
|
|
528
|
+
* if necessary, when the `download` feature is enabled.
|
|
529
|
+
* @throws Returns [`Error::LanguageNotFound`] if the language is not recognized,
|
|
530
|
+
* or [`Error::ParserSetup`] if the language ABI is incompatible.
|
|
531
|
+
*/
|
|
532
|
+
setLanguage(name: string): void;
|
|
533
|
+
/**
|
|
534
|
+
* Parse a UTF-8 source string. Returns `None` if parsing was cancelled
|
|
535
|
+
* or no language is set.
|
|
536
|
+
*/
|
|
537
|
+
parse(source: string): Tree | null;
|
|
538
|
+
/**
|
|
539
|
+
* Parse a raw byte slice. Returns `None` if parsing was cancelled or
|
|
540
|
+
* no language is set.
|
|
541
|
+
*/
|
|
542
|
+
parseBytes(source: Uint8Array): Tree | null;
|
|
543
|
+
/**
|
|
544
|
+
* Reset internal state. The next call to [`parse`](Self::parse) will
|
|
545
|
+
* not be incremental.
|
|
546
|
+
*/
|
|
547
|
+
reset(): void;
|
|
548
|
+
static default(): Parser;
|
|
622
549
|
}
|
|
623
550
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
551
|
+
/** A source position — row + column, zero-indexed. */
|
|
552
|
+
export interface Point {
|
|
553
|
+
/** Zero-indexed row number. */
|
|
554
|
+
readonly row: number;
|
|
555
|
+
/** Zero-indexed column number, in UTF-16 code units. */
|
|
556
|
+
readonly column: number;
|
|
628
557
|
}
|
|
629
558
|
|
|
630
559
|
/**
|
|
631
560
|
* Configuration for the `process()` function.
|
|
632
561
|
*
|
|
633
562
|
* Controls which analysis features are enabled and whether chunking is performed.
|
|
634
|
-
* @example
|
|
635
|
-
* ```typescript
|
|
636
|
-
* use tree_sitter_language_pack::ProcessConfig;
|
|
637
|
-
*
|
|
638
|
-
* // Defaults: structure + imports + exports enabled
|
|
639
|
-
* let config = ProcessConfig::new("python");
|
|
640
|
-
*
|
|
641
|
-
* // With chunking
|
|
642
|
-
* let config = ProcessConfig::new("python").with_chunking(1000);
|
|
643
|
-
*
|
|
644
|
-
* // Everything enabled
|
|
645
|
-
* let config = ProcessConfig::new("python").all();
|
|
646
|
-
* ```typescript
|
|
647
563
|
*/
|
|
648
|
-
export interface
|
|
564
|
+
export interface ProcessConfig {
|
|
649
565
|
/** Language name (required). */
|
|
650
|
-
language?: string;
|
|
566
|
+
readonly language?: string;
|
|
651
567
|
/** Extract structural items (functions, classes, etc.). Default: true. */
|
|
652
|
-
structure?: boolean;
|
|
568
|
+
readonly structure?: boolean;
|
|
653
569
|
/** Extract import statements. Default: true. */
|
|
654
|
-
imports?: boolean;
|
|
570
|
+
readonly imports?: boolean;
|
|
655
571
|
/** Extract export statements. Default: true. */
|
|
656
|
-
exports?: boolean;
|
|
572
|
+
readonly exports?: boolean;
|
|
657
573
|
/** Extract comments. Default: false. */
|
|
658
|
-
comments?: boolean;
|
|
574
|
+
readonly comments?: boolean;
|
|
659
575
|
/** Extract docstrings. Default: false. */
|
|
660
|
-
docstrings?: boolean;
|
|
576
|
+
readonly docstrings?: boolean;
|
|
661
577
|
/** Extract symbol definitions. Default: false. */
|
|
662
|
-
symbols?: boolean;
|
|
578
|
+
readonly symbols?: boolean;
|
|
663
579
|
/** Include parse diagnostics. Default: false. */
|
|
664
|
-
diagnostics?: boolean;
|
|
580
|
+
readonly diagnostics?: boolean;
|
|
665
581
|
/** Maximum chunk size in bytes. `None` disables chunking. */
|
|
666
|
-
chunkMaxSize?: number;
|
|
582
|
+
readonly chunkMaxSize?: number;
|
|
667
583
|
}
|
|
668
584
|
|
|
669
585
|
/**
|
|
@@ -686,17 +602,17 @@ export interface JsProcessConfig {
|
|
|
686
602
|
* - `diagnostics` - Parse errors (when `config.diagnostics = true`)
|
|
687
603
|
* - `chunks` - Chunked code segments (when `config.chunk_max_size` is set)
|
|
688
604
|
*/
|
|
689
|
-
export interface
|
|
690
|
-
language?: string;
|
|
691
|
-
metrics?:
|
|
692
|
-
structure?: Array<
|
|
693
|
-
imports?: Array<
|
|
694
|
-
exports?: Array<
|
|
695
|
-
comments?: Array<
|
|
696
|
-
docstrings?: Array<
|
|
697
|
-
symbols?: Array<
|
|
698
|
-
diagnostics?: Array<
|
|
699
|
-
chunks?: Array<
|
|
605
|
+
export interface ProcessResult {
|
|
606
|
+
readonly language?: string;
|
|
607
|
+
readonly metrics?: FileMetrics;
|
|
608
|
+
readonly structure?: Array<StructureItem>;
|
|
609
|
+
readonly imports?: Array<ImportInfo>;
|
|
610
|
+
readonly exports?: Array<ExportInfo>;
|
|
611
|
+
readonly comments?: Array<CommentInfo>;
|
|
612
|
+
readonly docstrings?: Array<DocstringInfo>;
|
|
613
|
+
readonly symbols?: Array<SymbolInfo>;
|
|
614
|
+
readonly diagnostics?: Array<Diagnostic>;
|
|
615
|
+
readonly chunks?: Array<CodeChunk>;
|
|
700
616
|
}
|
|
701
617
|
|
|
702
618
|
/**
|
|
@@ -705,26 +621,26 @@ export interface JsProcessResult {
|
|
|
705
621
|
* Represents both byte offsets (for slicing) and human-readable line/column
|
|
706
622
|
* positions (for display and diagnostics).
|
|
707
623
|
*/
|
|
708
|
-
export interface
|
|
709
|
-
startByte?: number;
|
|
710
|
-
endByte?: number;
|
|
711
|
-
startLine?: number;
|
|
712
|
-
startColumn?: number;
|
|
713
|
-
endLine?: number;
|
|
714
|
-
endColumn?: number;
|
|
624
|
+
export interface Span {
|
|
625
|
+
readonly startByte?: number;
|
|
626
|
+
readonly endByte?: number;
|
|
627
|
+
readonly startLine?: number;
|
|
628
|
+
readonly startColumn?: number;
|
|
629
|
+
readonly endLine?: number;
|
|
630
|
+
readonly endColumn?: number;
|
|
715
631
|
}
|
|
716
632
|
|
|
717
633
|
/** A structural item (function, class, struct, etc.) in source code. */
|
|
718
|
-
export interface
|
|
719
|
-
kind?:
|
|
720
|
-
name?: string;
|
|
721
|
-
visibility?: string;
|
|
722
|
-
span?:
|
|
723
|
-
children?: Array<
|
|
724
|
-
decorators?: Array<string>;
|
|
725
|
-
docComment?: string;
|
|
726
|
-
signature?: string;
|
|
727
|
-
bodySpan?:
|
|
634
|
+
export interface StructureItem {
|
|
635
|
+
readonly kind?: StructureKind;
|
|
636
|
+
readonly name?: string;
|
|
637
|
+
readonly visibility?: string;
|
|
638
|
+
readonly span?: Span;
|
|
639
|
+
readonly children?: Array<StructureItem>;
|
|
640
|
+
readonly decorators?: Array<string>;
|
|
641
|
+
readonly docComment?: string;
|
|
642
|
+
readonly signature?: string;
|
|
643
|
+
readonly bodySpan?: Span;
|
|
728
644
|
}
|
|
729
645
|
|
|
730
646
|
/**
|
|
@@ -734,7 +650,7 @@ export interface JsStructureItem {
|
|
|
734
650
|
* structs, enums, traits, and more. Use [`Other`](StructureKind::Other) for
|
|
735
651
|
* language-specific constructs that do not fit a standard category.
|
|
736
652
|
*/
|
|
737
|
-
export declare enum
|
|
653
|
+
export declare enum StructureKind {
|
|
738
654
|
Function = "Function",
|
|
739
655
|
Method = "Method",
|
|
740
656
|
Class = "Class",
|
|
@@ -749,12 +665,12 @@ export declare enum JsStructureKind {
|
|
|
749
665
|
}
|
|
750
666
|
|
|
751
667
|
/** A symbol (variable, function, type, etc.) extracted from source code. */
|
|
752
|
-
export interface
|
|
753
|
-
name?: string;
|
|
754
|
-
kind?:
|
|
755
|
-
span?:
|
|
756
|
-
typeAnnotation?: string;
|
|
757
|
-
doc?: string;
|
|
668
|
+
export interface SymbolInfo {
|
|
669
|
+
readonly name?: string;
|
|
670
|
+
readonly kind?: SymbolKind;
|
|
671
|
+
readonly span?: Span;
|
|
672
|
+
readonly typeAnnotation?: string;
|
|
673
|
+
readonly doc?: string;
|
|
758
674
|
}
|
|
759
675
|
|
|
760
676
|
/**
|
|
@@ -763,7 +679,7 @@ export interface JsSymbolInfo {
|
|
|
763
679
|
* Categorizes symbol definitions such as variables, constants, functions,
|
|
764
680
|
* classes, types, interfaces, enums, and modules.
|
|
765
681
|
*/
|
|
766
|
-
export declare enum
|
|
682
|
+
export declare enum SymbolKind {
|
|
767
683
|
Variable = "Variable",
|
|
768
684
|
Constant = "Constant",
|
|
769
685
|
Function = "Function",
|
|
@@ -775,20 +691,42 @@ export declare enum JsSymbolKind {
|
|
|
775
691
|
Other = "Other",
|
|
776
692
|
}
|
|
777
693
|
|
|
778
|
-
|
|
694
|
+
/** A parsed syntax tree. Cheap to clone (refcount bump). */
|
|
695
|
+
export declare class Tree {
|
|
696
|
+
/** Return the root [`Node`] of this tree. */
|
|
697
|
+
rootNode(): Node;
|
|
698
|
+
/** Return a [`TreeCursor`] positioned at the root. */
|
|
699
|
+
walk(): TreeCursor;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/** A cursor for traversing a [`Tree`]. */
|
|
703
|
+
export declare class TreeCursor {
|
|
704
|
+
/** Return the [`Node`] at the cursor's current position. */
|
|
705
|
+
node(): Node;
|
|
706
|
+
/**
|
|
707
|
+
* Move the cursor to the first child of the current node.
|
|
708
|
+
* Returns `true` if a child existed.
|
|
709
|
+
*/
|
|
710
|
+
gotoFirstChild(): boolean;
|
|
711
|
+
/**
|
|
712
|
+
* Move the cursor to the parent of the current node.
|
|
713
|
+
* Returns `true` if a parent existed.
|
|
714
|
+
*/
|
|
715
|
+
gotoParent(): boolean;
|
|
716
|
+
/**
|
|
717
|
+
* Move the cursor to the next sibling of the current node.
|
|
718
|
+
* Returns `true` if a sibling existed.
|
|
719
|
+
*/
|
|
720
|
+
gotoNextSibling(): boolean;
|
|
721
|
+
/** Return the field name for the current node, if any. */
|
|
722
|
+
fieldName(): string | null;
|
|
723
|
+
}
|
|
779
724
|
|
|
780
725
|
/**
|
|
781
726
|
* Return the number of available languages.
|
|
782
727
|
*
|
|
783
728
|
* Includes statically compiled languages, dynamically loadable languages,
|
|
784
729
|
* and aliases.
|
|
785
|
-
* @example
|
|
786
|
-
* ```typescript
|
|
787
|
-
* use tree_sitter_language_pack::language_count;
|
|
788
|
-
*
|
|
789
|
-
* let count = language_count();
|
|
790
|
-
* println!("{} languages available", count);
|
|
791
|
-
* ```typescript
|
|
792
730
|
*/
|
|
793
731
|
export declare function languageCount(): number;
|
|
794
732
|
|
|
@@ -799,14 +737,6 @@ export declare function languageCount(): number;
|
|
|
799
737
|
* downloadable languages. Use [`downloaded_languages`] to list what is
|
|
800
738
|
* already cached locally.
|
|
801
739
|
* @throws Returns an error if the manifest cannot be fetched.
|
|
802
|
-
*
|
|
803
|
-
* @example
|
|
804
|
-
* ```typescript
|
|
805
|
-
* use tree_sitter_language_pack::manifest_languages;
|
|
806
|
-
*
|
|
807
|
-
* let langs = manifest_languages().unwrap();
|
|
808
|
-
* println!("{} languages available for download", langs.len());
|
|
809
|
-
* ```typescript
|
|
810
740
|
*/
|
|
811
741
|
export declare function manifestLanguages(): Array<string>;
|
|
812
742
|
|
|
@@ -817,16 +747,5 @@ export declare function manifestLanguages(): Array<string>;
|
|
|
817
747
|
* exports, comments, docstrings, symbols, diagnostics, and/or chunks based on
|
|
818
748
|
* the flags set in [`ProcessConfig`].
|
|
819
749
|
* @throws Returns an error if the language is not found or parsing fails.
|
|
820
|
-
*
|
|
821
|
-
* @example
|
|
822
|
-
* ```typescript
|
|
823
|
-
* use tree_sitter_language_pack::{ProcessConfig, process};
|
|
824
|
-
*
|
|
825
|
-
* let config = ProcessConfig::new("python").all();
|
|
826
|
-
* let result = process("def hello(): pass", &config).unwrap();
|
|
827
|
-
* println!("Language: {}", result.language);
|
|
828
|
-
* println!("Lines: {}", result.metrics.total_lines);
|
|
829
|
-
* println!("Structures: {}", result.structure.len());
|
|
830
|
-
* ```typescript
|
|
831
750
|
*/
|
|
832
|
-
export declare function process(source: string, config:
|
|
751
|
+
export declare function process(source: string, config: ProcessConfig): ProcessResult;
|
package/index.js
CHANGED
|
@@ -3,14 +3,18 @@
|
|
|
3
3
|
const { platform, arch } = process;
|
|
4
4
|
const isWindows = platform === "win32";
|
|
5
5
|
const isMusl = () => {
|
|
6
|
+
// Prefer the report-header `glibcVersion` string when present — fastest and
|
|
7
|
+
// unambiguous on Node builds that populate it. On Node 22+, certain CI
|
|
8
|
+
// environments leave `glibcVersion` undefined even on glibc systems, so the
|
|
9
|
+
// `=== undefined` branch from older napi-rs templates produces a false
|
|
10
|
+
// "is musl" positive. Fall through to the filesystem heuristic instead: on
|
|
11
|
+
// glibc systems `/lib64/ld-musl-x86_64.so.1` does not exist; on musl systems
|
|
12
|
+
// it always does. statSync errors → not musl.
|
|
6
13
|
if (typeof process.report === "object" && typeof process.report.getReport === "function") {
|
|
7
14
|
const report = process.report.getReport();
|
|
8
15
|
if (report && report.header && typeof report.header.glibcVersion === "string") {
|
|
9
16
|
return false;
|
|
10
17
|
}
|
|
11
|
-
if (report && report.header && report.header.glibcVersion === undefined) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
18
|
}
|
|
15
19
|
try {
|
|
16
20
|
require("fs").statSync("/lib64/ld-musl-x86_64.so.1");
|
package/package.json
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kreuzberg/tree-sitter-language-pack",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
5
|
-
"keywords": [
|
|
6
|
-
"kreuzberg",
|
|
7
|
-
"language-pack",
|
|
8
|
-
"napi",
|
|
9
|
-
"parser",
|
|
10
|
-
"syntax",
|
|
11
|
-
"tree-sitter"
|
|
12
|
-
],
|
|
3
|
+
"version": "1.9.0-rc.1",
|
|
4
|
+
"description": "Pre-compiled tree-sitter grammars for 305 programming languages",
|
|
13
5
|
"license": "MIT",
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "https://github.com/kreuzberg-dev/tree-sitter-language-pack"
|
|
17
|
-
},
|
|
18
6
|
"files": [
|
|
19
7
|
"index.js",
|
|
20
8
|
"index.d.ts",
|
|
@@ -22,13 +10,9 @@
|
|
|
22
10
|
],
|
|
23
11
|
"main": "index.js",
|
|
24
12
|
"types": "index.d.ts",
|
|
25
|
-
"publishConfig": {
|
|
26
|
-
"access": "public",
|
|
27
|
-
"registry": "https://registry.npmjs.org/"
|
|
28
|
-
},
|
|
29
13
|
"scripts": {
|
|
30
|
-
"artifacts": "napi artifacts",
|
|
31
14
|
"build": "napi build --platform --release",
|
|
15
|
+
"artifacts": "napi artifacts",
|
|
32
16
|
"prepublishOnly": "napi prepublish -t npm --skip-optional-publish"
|
|
33
17
|
},
|
|
34
18
|
"devDependencies": {
|
|
@@ -37,14 +21,15 @@
|
|
|
37
21
|
"napi": {
|
|
38
22
|
"binaryName": "ts-pack-core-node",
|
|
39
23
|
"targets": [
|
|
40
|
-
"aarch64-apple-darwin",
|
|
41
24
|
"x86_64-unknown-linux-gnu",
|
|
42
25
|
"aarch64-unknown-linux-gnu",
|
|
26
|
+
"x86_64-apple-darwin",
|
|
27
|
+
"aarch64-apple-darwin",
|
|
43
28
|
"x86_64-pc-windows-msvc",
|
|
44
29
|
"aarch64-pc-windows-msvc"
|
|
45
30
|
]
|
|
46
31
|
},
|
|
47
32
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
33
|
+
"node": ">= 18"
|
|
49
34
|
}
|
|
50
35
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|