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

Method hook_binary_operator

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

Source from the content-addressed store, hash-verified

411 }
412
413 fn hook_binary_operator(&mut self, node: Node<'t>) -> bool {
414 stack_guard!();
415 let op = match node.child_by_field_name("operator") {
416 Some(o) => self.text(o),
417 None => return false,
418 };
419 let lhs = node.child_by_field_name("lhs");
420 let rhs = node.child_by_field_name("rhs");
421
422 // name <- function(…) — ANY scope (r.ts:267-279). Body walked through
423 // the hook-aware visit (visitFunctionBody never runs for R).
424 if is_assign_left(op) {
425 if let (Some(lhs), Some(rhs)) = (lhs, rhs) {
426 if lhs.kind() == "identifier" && rhs.kind() == "function_definition" {
427 let params_text = rhs.child_by_field_name("parameters").map(|p| self.text(p));
428 let name = self.text(lhs).to_string();
429 let fn_row = self.create_node("function", &name, node, params_text);
430 let body = rhs.child_by_field_name("body");
431 if let (Some(row), Some(body)) = (fn_row, body) {
432 self.stack.push(Scope { row, kind: "function", name });
433 self.visit(body);
434 self.stack.pop();
435 }
436 return true;
437 }
438 }
439 }
440
441 let top_level = node.parent().map(|p| p.kind() == "program").unwrap_or(false);
442
443 // Top-level value assignments → variable/constant (r.ts:284-296);
444 // the class-definition idiom suppresses the twin variable node but the
445 // rhs is ALWAYS visited.
446 if top_level && is_assign_left(op) {
447 if let (Some(lhs), Some(rhs)) = (lhs, rhs) {
448 if lhs.kind() == "identifier" {
449 let rhs_callee = if rhs.kind() == "call" { self.callee_name(rhs) } else { None };
450 let suppressed = rhs_callee
451 .map(|c| is_class_fn(c) || is_generic_fn(c))
452 .unwrap_or(false);
453 if !suppressed {
454 let name = self.text(lhs);
455 let kind = if constant_name_re().is_match(name) { "constant" } else { "variable" };
456 self.create_node(kind, name, node, None);
457 }
458 self.visit(rhs);
459 return true;
460 }
461 }
462 }
463
464 // value -> name / value ->> name (r.ts:298-303).
465 if top_level && is_assign_right(op) {
466 if let (Some(lhs), Some(rhs)) = (lhs, rhs) {
467 if rhs.kind() == "identifier" {
468 let name = self.text(rhs);
469 let kind = if constant_name_re().is_match(name) { "constant" } else { "variable" };
470 self.create_node(kind, name, node, None);

Callers 1

hookMethod · 0.80

Calls 11

is_assign_leftFunction · 0.85
is_class_fnFunction · 0.85
is_generic_fnFunction · 0.85
constant_name_reFunction · 0.85
is_assign_rightFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
textMethod · 0.65
create_nodeMethod · 0.45
visitMethod · 0.45
callee_nameMethod · 0.45

Tested by

no test coverage detected