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

Function node_resolution_score

src/mcp/mcp.c:9107–9132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9105 RES_LABEL_WEIGHT = 1000000 /* label tier dominates span */
9106};
9107static long node_resolution_score(const cbm_node_t *n) {
9108 long label_rank = RES_RANK_MODULE;
9109 if (n->label) {
9110 if (strcmp(n->label, "Function") == 0 || strcmp(n->label, "Method") == 0) {
9111 label_rank = RES_RANK_CALLABLE;
9112 } else if (strcmp(n->label, "Module") != 0 && strcmp(n->label, "File") != 0) {
9113 label_rank = RES_RANK_OTHER;
9114 }
9115 }
9116 /* Tie rule (CBM_MACRO_QN_SUFFIX): a name that is both a definition and a C
9117 * macro -- a typedef or enumerator next to its rename macro -- resolves to
9118 * the definition. The macro scores just under every other definition, and
9119 * still above Module/File; without this a one-line typedef and its macro
9120 * tie on span and the name reads as ambiguous. */
9121 size_t qn_len = n->qualified_name ? strlen(n->qualified_name) : 0;
9122 size_t fence_len = sizeof(CBM_MACRO_QN_SUFFIX) - SKIP_ONE;
9123 if (label_rank == RES_RANK_OTHER && qn_len > fence_len &&
9124 strcmp(n->qualified_name + qn_len - fence_len, CBM_MACRO_QN_SUFFIX) == 0) {
9125 return RES_RANK_OTHER * (long)RES_LABEL_WEIGHT - SKIP_ONE;
9126 }
9127 long span = (long)n->end_line - (long)n->start_line;
9128 if (span < 0) {
9129 span = 0;
9130 }
9131 return label_rank * (long)RES_LABEL_WEIGHT + span;
9132}
9133
9134/* A "real" callable definition: a Function/Method node with a non-empty body
9135 * span (end_line > start_line). A body-less node (start_line == end_line) is an

Callers 1

pick_resolved_nodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected