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

Method extract_variable

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

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