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

Method extract_variable

codegraph-kernel/src/python.rs:577–615  ·  view source on GitHub ↗

extractVariable's python branch: `left = right` at module scope. Returns the right-hand side when it was walked under the assigned name, for the declaration scan to skip.

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

575 /// Returns the right-hand side when it was walked under the assigned
576 /// name, for the declaration scan to skip.
577 fn extract_variable(&mut self, node: Node<'t>) -> Vec<usize> {
578 let docstring = preceding_docstring(node, self.src);
579 let left = node.child_by_field_name("left").or_else(|| node.named_child(0));
580 let right = node.child_by_field_name("right").or_else(|| node.named_child(1));
581 let mut assigned: Option<(u32, String)> = None;
582 if let Some(left) = left {
583 if matches!(left.kind(), "identifier" | "constant") {
584 let name = self.text(left).to_string();
585 let signature = right.map(|r| util::init_signature(self.text(r)));
586 // No isConst hook ⇒ always `variable` (UPPER_CASE constants included).
587 let row = self.create_node(
588 "variable",
589 &name,
590 node,
591 Extra { docstring, signature, ..Extra::default() },
592 );
593 if let Some(row) = row {
594 assigned = Some((row, name));
595 }
596 }
597 }
598 // Walk the initializer ATTRIBUTED to the assigned name (#693): a
599 // module-level `app = FastAPI()` / `handler = lambda: run()` dropped
600 // every call on the right-hand side. A tuple target mints no symbol, so
601 // its RHS is walked at the enclosing scope rather than lost.
602 let mut walked = Vec::new();
603 if let Some(right) = right {
604 match assigned {
605 Some((row, name)) => {
606 self.stack.push(Scope { row, kind: "variable", name });
607 self.visit_function_body(right);
608 self.stack.pop();
609 walked.push(right.id());
610 }
611 None => self.visit_function_body(right),
612 }
613 }
614 walked
615 }
616
617 fn extract_import(&mut self, node: Node<'t>) {
618 let import_text = self.text(node).trim().to_string();

Callers 1

visit_nodeMethod · 0.45

Calls 8

preceding_docstringFunction · 0.85
init_signatureFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
idMethod · 0.80
textMethod · 0.65
create_nodeMethod · 0.45
visit_function_bodyMethod · 0.45

Tested by

no test coverage detected