brokk_bifrost_python/graph/
hits.rs1use crate::graph::extractor::ScanCtx;
2use brokk_bifrost_core::analyzer::usages::common::{
3 insert_import_hit, insert_unproven_hit, reclassify_self_receiver_hit_at, usage_hit_for_node,
4};
5use tree_sitter::Node;
6
7pub fn record_hit(node: Node<'_>, ctx: &mut ScanCtx<'_>) {
8 if let Some(hit) = build_hit(node, ctx) {
9 ctx.hits.insert(hit);
10 }
11}
12
13pub fn record_unproven_hit(node: Node<'_>, ctx: &mut ScanCtx<'_>) {
14 let hit = build_hit(node, ctx);
15 insert_unproven_hit(ctx.unproven_hits, hit);
16}
17
18pub fn record_self_receiver_hit(node: Node<'_>, ctx: &mut ScanCtx<'_>) {
24 record_hit(node, ctx);
25 reclassify_self_receiver_hit_at(ctx.hits, ctx.file, node.start_byte(), node.end_byte());
26}
27
28pub fn record_import_hit(node: Node<'_>, ctx: &mut ScanCtx<'_>) {
32 let hit = build_hit(node, ctx);
33 insert_import_hit(ctx.hits, hit);
34}
35
36fn build_hit(
37 node: Node<'_>,
38 ctx: &mut ScanCtx<'_>,
39) -> Option<brokk_bifrost_core::analyzer::usages::model::UsageHit> {
40 usage_hit_for_node(node, ctx.file, ctx.source, ctx.line_starts, |range| {
41 ctx.graph.index.enclosing_code_unit(ctx.file, range)
42 })
43}