tree_sitter_language_pack 1.0.0.rc.7 → 1.0.0.rc.9
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.
- checksums.yaml +4 -4
- data/Cargo.toml +4 -1
- data/src/lib.rs +78 -0
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2153215d6298710720f131215b09d0dac8b8f38da43c1f72b85b3cfaab8f0c01
|
|
4
|
+
data.tar.gz: 1f591520ce16bda97c40cfb217a233e8af5b6f3ac4e6a358bb4cfe97d4fde165
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 57ddab59c16c7dcea2d1cb90144d928ed5161f72d0eead1fb0fb6e906cdbdc11b8e3c6b46725783d8243a1b58600a2aae31c269a44a04314993214b9e56fbc0a
|
|
7
|
+
data.tar.gz: 1d660c50f5ccfddb836f90ae898bcb3257b62f0cbb7beeab78143c07ff82b2ef4be0bf399a3c9c9d736fc833b2e441dcf388ab0585a863e94f1d43ecc9b2bf4f
|
data/Cargo.toml
CHANGED
|
@@ -12,7 +12,10 @@ name = "ts_pack_ruby"
|
|
|
12
12
|
crate-type = ["cdylib"]
|
|
13
13
|
|
|
14
14
|
[dependencies]
|
|
15
|
-
tree-sitter-language-pack = { workspace = true, features = [
|
|
15
|
+
tree-sitter-language-pack = { workspace = true, features = [
|
|
16
|
+
"serde",
|
|
17
|
+
"download",
|
|
18
|
+
] }
|
|
16
19
|
serde_json = { workspace = true }
|
|
17
20
|
tree-sitter = { workspace = true }
|
|
18
21
|
magnus = "0.8"
|
data/src/lib.rs
CHANGED
|
@@ -75,10 +75,78 @@ fn process(ruby: &Ruby, source: String, config_json: String) -> Result<String, E
|
|
|
75
75
|
.map_err(|e| Error::new(ruby.exception_runtime_error(), format!("serialization failed: {e}")))
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
/// Initialize the language pack with configuration.
|
|
79
|
+
///
|
|
80
|
+
/// Accepts a JSON string with optional fields:
|
|
81
|
+
/// - `cache_dir` (string): override default cache directory
|
|
82
|
+
/// - `languages` (array): language names to pre-download
|
|
83
|
+
/// - `groups` (array): language groups to pre-download
|
|
84
|
+
fn rb_init(ruby: &Ruby, config_json: String) -> Result<(), Error> {
|
|
85
|
+
let config: tree_sitter_language_pack::PackConfig = serde_json::from_str(&config_json)
|
|
86
|
+
.map_err(|e| Error::new(ruby.exception_runtime_error(), format!("invalid config JSON: {e}")))?;
|
|
87
|
+
|
|
88
|
+
tree_sitter_language_pack::init(&config).map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// Configure the language pack without downloading.
|
|
92
|
+
///
|
|
93
|
+
/// Accepts a JSON string with optional fields:
|
|
94
|
+
/// - `cache_dir` (string): override default cache directory
|
|
95
|
+
fn rb_configure(ruby: &Ruby, config_json: String) -> Result<(), Error> {
|
|
96
|
+
let config: tree_sitter_language_pack::PackConfig = serde_json::from_str(&config_json)
|
|
97
|
+
.map_err(|e| Error::new(ruby.exception_runtime_error(), format!("invalid config JSON: {e}")))?;
|
|
98
|
+
|
|
99
|
+
tree_sitter_language_pack::configure(&config)
|
|
100
|
+
.map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// Download specific languages to the cache.
|
|
104
|
+
///
|
|
105
|
+
/// Returns the number of newly downloaded languages.
|
|
106
|
+
fn rb_download(ruby: &Ruby, names: Vec<String>) -> Result<usize, Error> {
|
|
107
|
+
let refs: Vec<&str> = names.iter().map(String::as_str).collect();
|
|
108
|
+
tree_sitter_language_pack::download(&refs).map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// Download all available languages from the remote manifest.
|
|
112
|
+
///
|
|
113
|
+
/// Returns the number of newly downloaded languages.
|
|
114
|
+
fn rb_download_all(ruby: &Ruby) -> Result<usize, Error> {
|
|
115
|
+
tree_sitter_language_pack::download_all().map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Get all language names available in the remote manifest.
|
|
119
|
+
fn rb_manifest_languages(ruby: &Ruby) -> Result<Vec<String>, Error> {
|
|
120
|
+
tree_sitter_language_pack::manifest_languages()
|
|
121
|
+
.map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/// Get all languages that are already downloaded and cached locally.
|
|
125
|
+
fn rb_downloaded_languages() -> Vec<String> {
|
|
126
|
+
tree_sitter_language_pack::downloaded_languages()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// Delete all cached parser shared libraries.
|
|
130
|
+
fn rb_clean_cache(ruby: &Ruby) -> Result<(), Error> {
|
|
131
|
+
tree_sitter_language_pack::clean_cache().map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/// Get the effective cache directory path as a string.
|
|
135
|
+
fn rb_cache_dir(ruby: &Ruby) -> Result<String, Error> {
|
|
136
|
+
tree_sitter_language_pack::cache_dir()
|
|
137
|
+
.map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
|
|
138
|
+
.and_then(|path| {
|
|
139
|
+
path.to_str()
|
|
140
|
+
.ok_or_else(|| Error::new(ruby.exception_runtime_error(), "cache path is not valid UTF-8"))
|
|
141
|
+
.map(|s| s.to_string())
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
78
145
|
#[magnus::init]
|
|
79
146
|
fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
80
147
|
let module = ruby.define_module("TreeSitterLanguagePack")?;
|
|
81
148
|
|
|
149
|
+
// Registry and parsing functions
|
|
82
150
|
module.define_module_function("available_languages", function!(available_languages, 0))?;
|
|
83
151
|
module.define_module_function("has_language", function!(has_language, 1))?;
|
|
84
152
|
module.define_module_function("language_count", function!(language_count, 0))?;
|
|
@@ -86,6 +154,16 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
|
86
154
|
module.define_module_function("parse_string", function!(parse_string, 2))?;
|
|
87
155
|
module.define_module_function("process", function!(process, 2))?;
|
|
88
156
|
|
|
157
|
+
// Download API functions
|
|
158
|
+
module.define_module_function("init", function!(rb_init, 1))?;
|
|
159
|
+
module.define_module_function("configure", function!(rb_configure, 1))?;
|
|
160
|
+
module.define_module_function("download", function!(rb_download, 1))?;
|
|
161
|
+
module.define_module_function("download_all", function!(rb_download_all, 0))?;
|
|
162
|
+
module.define_module_function("manifest_languages", function!(rb_manifest_languages, 0))?;
|
|
163
|
+
module.define_module_function("downloaded_languages", function!(rb_downloaded_languages, 0))?;
|
|
164
|
+
module.define_module_function("clean_cache", function!(rb_clean_cache, 0))?;
|
|
165
|
+
module.define_module_function("cache_dir", function!(rb_cache_dir, 0))?;
|
|
166
|
+
|
|
89
167
|
let tree_class = module.define_class("Tree", ruby.class_object())?;
|
|
90
168
|
tree_class.define_method("root_node_type", method!(TreeWrapper::root_node_type, 0))?;
|
|
91
169
|
tree_class.define_method("root_child_count", method!(TreeWrapper::root_child_count, 0))?;
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tree_sitter_language_pack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.0.rc.
|
|
4
|
+
version: 1.0.0.rc.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- kreuzberg.dev
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rb_sys
|
|
@@ -42,7 +41,6 @@ licenses:
|
|
|
42
41
|
- MIT
|
|
43
42
|
metadata:
|
|
44
43
|
cargo_crate_name: ts-pack-ruby
|
|
45
|
-
post_install_message:
|
|
46
44
|
rdoc_options: []
|
|
47
45
|
require_paths:
|
|
48
46
|
- lib
|
|
@@ -50,15 +48,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
50
48
|
requirements:
|
|
51
49
|
- - ">="
|
|
52
50
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: 3.
|
|
51
|
+
version: 3.4.0
|
|
54
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
53
|
requirements:
|
|
56
54
|
- - ">="
|
|
57
55
|
- !ruby/object:Gem::Version
|
|
58
56
|
version: '0'
|
|
59
57
|
requirements: []
|
|
60
|
-
rubygems_version: 3.
|
|
61
|
-
signing_key:
|
|
58
|
+
rubygems_version: 3.6.9
|
|
62
59
|
specification_version: 4
|
|
63
60
|
summary: Ruby bindings for tree-sitter-language-pack
|
|
64
61
|
test_files: []
|