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

Method hook_binary_operator

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

Source from the content-addressed store, hash-verified

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