Skip to main content

brokk_bifrost_python/graph/
hits.rs

1use 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
18/// Record `node` as a same-owner self/cls receiver hit (#1014 facet B): a
19/// `self.member` / `cls.member` access whose receiver is the current instance /
20/// own class. Excluded from the external usage surface, counted as a same-owner
21/// site. Records the ordinary hit, then reclassifies it — the shared scan
22/// consumer, so the record ceremony lives in exactly one place.
23pub 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
28/// Record `node` as an `Import`-binding hit (the token that brings the symbol
29/// into this file), which the IDE find-references surface includes but the
30/// call-graph surfaces ignore.
31pub 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}