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

Method hook_call

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

Source from the content-addressed store, hash-verified

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