MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / visit_variable_declaration

Method visit_variable_declaration

src/extraction/zig_extractor.rs:174–213  ·  view source on GitHub ↗

Visit a `variable_declaration` node. In Zig, `const X = struct { ... }`, `const X = enum { ... }`, `const X = @import("...")`, and plain `const X: type = value` are all `variable_declaration` nodes. We dispatch based on the value child.

(state: &mut ExtractionState, node: TsNode<'_>)

Source from the content-addressed store, hash-verified

172 /// and plain `const X: type = value` are all `variable_declaration` nodes.
173 /// We dispatch based on the value child.
174 fn visit_variable_declaration(state: &mut ExtractionState, node: TsNode<'_>) {
175 // Get the name from the first identifier child.
176 let name = find_direct_child_by_kind(node, "identifier")
177 .map_or_else(|| "<anonymous>".to_string(), |n| state.node_text(n));
178
179 // Check what the value is: struct, enum, union, @import, or plain const.
180 // The value is typically the last named child that is not the type annotation.
181 let value_child = Self::find_value_child(node);
182
183 if let Some(val) = value_child {
184 match val.kind() {
185 "struct_declaration" => {
186 Self::visit_struct(state, node, val, &name);
187 return;
188 }
189 "enum_declaration" => {
190 Self::visit_enum(state, node, val, &name);
191 return;
192 }
193 "builtin_function" if Self::is_import_call(state, val) => {
194 Self::visit_import(state, node, val, &name);
195 return;
196 }
197 "field_expression" => {
198 // Handle `const mem = @import("std").mem` where the object
199 // of the field_expression is a builtin_function (@import).
200 if let Some(obj) = val.child_by_field_name("object") {
201 if obj.kind() == "builtin_function" && Self::is_import_call(state, obj) {
202 Self::visit_import(state, node, obj, &name);
203 return;
204 }
205 }
206 }
207 _ => {}
208 }
209 }
210
211 // Plain const (not struct/enum/import).
212 Self::visit_const(state, node, &name);
213 }
214
215 /// Find the "value" child of a `variable_declaration`.
216 ///

Callers

nothing calls this directly

Calls 3

kindMethod · 0.80
node_textMethod · 0.45

Tested by

no test coverage detected