extractVariable: C takes the dedicated branch (file-scope declarators, tree-sitter.ts:2795); cpp takes the TS GENERIC fallback (direct identifier children).
(&mut self, node: Node<'t>)
| 1130 | /// tree-sitter.ts:2795); cpp takes the TS GENERIC fallback (direct |
| 1131 | /// identifier children). |
| 1132 | fn extract_variable(&mut self, node: Node<'t>) { |
| 1133 | let is_const = self.variant == Variant::C && self.is_const_declaration(node); |
| 1134 | let kind: &'static str = if is_const { "constant" } else { "variable" }; |
| 1135 | let docstring = preceding_docstring(node, self.src); |
| 1136 | // isExported?.() ?? false — EXPLICIT false (tri-state flag set). |
| 1137 | let is_exported = Some(false); |
| 1138 | |
| 1139 | if self.variant == Variant::C { |
| 1140 | if has_function_ancestor(node) { |
| 1141 | return; |
| 1142 | } |
| 1143 | for i in 0..node.named_child_count() { |
| 1144 | let Some(child) = node.named_child(i) else { continue }; |
| 1145 | if !matches!( |
| 1146 | child.kind(), |
| 1147 | "init_declarator" | "pointer_declarator" | "array_declarator" |
| 1148 | ) { |
| 1149 | continue; |
| 1150 | } |
| 1151 | let Some(name_node) = c_declarator_identifier(child) else { continue }; |
| 1152 | let name = self.text(name_node); |
| 1153 | if name.is_empty() { |
| 1154 | continue; |
| 1155 | } |
| 1156 | let value_node = if child.kind() == "init_declarator" { |
| 1157 | child.child_by_field_name("value") |
| 1158 | } else { |
| 1159 | None |
| 1160 | }; |
| 1161 | let signature = value_node.map(|v| util::init_signature(self.text(v))); |
| 1162 | self.create_node( |
| 1163 | kind, |
| 1164 | name, |
| 1165 | child, |
| 1166 | Extra { |
| 1167 | docstring: docstring.clone(), |
| 1168 | signature, |
| 1169 | is_exported, |
| 1170 | ..Extra::default() |
| 1171 | }, |
| 1172 | ); |
| 1173 | } |
| 1174 | } else { |
| 1175 | // Generic fallback: direct identifier children only (`int x;` |
| 1176 | // extracts; `int x = 5;` nests in an init_declarator and does not). |
| 1177 | for i in 0..node.named_child_count() { |
| 1178 | let Some(child) = node.named_child(i) else { continue }; |
| 1179 | if child.kind() != "identifier" { |
| 1180 | continue; |
| 1181 | } |
| 1182 | let name = self.text(child).to_string(); |
| 1183 | if !name.is_empty() && name != "<anonymous>" { |
| 1184 | self.create_node( |
| 1185 | kind, |
| 1186 | &name, |
| 1187 | child, |
| 1188 | Extra { docstring: docstring.clone(), is_exported, ..Extra::default() }, |
| 1189 | ); |
no test coverage detected