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

Function pp_add_file_doc

src/pipeline/pass_parallel.c:1811–1838  ·  view source on GitHub ↗

Add a file's own doc (Go package comment, Rust inner docs) to its File * node as "docstring". Twin of pass_definitions.c -- keep both in sync. */

Source from the content-addressed store, hash-verified

1809/* Add a file's own doc (Go package comment, Rust inner docs) to its File
1810 * node as "docstring". Twin of pass_definitions.c -- keep both in sync. */
1811static void pp_add_file_doc(const cbm_gbuf_node_t *file_node, const char *doc) {
1812 if (!file_node || !doc || !doc[0]) {
1813 return;
1814 }
1815 const char *old = file_node->properties_json ? file_node->properties_json : "{}";
1816 size_t olen = strlen(old);
1817 if (olen < PAIR_LEN || old[olen - SKIP_ONE] != '}') {
1818 return; /* not a JSON object -- leave it untouched */
1819 }
1820 size_t cap = olen + strlen("docstring") + pp_json_escaped_len(doc) + PP_JSON_FIELD_OVERHEAD +
1821 PP_ESC_SPACE + SKIP_ONE;
1822 char *neu = cbm_alloc(CBM_MEM_CLASS_GBUF_STRING, cap);
1823 if (!neu) {
1824 return;
1825 }
1826 size_t pos = olen - SKIP_ONE; /* without the closing brace */
1827 memcpy(neu, old, pos);
1828 neu[pos] = '\0';
1829 append_json_string(neu, cap, &pos, "docstring", doc);
1830 if (olen == PAIR_LEN && pos > PAIR_LEN) { /* "{}": drop the leading comma */
1831 memmove(neu + SKIP_ONE, neu + PAIR_LEN, pos - SKIP_ONE);
1832 pos--;
1833 }
1834 neu[pos++] = '}';
1835 neu[pos] = '\0';
1836 (void)cbm_gbuf_node_set_properties_json((cbm_gbuf_node_t *)file_node, neu);
1837 cbm_free(CBM_MEM_CLASS_GBUF_STRING, neu);
1838}
1839
1840/* Create IMPORTS edges for one file's imports (parallel path). */
1841static int create_imports_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *result,

Callers 1

Calls 5

pp_json_escaped_lenFunction · 0.85
cbm_allocFunction · 0.85
cbm_freeFunction · 0.85
append_json_stringFunction · 0.70

Tested by

no test coverage detected