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

Function sh_source

src/pipeline/pass_shell.c:3524–3570  ·  view source on GitHub ↗

The innermost Function around `line` in `file`, else its Module, else its * File node. Into `twins` (when given): every Function of exactly that * span, in QN order -- the targets of one Make rule share it, and the * rule's recipe runs for each of them. */

Source from the content-addressed store, hash-verified

3522 * span, in QN order -- the targets of one Make rule share it, and the
3523 * rule's recipe runs for each of them. */
3524static int64_t sh_source(cbm_pipeline_ctx_t *ctx, const sh_span_t *spans, int n,
3525 CBMHashTable *modules, const char *file, int line, sh_srcs_t *twins) {
3526 int lo = 0;
3527 int hi = n;
3528 while (lo < hi) {
3529 int mid = lo + (hi - lo) / PAIR_LEN;
3530 if (strcmp(spans[mid].file, file) < 0) {
3531 lo = mid + SKIP_ONE;
3532 } else {
3533 hi = mid;
3534 }
3535 }
3536 const cbm_gbuf_node_t *best = NULL;
3537 for (int i = lo; i < n && strcmp(spans[i].file, file) == 0; i++) {
3538 const cbm_gbuf_node_t *f = spans[i].node;
3539 if (f->start_line > line || f->end_line < line) {
3540 continue;
3541 }
3542 int w = f->end_line - f->start_line;
3543 int bw = best ? best->end_line - best->start_line : 0;
3544 if (!best || w < bw ||
3545 (w == bw && strcmp(f->qualified_name ? f->qualified_name : "",
3546 best->qualified_name ? best->qualified_name : "") < 0)) {
3547 best = f;
3548 }
3549 }
3550 if (best) {
3551 for (int i = lo; twins && i < n && strcmp(spans[i].file, file) == 0; i++) {
3552 const cbm_gbuf_node_t *f = spans[i].node;
3553 if (f->start_line == best->start_line && f->end_line == best->end_line &&
3554 sh_grow((void **)&twins->items, &twins->cap, twins->count, sizeof(*twins->items))) {
3555 twins->items[twins->count++] = f;
3556 }
3557 }
3558 if (twins && twins->count > SKIP_ONE) {
3559 qsort((void *)twins->items, (size_t)twins->count, sizeof(*twins->items),
3560 sh_cmp_node_qn);
3561 }
3562 return best->id;
3563 }
3564 int64_t mod = (int64_t)(intptr_t)cbm_ht_get(modules, file);
3565 if (mod > 0) {
3566 return mod;
3567 }
3568 const cbm_gbuf_node_t *fn = cbm_pipeline_file_node(ctx->gbuf, ctx->project_name, file);
3569 return fn ? fn->id : 0;
3570}
3571
3572/* The external Chart of `name` a helm command names: the hit keeps no
3573 * repository URL (a `repo/name` alias, an oci:// reference's last segment),

Callers 1

sh_linkFunction · 0.85

Calls 3

sh_growFunction · 0.85
cbm_ht_getFunction · 0.85
cbm_pipeline_file_nodeFunction · 0.85

Tested by

no test coverage detected