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

Method extract_variable

codegraph-kernel/src/python.rs:579–617  ·  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

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