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

Function build_language

src/pipeline/doc_links.c:282–339  ·  view source on GitHub ↗

Build one language's index over this run's files of that language plus the * base scopes tagged for it. Returns false, with *why, when a scope cannot be * read or copied or the index cannot be built: the caller fails the layer. */

Source from the content-addressed store, hash-verified

280 * base scopes tagged for it. Returns false, with *why, when a scope cannot be
281 * read or copied or the index cannot be built: the caller fails the layer. */
282static bool build_language(cbm_doclinks_t *dl, int slot, const cbm_pipeline_ctx_t *ctx,
283 const cbm_file_info_t *files, int file_count, CBMFileResult **cache,
284 const cbm_doclink_scope_t *base, int base_count, const cbm_gbuf_t *graph,
285 const char **why) {
286 const cbm_doclink_resolver_t *R = DOCLINK_RESOLVERS[slot];
287 int cap = 0;
288 for (int i = 0; i < file_count; i++) {
289 cap += resolver_has_lang(R, files[i].language);
290 }
291 for (int i = 0; i < base_count; i++) {
292 cap += scope_has_tag(base[i].scope, R->scope_tag);
293 }
294 if (cap == 0) {
295 return true;
296 }
297 cbm_doclink_file_t *lf =
298 (cbm_doclink_file_t *)cbm_calloc(CBM_MEM_CLASS_OTHER, (size_t)cap * sizeof(*lf));
299 if (!lf) {
300 *why = "alloc";
301 return false;
302 }
303 const char *failed = NULL;
304 int n = 0;
305 for (int i = 0; i < file_count; i++) {
306 if (!resolver_has_lang(R, files[i].language)) {
307 continue;
308 }
309 const char *scope = run_file_scope(dl, ctx, cache, i, &failed);
310 lf[n++] =
311 (cbm_doclink_file_t){.rel_path = files[i].rel_path, .scope = scope, .run_file = i};
312 }
313 for (int i = 0; i < base_count; i++) {
314 if (!scope_has_tag(base[i].scope, R->scope_tag)) {
315 continue;
316 }
317 const char *rel_path = cbm_arena_strdup(&dl->arena, base[i].rel_path);
318 const char *scope = cbm_arena_strdup(&dl->arena, base[i].scope);
319 if (!rel_path || !scope) {
320 failed = "alloc";
321 }
322 lf[n++] =
323 (cbm_doclink_file_t){.rel_path = rel_path, .scope = scope, .run_file = CBM_NOT_FOUND};
324 }
325 if (failed) {
326 cbm_free(CBM_MEM_CLASS_OTHER, lf);
327 *why = failed;
328 return false;
329 }
330 qsort(lf, (size_t)n, sizeof(*lf), file_cmp);
331 cbm_doclink_build_in_t in = {
332 .ctx = ctx, .graph = graph, .files = lf, .file_count = n, .run_file_count = file_count};
333 dl->index[slot] = R->build(&in);
334 cbm_free(CBM_MEM_CLASS_OTHER, lf);
335 if (!dl->index[slot]) {
336 *why = "index";
337 }
338 return dl->index[slot] != NULL;
339}

Callers 1

cbm_doclinks_buildFunction · 0.85

Calls 6

resolver_has_langFunction · 0.85
scope_has_tagFunction · 0.85
cbm_callocFunction · 0.85
run_file_scopeFunction · 0.85
cbm_freeFunction · 0.85
cbm_arena_strdupFunction · 0.50

Tested by

no test coverage detected