Resolve calls for one file and emit CALLS/HTTP_CALLS/ASYNC_CALLS edges. */
| 2255 | |
| 2256 | /* Resolve calls for one file and emit CALLS/HTTP_CALLS/ASYNC_CALLS edges. */ |
| 2257 | static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CBMFileResult *result, |
| 2258 | const char *rel, const char *module_qn, const char **imp_keys, |
| 2259 | const char **imp_vals, int imp_count, CBMLanguage lang) { |
| 2260 | /* Two occurrence-aware indexes preserve the authoritative matcher's |
| 2261 | * primary ordering without restoring its O(calls × resolutions) scan: |
| 2262 | * exact caller+leaf+span first, then the legacy caller+leaf fallback. |
| 2263 | * Repeated same-leaf calls therefore remain O(1), and a high-confidence |
| 2264 | * 0:0 record can never hide an exact source occurrence. */ |
| 2265 | CBMHashTable *lsp_exact_idx = NULL; |
| 2266 | CBMHashTable *lsp_legacy_idx = NULL; |
| 2267 | bool lsp_exact_idx_complete = true; |
| 2268 | bool lsp_legacy_idx_complete = true; |
| 2269 | bool allow_tail = cbm_pipeline_lsp_allow_tail_match(lang); |
| 2270 | if (result->calls.count > 0 && result->resolved_calls.count > 0) { |
| 2271 | uint32_t capacity = (uint32_t)result->resolved_calls.count * 2u + 16u; |
| 2272 | lsp_exact_idx = cbm_ht_create(capacity); |
| 2273 | lsp_legacy_idx = cbm_ht_create(capacity); |
| 2274 | if (!lsp_exact_idx) { |
| 2275 | lsp_exact_idx_complete = false; |
| 2276 | } |
| 2277 | if (!lsp_legacy_idx) { |
| 2278 | lsp_legacy_idx_complete = false; |
| 2279 | } |
| 2280 | if (lsp_exact_idx || lsp_legacy_idx) { |
| 2281 | for (int i = 0; i < result->resolved_calls.count; i++) { |
| 2282 | CBMResolvedCall *rc_e = &result->resolved_calls.items[i]; |
| 2283 | if (rc_e->kind != CBM_RESOLVED_INVOCATION || !rc_e->caller_qn || !rc_e->callee_qn || |
| 2284 | rc_e->confidence < CBM_LSP_CONFIDENCE_FLOOR) { |
| 2285 | continue; |
| 2286 | } |
| 2287 | bool exact_site = |
| 2288 | cbm_pipeline_source_site_present(rc_e->site_start_byte, rc_e->site_end_byte); |
| 2289 | bool legacy_site = |
| 2290 | cbm_pipeline_source_site_legacy(rc_e->site_start_byte, rc_e->site_end_byte); |
| 2291 | if (!exact_site && !legacy_site) { |
| 2292 | continue; |
| 2293 | } |
| 2294 | CBMHashTable *index = exact_site ? lsp_exact_idx : lsp_legacy_idx; |
| 2295 | bool inserted = |
| 2296 | lsp_idx_insert_leaf(index, rc_e, cbm_lsp_bare_segment(rc_e->callee_qn), |
| 2297 | exact_site, rc->main_gbuf, rc->project_name, allow_tail); |
| 2298 | if (!inserted) { |
| 2299 | if (exact_site) { |
| 2300 | lsp_exact_idx_complete = false; |
| 2301 | } else { |
| 2302 | lsp_legacy_idx_complete = false; |
| 2303 | } |
| 2304 | } |
| 2305 | if (rc_e->reason && cbm_pipeline_invocation_reason_join_strategy(rc_e->strategy)) { |
| 2306 | inserted = lsp_idx_insert_leaf(index, rc_e, cbm_lsp_bare_segment(rc_e->reason), |
| 2307 | exact_site, rc->main_gbuf, rc->project_name, |
| 2308 | allow_tail); |
| 2309 | if (!inserted) { |
| 2310 | if (exact_site) { |
| 2311 | lsp_exact_idx_complete = false; |
| 2312 | } else { |
| 2313 | lsp_legacy_idx_complete = false; |
| 2314 | } |
no test coverage detected