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

Method require_module

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

requireModule (lua.ts:28-60).

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

Source from the content-addressed store, hash-verified

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