MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / require_module

Method require_module

codegraph-kernel/src/lua.rs:301–338  ·  view source on GitHub ↗

requireModule (lua.ts:28-60).

(&self, call: Node<'t>)

Source from the content-addressed store, hash-verified

299
300 /// requireModule (lua.ts:28-60).
301 fn require_module(&self, call: Node<'t>) -> Option<String> {
302 let name = call.child_by_field_name("name")?;
303 if name.kind() != "identifier" || self.text(name) != "require" {
304 return None;
305 }
306 let args = call.child_by_field_name("arguments")?;
307
308 // String win: first string_content descendant, BFS order.
309 if let Some(content) = self.find_descendant(args, "string_content") {
310 let t = self.text(content).trim();
311 return if t.is_empty() { None } else { Some(t.to_string()) };
312 }
313 // Fallback: a string node with no content child — strip [[ ]] / quotes.
314 if let Some(s) = self.find_descendant(args, "string") {
315 let mut t = self.text(s).trim();
316 t = t.strip_prefix("[[").unwrap_or(t);
317 t = t.strip_suffix("]]").unwrap_or(t);
318 t = t.strip_prefix(['"', '\'']).unwrap_or(t);
319 t = t.strip_suffix(['"', '\'']).unwrap_or(t);
320 if !t.is_empty() {
321 return Some(t.to_string());
322 }
323 }
324 // Roblox instance path: trailing field/method segment.
325 let idx = self
326 .find_descendant(args, "dot_index_expression")
327 .or_else(|| self.find_descendant(args, "method_index_expression"));
328 if let Some(idx) = idx {
329 if let Some(field) = idx
330 .child_by_field_name("field")
331 .or_else(|| idx.child_by_field_name("method"))
332 {
333 let t = self.text(field).trim();
334 return if t.is_empty() { None } else { Some(t.to_string()) };
335 }
336 }
337 None
338 }
339
340 /// The hook's `emit` (lua.ts:108-126): import node at the CALL node +
341 /// imports ref from the stack top.

Callers 1

visitMethod · 0.80

Calls 2

find_descendantMethod · 0.80
textMethod · 0.65

Tested by

no test coverage detected