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

Function extract_call_name

src/extraction/complexity.rs:198–235  ·  view source on GitHub ↗

Extracts the method/function name from a call expression node. Tries the configured `method_field` first (e.g. "function", "method"), then falls back to common child patterns: last identifier before `(`, or a `field_expression`/`member_expression` selector.

(node: TsNode<'_>, method_field: &str, source: &[u8])

Source from the content-addressed store, hash-verified

196/// then falls back to common child patterns: last identifier before `(`,
197/// or a `field_expression`/`member_expression` selector.
198fn extract_call_name(node: TsNode<'_>, method_field: &str, source: &[u8]) -> Option<String> {
199 // Try the configured field name first.
200 if !method_field.is_empty() {
201 if let Some(field_node) = node.child_by_field_name(method_field) {
202 // For chained calls like `x.unwrap()`, the field may be a
203 // field_expression / member_expression — grab the rightmost identifier.
204 let text = rightmost_identifier(field_node, source);
205 if !text.is_empty() {
206 return Some(text);
207 }
208 }
209 }
210
211 // Fallback: scan direct children via cursor (O(N), not O(N²)).
212 let mut cursor = node.walk();
213 if cursor.goto_first_child() {
214 loop {
215 let child = cursor.node();
216 let ck = child.kind();
217 if ck == "identifier" || ck == "field_identifier" || ck == "property_identifier" {
218 if let Ok(text) = child.utf8_text(source) {
219 return Some(text.to_string());
220 }
221 }
222 // member_expression / field_expression: grab the property/field child.
223 if ck.contains("member_expression") || ck.contains("field_expression") {
224 let text = rightmost_identifier(child, source);
225 if !text.is_empty() {
226 return Some(text);
227 }
228 }
229 if !cursor.goto_next_sibling() {
230 break;
231 }
232 }
233 }
234 None
235}
236
237/// Extracts the macro name from a macro invocation node (e.g. `assert!`).
238///

Callers 3

extract_call_sitesMethod · 0.85
count_complexityFunction · 0.85
extract_call_sitesMethod · 0.85

Calls 4

rightmost_identifierFunction · 0.85
kindMethod · 0.80
is_emptyMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected