Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions crates/tracedecay-code-extraction/src/ts_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ pub fn try_language(key: &str) -> Result<Language, String> {
.ok_or_else(|| format!("ts_provider: unknown language key '{key}'"))
Comment thread
ScriptedAlchemy marked this conversation as resolved.
}

/// Backward-compatible fallible alias for extractor parser call sites.
pub fn language(key: &str) -> Result<Language, String> {
try_language(key)
}

/// Parse one file with the shared grammar table.
///
/// Language load and `set_language` are the `code_extraction.language` phase.
Expand Down Expand Up @@ -203,7 +198,7 @@ mod tests {
#[cfg(not(feature = "large-grammars"))]
fn large_bundle_keys_are_not_registered_without_the_bundle() -> Result<(), String> {
for key in ["powershell", "cobol", "protobuf", "zig"] {
let Err(err) = super::language(key) else {
let Err(err) = super::try_language(key) else {
return Err(format!(
"grammar key '{key}' should not be registered when its bundle is disabled"
));
Expand All @@ -216,7 +211,7 @@ mod tests {
#[test]
#[cfg(not(feature = "lang-markdown"))]
fn markdown_is_not_registered_without_its_feature() -> Result<(), String> {
let Err(err) = super::language("markdown") else {
let Err(err) = super::try_language("markdown") else {
return Err("markdown should not be registered when lang-markdown is disabled".into());
};
assert!(err.contains("unknown language key"));
Expand Down
2 changes: 1 addition & 1 deletion crates/tracedecay-code-extraction/tests/extract_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn extract_parsed(
fn parse_with_grammar(key: &str, source: &str) -> Tree {
let mut parser = Parser::new();
parser
.set_language(&ts_provider::language(key).expect("bundled grammar"))
.set_language(&ts_provider::try_language(key).expect("bundled grammar"))
.expect("configure parser");
parser.parse(source, None).expect("parse fixture")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn parse_rust(source: &str) -> Tree {
let mut parser = Parser::new();
parser
.set_language(
&tracedecay_code_extraction::ts_provider::language("rust")
&tracedecay_code_extraction::ts_provider::try_language("rust")
.expect("bundled Rust grammar"),
)
.expect("configure Rust parser");
Expand Down
2 changes: 1 addition & 1 deletion crates/tracedecay-code-extraction/tests/main/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn destructure(context: Context) {
let mut parser = Parser::new();
parser
.set_language(
&tracedecay_code_extraction::ts_provider::language("rust")
&tracedecay_code_extraction::ts_provider::try_language("rust")
.expect("bundled Rust grammar"),
)
.expect("configure Rust parser");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn parser_owned_tree_import_rows_do_not_disappear_from_parsed_artifact() {
let mut parser = Parser::new();
parser
.set_language(
&tracedecay_code_extraction::ts_provider::language("typescript")
&tracedecay_code_extraction::ts_provider::try_language("typescript")
.expect("bundled TypeScript grammar"),
)
.expect("configure TypeScript parser");
Expand Down
2 changes: 1 addition & 1 deletion crates/tracedecay/tests/graph_suite/complexity_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn rust_fn_complexity(source: &str) -> tracedecay_code_extraction::complexity::C
let mut parser = tree_sitter::Parser::new();
parser
.set_language(
&tracedecay_code_extraction::ts_provider::language("rust")
&tracedecay_code_extraction::ts_provider::try_language("rust")
.expect("failed to load Rust grammar"),
)
.expect("failed to load Rust grammar");
Expand Down
2 changes: 1 addition & 1 deletion docs/PLUGINS-DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ A `tracedecay-plugin-sdk` crate (published separately) provides:

- A `#[tracedecay_plugin]` proc-macro that generates the C ABI glue from a normal `LanguageExtractor` impl.
- Safe Rust wrappers around the JSON serialisation / deserialisation boundary.
- A `grammar!` macro that embeds the tree-sitter grammar and calls `ts_provider::language`.
- A `grammar!` macro that embeds the tree-sitter grammar and calls `ts_provider::try_language`.

Authors implement the same `LanguageExtractor` trait they would for a built-in, then add two lines:

Expand Down
Loading