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

Function cbm_doclinks_extract

internal/cbm/doclink.c:524–587  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

522}
523
524void cbm_doclinks_extract(CBMExtractCtx *ctx) {
525 if (!ctx || !ctx->result) {
526 return;
527 }
528 const doclink_lang_t *L = doclink_lang(ctx->language);
529 if (!L) {
530 return;
531 }
532 if (L->scan_file) {
533 L->scan_file(ctx);
534 return;
535 }
536 if (!L->parse_doc) { /* a scope, and no references (Python) */
537 ctx->result->doc_scope = L->scan_scope ? L->scan_scope(ctx) : NULL;
538 return;
539 }
540 int twin_count = 0;
541 doclink_twin_key_t *twins = L->twin_label ? twin_keys(ctx, L->twin_of, &twin_count) : NULL;
542 CBMDefArray *defs = &ctx->result->defs;
543 for (int i = 0; i < defs->count; i++) {
544 const CBMDefinition *d = &defs->items[i];
545 if (!d->docstring || !d->docstring[0] || !d->qualified_name || !d->name) {
546 continue;
547 }
548 if (twins && d->label && strcmp(d->label, L->twin_label) == 0) {
549 doclink_twin_key_t key = {d->start_line, d->name};
550 if (bsearch(&key, twins, (size_t)twin_count, sizeof(twins[0]), twin_key_cmp)) {
551 /* the Field twin carries these references -- and so those of
552 * the declarators after it, which share this doc text */
553 doc_line_ent_t *taken = doc_info_of(ctx, d->docstring);
554 if (taken) {
555 taken->parsed = true;
556 }
557 continue;
558 }
559 }
560 doc_line_ent_t *info = doc_info_of(ctx, d->docstring);
561 uint32_t doc_line = info ? info->line : 0;
562 bool csharp = ctx->language == CBM_LANG_CSHARP;
563 if (csharp && info && info->parsed) {
564 /* One C# doc comment documents every declarator of a field
565 * declaration (`int a, b, c;` share its text, extract_defs.c): its
566 * references are taken once, from the first declarator. Taken
567 * again per declarator, the tokens, their resolutions and the
568 * rows grow with references x declarators. */
569 continue;
570 }
571 if (csharp) {
572 if (!cbm_doclink_cs_parse_doc_checked(ctx, d, d->docstring,
573 doc_line ? doc_line : d->start_line)) {
574 ctx->result->doc_links.failed = true; /* a reference value was lost */
575 }
576 } else {
577 L->parse_doc(ctx, d, d->docstring, doc_line ? doc_line : d->start_line);
578 }
579 if (info) {
580 info->parsed = true;
581 }

Callers 1

extract_file_ex_bodyFunction · 0.85

Calls 5

doclink_langFunction · 0.85
twin_keysFunction · 0.85
doc_info_ofFunction · 0.85
doclink_file_passFunction · 0.85

Tested by

no test coverage detected