MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / rust_fn_complexity

Function rust_fn_complexity

tests/graph_suite/complexity_test.rs:4–16  ·  view source on GitHub ↗

Helper: parse Rust source, find the first `function_item` node, and return its complexity.

(source: &str)

Source from the content-addressed store, hash-verified

2
3/// Helper: parse Rust source, find the first `function_item` node, and return its complexity.
4fn rust_fn_complexity(source: &str) -> tracedecay::extraction::complexity::ComplexityMetrics {
5 let mut parser = tree_sitter::Parser::new();
6 parser
7 .set_language(
8 &tracedecay::extraction::ts_provider::language("rust")
9 .expect("failed to load Rust grammar"),
10 )
11 .expect("failed to load Rust grammar");
12 let tree = parser.parse(source, None).expect("parse failed");
13 let root = tree.root_node();
14 let fn_node = find_first_kind(root, "function_item").expect("no function_item found in source");
15 count_complexity(fn_node, &RUST_COMPLEXITY, source.as_bytes())
16}
17
18/// Recursively find the first node of the given kind.
19fn find_first_kind<'a>(node: tree_sitter::Node<'a>, kind: &str) -> Option<tree_sitter::Node<'a>> {

Calls 4

languageFunction · 0.85
count_complexityFunction · 0.85
find_first_kindFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected