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

Method hook_call

codegraph-kernel/src/rlang.rs:328–411  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

326 }
327
328 fn hook_call(&mut self, node: Node<'t>) -> bool {
329 stack_guard!();
330 let fname = match self.callee_name(node) {
331 Some(f) => f,
332 None => return false,
333 };
334
335 // library(dplyr) / require(stats) / requireNamespace("jsonlite") /
336 // source("helpers.R") (r.ts:189-208). A dynamic/missing/empty first
337 // arg is consumed SILENTLY — nothing recorded, subtree never visited.
338 if is_import_fn(fname) || fname == "source" {
339 let module = match self.literal_or_identifier(self.first_arg_value(node)) {
340 Some(m) if !m.is_empty() => m,
341 _ => return true,
342 };
343 // signature: whole call text .trim().slice(0, 100) — UTF-16 slice.
344 // (A call node's text starts at the callee and ends at `)`, so
345 // trim() never has anything to strip on reachable inputs.)
346 let (sig, _) = util::slice_utf16(self.text(node).trim(), 100);
347 let module = module.to_string();
348 let imp = self.create_node("import", &module, node, Some(&sig));
349 if imp.is_some() && !self.stack.is_empty() {
350 let parent_row = self.top_row();
351 self.push_ref_at(parent_row, &module, "imports", node);
352 }
353 return true;
354 }
355
356 // setClass("Patient", …) / setRefClass / R6Class / ggproto
357 // (r.ts:211-221). A falsy name FALLS THROUGH to the generic call —
358 // `ggproto(NULL, Geom, …)` emits `calls ggproto` + file-scope body
359 // leak (asymmetric with imports, preserved).
360 if is_class_fn(fname) {
361 let name = match self.literal_or_identifier(self.first_arg_value(node)) {
362 Some(n) if !n.is_empty() => n.to_string(),
363 _ => return false,
364 };
365 if let Some(cls_row) = self.create_node("class", &name, node, None) {
366 self.stack.push(Scope { row: cls_row, kind: "class", name });
367 self.extract_class_members(node, cls_row);
368 self.stack.pop();
369 }
370 return true;
371 }
372
373 // setGeneric("describe", …) / setMethod("describe", "Patient", fn)
374 // (r.ts:224-249): function node named by the first arg; signature and
375 // body from the FIRST argument (any position) whose value is a
376 // function_definition.
377 if is_generic_fn(fname) {
378 let name = match self.literal_or_identifier(self.first_arg_value(node)) {
379 Some(n) if !n.is_empty() => n.to_string(),
380 _ => return false,
381 };
382 let mut impl_node: Option<Node<'t>> = None;
383 if let Some(args) = node.child_by_field_name("arguments") {
384 let mut cursor = args.walk();
385 for a in args.named_children(&mut cursor) {

Callers 1

hookMethod · 0.80

Calls 15

is_import_fnFunction · 0.85
slice_utf16Function · 0.85
is_class_fnFunction · 0.85
is_generic_fnFunction · 0.85
literal_or_identifierMethod · 0.80
first_arg_valueMethod · 0.80
pushMethod · 0.80
extract_class_membersMethod · 0.80
walkMethod · 0.80
mapMethod · 0.80
textMethod · 0.65
callee_nameMethod · 0.45

Tested by

no test coverage detected