(&mut self, root: Node<'t>)
| 1331 | // --- value refs ------------------------------------------------------------------- |
| 1332 | |
| 1333 | fn flush_value_refs(&mut self, root: Node<'t>) { |
| 1334 | let scopes = std::mem::take(&mut self.value_scopes); |
| 1335 | let mut targets = std::mem::take(&mut self.fs_values); |
| 1336 | let counts = std::mem::take(&mut self.fs_value_counts); |
| 1337 | if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 1338 | return; |
| 1339 | } |
| 1340 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 1341 | return; |
| 1342 | } |
| 1343 | |
| 1344 | // Shadow prune — Go declarator shapes: const_spec/var_spec (name = |
| 1345 | // first child) and short_var_declaration (left / expression_list). |
| 1346 | let mut decl_counts: HashMap<&str, u32> = HashMap::new(); |
| 1347 | let mut bump = |decl_counts: &mut HashMap<&'t str, u32>, name_node: Option<Node<'t>>, src: &'t str, targets: &HashMap<String, u32>| { |
| 1348 | if let Some(n) = name_node { |
| 1349 | if matches!(n.kind(), "identifier" | "simple_identifier") { |
| 1350 | let nm = &src[n.byte_range()]; |
| 1351 | if targets.contains_key(nm) { |
| 1352 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | }; |
| 1357 | let mut dstack: Vec<Node> = vec![root]; |
| 1358 | let mut dvisited = 0usize; |
| 1359 | while let Some(n) = dstack.pop() { |
| 1360 | if dvisited >= MAX_VALUE_REF_NODES { |
| 1361 | break; |
| 1362 | } |
| 1363 | dvisited += 1; |
| 1364 | match n.kind() { |
| 1365 | "const_spec" | "var_spec" => bump(&mut decl_counts, n.named_child(0), self.src, &targets), |
| 1366 | "short_var_declaration" => { |
| 1367 | let left = n |
| 1368 | .child_by_field_name("left") |
| 1369 | .or_else(|| n.child_by_field_name("pattern")) |
| 1370 | .or_else(|| n.named_child(0)); |
| 1371 | if let Some(left) = left { |
| 1372 | if left.kind() == "identifier" { |
| 1373 | bump(&mut decl_counts, Some(left), self.src, &targets); |
| 1374 | } else { |
| 1375 | for i in 0..left.named_child_count() { |
| 1376 | bump(&mut decl_counts, left.named_child(i), self.src, &targets); |
| 1377 | } |
| 1378 | } |
| 1379 | } |
| 1380 | } |
| 1381 | _ => {} |
| 1382 | } |
| 1383 | for i in 0..n.named_child_count() { |
| 1384 | if let Some(c) = n.named_child(i) { |
| 1385 | dstack.push(c); |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | let shadowed: Vec<String> = decl_counts |
| 1390 | .iter() |
no test coverage detected