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

Method extract_variable

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

466
467 /// extractVariable's python branch: `left = right` at module scope.
468 fn extract_variable(&mut self, node: Node<'t>) {
469 let docstring = preceding_docstring(node, self.src);
470 let left = node.child_by_field_name("left").or_else(|| node.named_child(0));
471 let right = node.child_by_field_name("right").or_else(|| node.named_child(1));
472 let Some(left) = left else { return };
473 if !matches!(left.kind(), "identifier" | "constant") {
474 return;
475 }
476 let name = self.text(left).to_string();
477 let signature = right.map(|r| util::init_signature(self.text(r)));
478 // No isConst hook ⇒ always `variable` (UPPER_CASE constants included).
479 self.create_node("variable", &name, node, Extra { docstring, signature, ..Extra::default() });
480 }
481
482 fn extract_import(&mut self, node: Node<'t>) {
483 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.45
create_nodeMethod · 0.45

Tested by

no test coverage detected