MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / resolve_import_map

Function resolve_import_map

src/pipeline/registry.c:1350–1435  ·  view source on GitHub ↗

Callback context for import_map_suffix scan */ Strategy 1: Import map lookup (exact → suffix fallback) */

Source from the content-addressed store, hash-verified

1348/* Callback context for import_map_suffix scan */
1349/* Strategy 1: Import map lookup (exact → suffix fallback) */
1350static cbm_resolution_t resolve_import_map(const cbm_registry_t *r, const char *prefix,
1351 const char *suffix, const char **keys, const char **vals,
1352 int map_count) {
1353 if (!keys || !vals || map_count <= 0) {
1354 return empty_result();
1355 }
1356
1357 /* Find prefix in import map keys. Prefer the per-file TLS hash
1358 * cache (O(1)) over the linear scan when available. */
1359 const char *resolved = NULL;
1360 if (_import_map_cache) {
1361 resolved = (const char *)cbm_ht_get(_import_map_cache, prefix);
1362 } else {
1363 for (int i = 0; i < map_count; i++) {
1364 if (strcmp(keys[i], prefix) == 0) {
1365 resolved = vals[i];
1366 break;
1367 }
1368 }
1369 }
1370 if (!resolved) {
1371 return empty_result();
1372 }
1373
1374 /* Build candidate: resolved.suffix or resolved.prefix.
1375 * When the callee has a dot ("pkg.Func"), prefix="pkg" is the import key
1376 * and suffix="Func" is the function name, so the target QN is
1377 * resolved.Func. When the callee is bare ("requireAdmin"), prefix IS the
1378 * function name and suffix is NULL, so the target QN must be
1379 * resolved.requireAdmin — not just resolved, which would point at the
1380 * module node and miss the function entirely. */
1381 /* Direct hit ONLY for suffix-less callees (an aliased direct-symbol
1382 * import called bare: `from m import f as g; g()` — #875/#979; Yui
1383 * `import execute as bridge_execute`). With a suffix present
1384 * (`imported.method()`), returning the bare base here would swallow
1385 * the suffix and bind the call to the imported symbol's own node
1386 * (a Variable/Class/module) instead of base.method — exactly the
1387 * mis-resolution the comment above warns about. That regressed
1388 * django-scale graphs by ~11K CALLS/TESTS edges (Signal.send calls
1389 * degraded to edges onto the signal variables themselves). #1000 */
1390 if (!suffix || !suffix[0]) {
1391 const char *direct = cbm_ht_get_key(r->exact, resolved);
1392 if (direct) {
1393 return (cbm_resolution_t){direct, "import_map", CONF_IMPORT_MAP, REG_RESOLVED};
1394 }
1395 }
1396 char candidate[CBM_SZ_512];
1397 if (suffix && suffix[0]) {
1398 snprintf(candidate, sizeof(candidate), "%s.%s", resolved, suffix);
1399 } else {
1400 snprintf(candidate, sizeof(candidate), "%s.%s", resolved, prefix);
1401 }
1402 /* Use cbm_ht_get_key to get the persistent heap-owned key string */
1403 const char *stored_key = cbm_ht_get_key(r->exact, candidate);
1404 if (stored_key) {
1405 return (cbm_resolution_t){stored_key, "import_map", CONF_IMPORT_MAP, REG_RESOLVED};
1406 }
1407

Callers 1

registry_resolve_chainFunction · 0.85

Calls 4

empty_resultFunction · 0.85
cbm_ht_getFunction · 0.85
cbm_ht_get_keyFunction · 0.85
simple_nameFunction · 0.85

Tested by

no test coverage detected