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

Method extract_variable

codegraph-kernel/src/rustlang.rs:730–778  ·  view source on GitHub ↗

extractVariable's generic fallback: kind is ALWAYS `variable` (no isConst hook), every direct `identifier` child mints a node positioned at the CHILD, docstring shared, isExported present-false, no signature. The initializer is walked under the declared symbol (#693), and returned then for the declaration scan to skip.

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

Source from the content-addressed store, hash-verified

728 /// The initializer is walked under the declared symbol (#693), and returned
729 /// then for the declaration scan to skip.
730 fn extract_variable(&mut self, node: Node<'t>) -> Vec<usize> {
731 let docstring = preceding_docstring(node, self.src);
732 let name_field = node.child_by_field_name("name");
733 // An impl's associated const is its type's (`Limits::MAX`), as its methods are.
734 let owner = self.impl_item_owner(node);
735 let mut declared: Option<(u32, String)> = None;
736 for child in node.named_children(&mut node.walk()) {
737 if child.kind() != "identifier" {
738 continue;
739 }
740 let name = self.text(child).to_string();
741 if !name.is_empty() {
742 let row = self.create_node(
743 "variable",
744 &name,
745 child,
746 Extra {
747 docstring: docstring.clone(),
748 is_exported: Some(false),
749 qualified_name: owner.as_ref().map(|o| format!("{o}::{name}")),
750 ..Extra::default()
751 },
752 );
753 if let (Some(row), Some(nf)) = (row, name_field) {
754 if child.start_byte() == nf.start_byte() {
755 declared = Some((row, name));
756 }
757 }
758 }
759 }
760 // Walk the initializer ATTRIBUTED to the declared symbol (#693):
761 // `const N: usize = compute()` and
762 // `static REGISTRY: Lazy<T> = Lazy::new(|| build())` dropped every call
763 // inside the initializer, so a handler table or a lazily-built
764 // singleton linked to nothing.
765 let mut walked = Vec::new();
766 if let Some(value) = node.child_by_field_name("value") {
767 match declared {
768 Some((row, name)) => {
769 self.stack.push(Scope { row, kind: "variable", name });
770 self.visit_function_body(value);
771 self.stack.pop();
772 walked.push(value.id());
773 }
774 None => self.visit_function_body(value),
775 }
776 }
777 walked
778 }
779
780 /// extractImport via the rust hook: import node named by the ROOT module +
781 /// one generic root `imports` ref + per-binding FULL-path refs.

Callers 1

visit_nodeMethod · 0.45

Calls 9

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

Tested by

no test coverage detected