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

Method extract_require_module

src/extraction/lua_extractor.rs:433–457  ·  view source on GitHub ↗

Extract the module name from a `require("module")` call. Looks for the first string argument inside the arguments node.

(state: &ExtractionState, call_node: TsNode<'_>)

Source from the content-addressed store, hash-verified

431 ///
432 /// Looks for the first string argument inside the arguments node.
433 fn extract_require_module(state: &ExtractionState, call_node: TsNode<'_>) -> Option<String> {
434 let args = call_node
435 .child_by_field_name("arguments")
436 .or_else(|| find_direct_child_by_kind(call_node, "arguments"))?;
437 // Look for a string node inside arguments.
438 let mut cursor = args.walk();
439 if cursor.goto_first_child() {
440 loop {
441 let child = cursor.node();
442 if child.kind() == "string" {
443 // The string node contains a string_content child.
444 if let Some(content) = find_direct_child_by_kind(child, "string_content") {
445 return Some(state.node_text(content));
446 }
447 // Fall back to stripping quotes from the full text.
448 let text = state.node_text(child);
449 return Some(text.trim_matches(|c| c == '"' || c == '\'').to_string());
450 }
451 if !cursor.goto_next_sibling() {
452 break;
453 }
454 }
455 }
456 None
457 }
458
459 /// Extract the function signature (first line of the definition).
460 fn extract_function_signature(

Callers

nothing calls this directly

Calls 3

kindMethod · 0.80
node_textMethod · 0.45

Tested by

no test coverage detected