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

Method extract_variable

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

extractVariable's python branch: `left = right` at module scope.

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

Source from the content-addressed store, hash-verified

472
473 /// extractVariable's python branch: `left = right` at module scope.
474 fn extract_variable(&mut self, node: Node<'t>) {
475 let docstring = preceding_docstring(node, self.src);
476 let left = node.child_by_field_name("left").or_else(|| node.named_child(0));
477 let right = node.child_by_field_name("right").or_else(|| node.named_child(1));
478 let Some(left) = left else { return };
479 if !matches!(left.kind(), "identifier" | "constant") {
480 return;
481 }
482 let name = self.text(left).to_string();
483 let signature = right.map(|r| util::init_signature(self.text(r)));
484 // No isConst hook ⇒ always `variable` (UPPER_CASE constants included).
485 self.create_node("variable", &name, node, Extra { docstring, signature, ..Extra::default() });
486 }
487
488 fn extract_import(&mut self, node: Node<'t>) {
489 let import_text = self.text(node).trim().to_string();

Callers 1

visit_nodeMethod · 0.45

Calls 4

preceding_docstringFunction · 0.85
init_signatureFunction · 0.85
textMethod · 0.65
create_nodeMethod · 0.45

Tested by

no test coverage detected