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

Method flush_value_refs

codegraph-kernel/src/go.rs:1361–1470  ·  view source on GitHub ↗
(&mut self, root: Node<'t>)

Source from the content-addressed store, hash-verified

1359 // --- value refs -------------------------------------------------------------------
1360
1361 fn flush_value_refs(&mut self, root: Node<'t>) {
1362 let scopes = std::mem::take(&mut self.value_scopes);
1363 let mut targets = std::mem::take(&mut self.fs_values);
1364 let counts = std::mem::take(&mut self.fs_value_counts);
1365 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1366 return;
1367 }
1368 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1369 return;
1370 }
1371
1372 // Shadow prune — Go declarator shapes: const_spec/var_spec (name =
1373 // first child) and short_var_declaration (left / expression_list).
1374 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1375 let mut bump = |decl_counts: &mut HashMap<&'t str, u32>, name_node: Option<Node<'t>>, src: &'t str, targets: &HashMap<String, u32>| {
1376 if let Some(n) = name_node {
1377 if matches!(n.kind(), "identifier" | "simple_identifier") {
1378 let nm = &src[n.byte_range()];
1379 if targets.contains_key(nm) {
1380 *decl_counts.entry(nm).or_insert(0) += 1;
1381 }
1382 }
1383 }
1384 };
1385 let mut dstack: Vec<Node> = vec![root];
1386 let mut dvisited = 0usize;
1387 while let Some(n) = dstack.pop() {
1388 if dvisited >= MAX_VALUE_REF_NODES {
1389 break;
1390 }
1391 dvisited += 1;
1392 match n.kind() {
1393 "const_spec" | "var_spec" => bump(&mut decl_counts, n.named_child(0), self.src, &targets),
1394 "short_var_declaration" => {
1395 let left = n
1396 .child_by_field_name("left")
1397 .or_else(|| n.child_by_field_name("pattern"))
1398 .or_else(|| n.named_child(0));
1399 if let Some(left) = left {
1400 if left.kind() == "identifier" {
1401 bump(&mut decl_counts, Some(left), self.src, &targets);
1402 } else {
1403 for i in 0..left.named_child_count() {
1404 bump(&mut decl_counts, left.named_child(i), self.src, &targets);
1405 }
1406 }
1407 }
1408 }
1409 _ => {}
1410 }
1411 for i in 0..n.named_child_count() {
1412 if let Some(c) = n.named_child(i) {
1413 dstack.push(c);
1414 }
1415 }
1416 }
1417 let shadowed: Vec<String> = decl_counts
1418 .iter()

Callers 1

extractFunction · 0.45

Calls 12

is_generated_fileFunction · 0.85
bumpFunction · 0.85
edge_kind_indexFunction · 0.85
pushMethod · 0.80
mapMethod · 0.80
push_edgeMethod · 0.80
getMethod · 0.65
textMethod · 0.65
putMethod · 0.65
unwrapMethod · 0.60
takeFunction · 0.50
collectMethod · 0.45

Tested by

no test coverage detected