Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

style: apply clang-format-20 across tree

Martin Vogel7a6a8cb7a579
diff --git a/internal/cbm/cbm.c b/internal/cbm/cbm.c
index f46e87ceb..7a7fa95be 100644
--- a/internal/cbm/cbm.c
+++ b/internal/cbm/cbm.c
@@ -376,13 +376,15 @@ CBMFileResult *cbm_extract_file(const char *source, int source_len, CBMLanguage
bool jsx_mode = (language == CBM_LANG_TSX);
if (language == CBM_LANG_JAVASCRIPT && rel_path) {
size_t rl = strlen(rel_path);
- if (rl >= 4 && strcmp(rel_path + rl - 4, ".jsx") == 0) jsx_mode = true;
+ if (rl >= 4 && strcmp(rel_path + rl - 4, ".jsx") == 0)
+ jsx_mode = true;
}
// dts_mode: ".d.ts" suffix (TypeScript only).
bool dts_mode = false;
if (language == CBM_LANG_TYPESCRIPT && rel_path) {
size_t rl = strlen(rel_path);
- if (rl >= 5 && strcmp(rel_path + rl - 5, ".d.ts") == 0) dts_mode = true;
+ if (rl >= 5 && strcmp(rel_path + rl - 5, ".d.ts") == 0)
+ dts_mode = true;
}
cbm_run_ts_lsp(a, result, source, source_len, root, js_mode, jsx_mode, dts_mode);
}
diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.c
index a70502d7f..0badf261b 100644
--- a/internal/cbm/extract_defs.c
+++ b/internal/cbm/extract_defs.c
@@ -1181,8 +1181,7 @@ static const char **extract_base_classes(CBMArena *a, TSNode node, const char *s
for (const char **f = fields; *f; f++) {
TSNode super = ts_node_child_by_field_name(node, *f, (uint32_t)strlen(*f));
if (!ts_node_is_null(super)) {
- base_count += collect_bases_from_field(a, super, source,
- bases + base_count,
+ base_count += collect_bases_from_field(a, super, source, bases + base_count,
MAX_BASES_MINUS_1 - base_count);
}
}
@@ -3284,7 +3283,8 @@ static void extract_variables(CBMExtractCtx *ctx, TSNode root, const CBMLangSpec
extract_var_names(ctx, inner, spec);
}
}
- // Also check if the wrapper itself is a variable type (e.g., PHP expression_statement)
+ // Also check if the wrapper itself is a variable type (e.g., PHP
+ // expression_statement)
if (cbm_kind_in_set(child, spec->variable_node_types)) {
extract_var_names(ctx, child, spec);
}
@@ -3373,7 +3373,8 @@ static void extract_class_fields(CBMExtractCtx *ctx, TSNode class_node, const ch
* For the nested case, the child has no "type" field directly. Detect by
* walking named children for a variable_declaration. */
TSNode type_node = ts_node_child_by_field_name(child, TS_FIELD("type"));
- TSNode name_node = ts_node_is_null(type_node) ? (TSNode){0} : resolve_field_name_node(child);
+ TSNode name_node =
+ ts_node_is_null(type_node) ? (TSNode){0} : resolve_field_name_node(child);
if (ts_node_is_null(type_node)) {
uint32_t cnc = ts_node_named_child_count(child);
diff --git a/internal/cbm/extract_imports.c b/internal/cbm/extract_imports.c
index ea286e4ab..6295fb327 100644
--- a/internal/cbm/extract_imports.c
+++ b/internal/cbm/extract_imports.c
@@ -1,7 +1,7 @@
#include "cbm.h"
#include "arena.h" // CBMArena, cbm_arena_strdup/strndup/sprintf
#include "helpers.h"
-#include "lang_specs.h" // CBMLangSpec, CBMEmbeddedLangSpec, cbm_lang_spec, cbm_ts_language
+#include "lang_specs.h" // CBMLangSpec, CBMEmbeddedLangSpec, cbm_lang_spec, cbm_ts_language
#include "tree_sitter/api.h" // TSNode, ts_node_*
#include "foundation/constants.h"
#include "extract_node_stack.h"
diff --git a/internal/cbm/extract_node_stack.h b/internal/cbm/extract_node_stack.h
index fd70cb95c..d112ccc2f 100644
--- a/internal/cbm/extract_node_stack.h
+++ b/internal/cbm/extract_node_stack.h
@@ -34,7 +34,8 @@ static inline void ts_nstack_push(TSNodeStack *s, CBMArena *arena, TSNode node)
if (s->count >= s->cap) {
int new_cap = s->cap ? s->cap * 2 : 512;
TSNode *new_items = (TSNode *)cbm_arena_alloc(arena, (size_t)new_cap * sizeof(TSNode));
- if (!new_items) return; /* OOM: best-effort, stop growing */
+ if (!new_items)
+ return; /* OOM: best-effort, stop growing */
if (s->items && s->count > 0) {
memcpy(new_items, s->items, (size_t)s->count * sizeof(TSNode));
}
diff --git a/internal/cbm/helpers.c b/internal/cbm/helpers.c
index 6a44425b0..8dad0813b 100644
--- a/internal/cbm/helpers.c
+++ b/internal/cbm/helpers.c
@@ -760,8 +760,10 @@ static char *append_path_segments(char *out, const char *rel_path, size_t plen,
}
char *cbm_fqn_compute(CBMArena *a, const char *project, const char *rel_path, const char *name) {
- if (!project) project = "";
- if (!rel_path) rel_path = "";
+ if (!project)
+ project = "";
+ if (!rel_path)
+ rel_path = "";
size_t proj_len = strlen(project);
size_t path_len = strlen(rel_path);
size_t name_len = name ? strlen(name) : 0;
diff --git a/internal/cbm/lang_specs.c b/internal/cbm/lang_specs.c
index 90627b029..133ff42d3 100644
--- a/internal/cbm/lang_specs.c
+++ b/internal/cbm/lang_specs.c
@@ -1510,10 +1510,10 @@ static const char *pine_func_types[] = {"function_declaration_statement", NULL};
static const char *pine_class_types[] = {"type_definition_statement", NULL};
static const char *pine_module_types[] = {"source_file", NULL};
static const char *pine_call_types[] = {"call", NULL};
-static const char *pine_var_types[] = {"variable_definition_statement", "tuple_declaration_statement",
- NULL};
-static const char *pine_branch_types[] = {"if_statement", "switch_statement", "for_statement",
- "for_in_statement", "while_statement", NULL};
+static const char *pine_var_types[] = {"variable_definition_statement",
+ "tuple_declaration_statement", NULL};
+static const char *pine_branch_types[] = {"if_statement", "switch_statement", "for_statement",
+ "for_in_statement", "while_statement", NULL};
static const char *pine_assign_types[] = {"reassignment_statement", NULL};
// ==================== SPEC TABLE ====================
@@ -1528,7 +1528,8 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
[CBM_LANG_PYTHON] = {CBM_LANG_PYTHON, py_func_types, py_class_types, empty_types,
py_module_types, py_call_types, py_import_types, py_import_from_types,
py_branch_types, py_var_types, py_var_types, py_throw_types, NULL,
- py_decorator_types, py_env_funcs, py_env_members, tree_sitter_python, NULL},
+ py_decorator_types, py_env_funcs, py_env_members, tree_sitter_python,
+ NULL},
// CBM_LANG_JAVASCRIPT
[CBM_LANG_JAVASCRIPT] =
@@ -1538,11 +1539,13 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
js_throw_types, NULL, empty_types, NULL, js_env_members, tree_sitter_javascript, NULL},
// CBM_LANG_TYPESCRIPT
- [CBM_LANG_TYPESCRIPT] =
- {CBM_LANG_TYPESCRIPT, ts_func_types, ts_class_types, empty_types, js_module_types,
- js_call_types, js_import_types, js_import_types, js_branch_types, js_var_types,
- (const char *[]){"assignment_expression", "augmented_assignment_expression", NULL},
- js_throw_types, NULL, ts_decorator_types, NULL, ts_env_members, tree_sitter_typescript, NULL},
+ [CBM_LANG_TYPESCRIPT] = {CBM_LANG_TYPESCRIPT, ts_func_types, ts_class_types, empty_types,
+ js_module_types, js_call_types, js_import_types, js_import_types,
+ js_branch_types, js_var_types,
+ (const char *[]){"assignment_expression",
+ "augmented_assignment_expression", NULL},
+ js_throw_types, NULL, ts_decorator_types, NULL, ts_env_members,
+ tree_sitter_typescript, NULL},
// CBM_LANG_TSX
[CBM_LANG_TSX] =
@@ -1562,7 +1565,8 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
[CBM_LANG_JAVA] = {CBM_LANG_JAVA, java_func_types, java_class_types, java_field_types,
java_module_types, java_call_types, java_import_types, java_import_types,
java_branch_types, java_var_types, java_assign_types, java_throw_types,
- "throws", java_decorator_types, java_env_funcs, NULL, tree_sitter_java, NULL},
+ "throws", java_decorator_types, java_env_funcs, NULL, tree_sitter_java,
+ NULL},
// CBM_LANG_CPP
[CBM_LANG_CPP] = {CBM_LANG_CPP, cpp_func_types, cpp_class_types, cpp_field_types,
@@ -1680,12 +1684,14 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
[CBM_LANG_ERLANG] = {CBM_LANG_ERLANG, erlang_func_types, erlang_class_types, empty_types,
erlang_module_types, erlang_call_types, erlang_import_types, empty_types,
erlang_branch_types, erlang_var_types, erlang_assign_types,
- erlang_throw_types, NULL, empty_types, NULL, NULL, tree_sitter_erlang, NULL},
+ erlang_throw_types, NULL, empty_types, NULL, NULL, tree_sitter_erlang,
+ NULL},
// CBM_LANG_R
[CBM_LANG_R] = {CBM_LANG_R, r_func_types, empty_types, empty_types, r_module_types,
r_call_types, r_import_types, empty_types, r_branch_types, r_var_types,
- r_var_types, empty_types, NULL, empty_types, r_env_funcs, NULL, tree_sitter_r, NULL},
+ r_var_types, empty_types, NULL, empty_types, r_env_funcs, NULL, tree_sitter_r,
+ NULL},
// CBM_LANG_HTML
[CBM_LANG_HTML] = {CBM_LANG_HTML, empty_types, empty_types, empty_types, html_module_types,
@@ -1696,7 +1702,8 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_CSS
[CBM_LANG_CSS] = {CBM_LANG_CSS, empty_types, empty_types, empty_types, css_module_types,
css_call_types, css_import_types, empty_types, empty_types, empty_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_css, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_css,
+ NULL},
// CBM_LANG_SCSS
[CBM_LANG_SCSS] = {CBM_LANG_SCSS, scss_func_types, empty_types, empty_types, scss_module_types,
@@ -1707,17 +1714,20 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_YAML
[CBM_LANG_YAML] = {CBM_LANG_YAML, empty_types, empty_types, empty_types, yaml_module_types,
empty_types, empty_types, empty_types, empty_types, yaml_var_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_yaml, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_yaml,
+ NULL},
// CBM_LANG_TOML
[CBM_LANG_TOML] = {CBM_LANG_TOML, empty_types, toml_class_types, empty_types, toml_module_types,
empty_types, empty_types, empty_types, empty_types, toml_var_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_toml, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_toml,
+ NULL},
// CBM_LANG_HCL
[CBM_LANG_HCL] = {CBM_LANG_HCL, empty_types, hcl_class_types, empty_types, hcl_module_types,
hcl_call_types, empty_types, empty_types, empty_types, hcl_var_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_hcl, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_hcl,
+ NULL},
// CBM_LANG_SQL
[CBM_LANG_SQL] = {CBM_LANG_SQL, sql_func_types, sql_class_types, sql_field_types,
@@ -1771,7 +1781,8 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_ELM
[CBM_LANG_ELM] = {CBM_LANG_ELM, elm_func_types, elm_class_types, empty_types, elm_module_types,
elm_call_types, elm_import_types, empty_types, elm_branch_types, empty_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_elm, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_elm,
+ NULL},
// CBM_LANG_FORTRAN
[CBM_LANG_FORTRAN] = {CBM_LANG_FORTRAN, fortran_func_types, fortran_class_types, empty_types,
@@ -1808,7 +1819,8 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_JSON
[CBM_LANG_JSON] = {CBM_LANG_JSON, empty_types, empty_types, empty_types, json_module_types,
empty_types, empty_types, empty_types, empty_types, json_var_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_json, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_json,
+ NULL},
// CBM_LANG_XML
[CBM_LANG_XML] = {CBM_LANG_XML, empty_types, xml_class_types, empty_types, xml_module_types,
@@ -1867,13 +1879,14 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_GLSL (reuses C node types)
[CBM_LANG_GLSL] = {CBM_LANG_GLSL, c_func_types, c_class_types, c_field_types, c_module_types,
c_call_types, c_import_types, empty_types, c_branch_types, c_var_types,
- c_assign_types, empty_types, NULL, empty_types, NULL, NULL,
- tree_sitter_glsl, NULL},
+ c_assign_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_glsl,
+ NULL},
// CBM_LANG_INI
[CBM_LANG_INI] = {CBM_LANG_INI, empty_types, ini_class_types, empty_types, ini_module_types,
empty_types, empty_types, empty_types, empty_types, ini_var_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_ini, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_ini,
+ NULL},
// CBM_LANG_MATLAB
[CBM_LANG_MATLAB] = {CBM_LANG_MATLAB, matlab_func_types, matlab_class_types, empty_types,
@@ -1942,13 +1955,14 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
[CBM_LANG_PASCAL] = {CBM_LANG_PASCAL, pascal_func_types, pascal_class_types, pascal_field_types,
pascal_module_types, pascal_call_types, pascal_import_types, empty_types,
pascal_branch_types, pascal_var_types, pascal_assign_types,
- pascal_throw_types, NULL, empty_types, NULL, NULL, tree_sitter_pascal, NULL},
+ pascal_throw_types, NULL, empty_types, NULL, NULL, tree_sitter_pascal,
+ NULL},
// CBM_LANG_DLANG
[CBM_LANG_DLANG] = {CBM_LANG_DLANG, d_func_types, d_class_types, d_field_types, d_module_types,
d_call_types, d_import_types, empty_types, d_branch_types, d_var_types,
- d_assign_types, d_throw_types, NULL, empty_types, NULL, NULL,
- tree_sitter_d, NULL},
+ d_assign_types, d_throw_types, NULL, empty_types, NULL, NULL, tree_sitter_d,
+ NULL},
// CBM_LANG_NIM
[CBM_LANG_NIM] = {CBM_LANG_NIM, nim_func_types, nim_class_types, nim_field_types,
@@ -1971,24 +1985,26 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_FISH
[CBM_LANG_FISH] = {CBM_LANG_FISH, fish_func_types, empty_types, empty_types, fish_module_types,
fish_call_types, empty_types, empty_types, fish_branch_types, fish_var_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_fish, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_fish,
+ NULL},
// CBM_LANG_AWK
[CBM_LANG_AWK] = {CBM_LANG_AWK, awk_func_types, empty_types, empty_types, awk_module_types,
awk_call_types, empty_types, empty_types, awk_branch_types, awk_var_types,
- awk_assign_types, empty_types, NULL, empty_types, NULL, NULL,
- tree_sitter_awk, NULL},
+ awk_assign_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_awk,
+ NULL},
// CBM_LANG_ZSH
[CBM_LANG_ZSH] = {CBM_LANG_ZSH, zsh_func_types, empty_types, empty_types, zsh_module_types,
zsh_call_types, empty_types, empty_types, zsh_branch_types, zsh_var_types,
- zsh_assign_types, empty_types, NULL, empty_types, NULL, NULL,
- tree_sitter_zsh, NULL},
+ zsh_assign_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_zsh,
+ NULL},
// CBM_LANG_TCL
[CBM_LANG_TCL] = {CBM_LANG_TCL, tcl_func_types, tcl_class_types, empty_types, tcl_module_types,
tcl_call_types, empty_types, empty_types, tcl_branch_types, tcl_var_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_tcl, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_tcl,
+ NULL},
// CBM_LANG_ADA
[CBM_LANG_ADA] = {CBM_LANG_ADA, ada_func_types, ada_class_types, ada_field_types,
@@ -2080,7 +2096,8 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_NASM
[CBM_LANG_NASM] = {CBM_LANG_NASM, empty_types, nasm_class_types, empty_types, nasm_module_types,
nasm_call_types, nasm_import_types, empty_types, empty_types, nasm_var_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_nasm, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_nasm,
+ NULL},
// CBM_LANG_ASSEMBLY
[CBM_LANG_ASSEMBLY] = {CBM_LANG_ASSEMBLY, empty_types, empty_types, empty_types,
@@ -2097,7 +2114,8 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_BLADE
[CBM_LANG_BLADE] = {CBM_LANG_BLADE, empty_types, empty_types, empty_types, blade_module_types,
empty_types, empty_types, empty_types, empty_types, empty_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_blade, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_blade,
+ NULL},
// CBM_LANG_JUST
[CBM_LANG_JUST] = {CBM_LANG_JUST, just_func_types, empty_types, empty_types, just_module_types,
@@ -2150,7 +2168,8 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_DIFF
[CBM_LANG_DIFF] = {CBM_LANG_DIFF, empty_types, empty_types, empty_types, diff_module_types,
diff_call_types, empty_types, empty_types, empty_types, empty_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_diff, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_diff,
+ NULL},
// CBM_LANG_WGSL
[CBM_LANG_WGSL] = {CBM_LANG_WGSL, wgsl_func_types, wgsl_class_types, empty_types,
@@ -2166,7 +2185,8 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_JSON5
[CBM_LANG_JSON5] = {CBM_LANG_JSON5, empty_types, empty_types, empty_types, json5_module_types,
empty_types, empty_types, empty_types, empty_types, empty_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_json5, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_json5,
+ NULL},
// CBM_LANG_JSONNET
[CBM_LANG_JSONNET] = {CBM_LANG_JSONNET, jsonnet_func_types, empty_types, empty_types,
@@ -2269,7 +2289,8 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_GN
[CBM_LANG_GN] = {CBM_LANG_GN, empty_types, empty_types, empty_types, gn_module_types,
gn_call_types, gn_import_types, empty_types, gn_branch_types, empty_types,
- gn_assign_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_gn, NULL},
+ gn_assign_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_gn,
+ NULL},
// CBM_LANG_KCONFIG
[CBM_LANG_KCONFIG] = {CBM_LANG_KCONFIG, empty_types, kconfig_class_types, empty_types,
@@ -2323,17 +2344,20 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_FUNC
[CBM_LANG_FUNC] = {CBM_LANG_FUNC, func_func_types, empty_types, empty_types, func_module_types,
func_call_types, func_import_types, empty_types, empty_types, empty_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_func, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_func,
+ NULL},
// CBM_LANG_REGEX
[CBM_LANG_REGEX] = {CBM_LANG_REGEX, empty_types, empty_types, empty_types, regex_module_types,
empty_types, empty_types, empty_types, empty_types, empty_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_regex, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_regex,
+ NULL},
// CBM_LANG_JSDOC
[CBM_LANG_JSDOC] = {CBM_LANG_JSDOC, empty_types, empty_types, empty_types, jsdoc_module_types,
empty_types, empty_types, empty_types, empty_types, empty_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_jsdoc, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_jsdoc,
+ NULL},
// CBM_LANG_RST
[CBM_LANG_RST] = {CBM_LANG_RST, empty_types, empty_types, empty_types, rst_module_types,
@@ -2408,12 +2432,14 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_PKL
[CBM_LANG_PKL] = {CBM_LANG_PKL, pkl_func_types, pkl_class_types, empty_types, pkl_module_types,
empty_types, pkl_import_types, empty_types, empty_types, pkl_var_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_pkl, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_pkl,
+ NULL},
// CBM_LANG_GOMOD
[CBM_LANG_GOMOD] = {CBM_LANG_GOMOD, empty_types, empty_types, empty_types, gomod_module_types,
empty_types, gomod_import_types, empty_types, empty_types, gomod_var_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_gomod, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_gomod,
+ NULL},
// CBM_LANG_APEX
[CBM_LANG_APEX] = {CBM_LANG_APEX, apex_func_types, apex_class_types, apex_field_types,
@@ -2424,12 +2450,14 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
// CBM_LANG_SOQL
[CBM_LANG_SOQL] = {CBM_LANG_SOQL, empty_types, empty_types, empty_types, soql_module_types,
empty_types, soql_import_types, empty_types, empty_types, empty_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_soql, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_soql,
+ NULL},
// CBM_LANG_SOSL
[CBM_LANG_SOSL] = {CBM_LANG_SOSL, empty_types, empty_types, empty_types, sosl_module_types,
empty_types, sosl_import_types, empty_types, empty_types, empty_types,
- empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_sosl, NULL},
+ empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_sosl,
+ NULL},
// CBM_LANG_KUSTOMIZE — reuses YAML grammar; semantic extraction via cbm_extract_k8s()
[CBM_LANG_KUSTOMIZE] = {CBM_LANG_KUSTOMIZE, yaml_var_types, empty_types, empty_types,
diff --git a/internal/cbm/service_patterns.c b/internal/cbm/service_patterns.c
index 9e799d221..75c0c1556 100644
--- a/internal/cbm/service_patterns.c
+++ b/internal/cbm/service_patterns.c
@@ -574,12 +574,14 @@ static void svc_cache_free_key(const char *key, void *val, void *ud) {
}
void cbm_service_pattern_cache_begin(void) {
- if (_svc_cache) return; /* idempotent */
+ if (_svc_cache)
+ return; /* idempotent */
_svc_cache = cbm_ht_create(8192);
}
void cbm_service_pattern_cache_end(void) {
- if (!_svc_cache) return;
+ if (!_svc_cache)
+ return;
cbm_ht_foreach(_svc_cache, svc_cache_free_key, NULL);
cbm_ht_free(_svc_cache);
_svc_cache = NULL;
@@ -606,17 +608,25 @@ cbm_svc_kind_t cbm_service_pattern_match(const char *resolved_qn) {
/* Route registration checked first — prevents gin/echo from matching
* as HTTP clients (both have .get/.post suffixes). */
- if ((p = match_qn(resolved_qn, route_reg_libraries))) result = p->kind;
- else if ((p = match_qn(resolved_qn, http_libraries))) result = p->kind;
- else if ((p = match_qn(resolved_qn, async_libraries))) result = p->kind;
- else if ((p = match_qn(resolved_qn, config_libraries))) result = p->kind;
- else if ((p = match_qn(resolved_qn, grpc_libraries))) result = p->kind;
- else if ((p = match_qn(resolved_qn, graphql_libraries))) result = p->kind;
- else if ((p = match_qn(resolved_qn, trpc_libraries))) result = p->kind;
+ if ((p = match_qn(resolved_qn, route_reg_libraries)))
+ result = p->kind;
+ else if ((p = match_qn(resolved_qn, http_libraries)))
+ result = p->kind;
+ else if ((p = match_qn(resolved_qn, async_libraries)))
+ result = p->kind;
+ else if ((p = match_qn(resolved_qn, config_libraries)))
+ result = p->kind;
+ else if ((p = match_qn(resolved_qn, grpc_libraries)))
+ result = p->kind;
+ else if ((p = match_qn(resolved_qn, graphql_libraries)))
+ result = p->kind;
+ else if ((p = match_qn(resolved_qn, trpc_libraries)))
+ result = p->kind;
if (_svc_cache) {
char *kdup = strdup(resolved_qn);
- if (kdup) cbm_ht_set(_svc_cache, kdup, svc_enum_to_ptr(result));
+ if (kdup)
+ cbm_ht_set(_svc_cache, kdup, svc_enum_to_ptr(result));
}
return result;
}
diff --git a/internal/cbm/sqlite_writer.c b/internal/cbm/sqlite_writer.c
index c3826aaef..01b2c4042 100644
--- a/internal/cbm/sqlite_writer.c
+++ b/internal/cbm/sqlite_writer.c
@@ -1222,8 +1222,7 @@ static uint32_t write_index_btree(FILE *fp, uint32_t *next_page, uint8_t **cells
// After flush, check if the cell still doesn't fit on an empty page.
// Index cells larger than a full page can never be stored; skip them.
if (!pb_cell_fits(&pb, cell_lens[i])) {
- (void)fprintf(stderr,
- "cbm_write_db: index cell oversized, skipped len=%d idx=%d\n",
+ (void)fprintf(stderr, "cbm_write_db: index cell oversized, skipped len=%d idx=%d\n",
cell_lens[i], i);
continue;
}
diff --git a/src/cli/cli.c b/src/cli/cli.c
index cffe3c36a..1b206e60c 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -1698,18 +1698,17 @@ static void cbm_install_hook_gate_script(const char *home, const char *binary_pa
if (!f) {
return;
}
- (void)fprintf(
- f,
- "#!/bin/bash\n"
- "# codebase-memory-mcp search augmenter (Claude Code PreToolUse).\n"
- "# NOTE: the legacy filename is kept for zero-migration upgrades.\n"
- "# Despite the name this NEVER blocks a tool call - it only adds\n"
- "# graph context. Any failure is silent (exit 0, no output).\n"
- "BIN=\"%s\"\n"
- "[ -x \"$BIN\" ] || exit 0\n"
- "\"$BIN\" hook-augment 2>/dev/null\n"
- "exit 0\n",
- binary_path);
+ (void)fprintf(f,
+ "#!/bin/bash\n"
+ "# codebase-memory-mcp search augmenter (Claude Code PreToolUse).\n"
+ "# NOTE: the legacy filename is kept for zero-migration upgrades.\n"
+ "# Despite the name this NEVER blocks a tool call - it only adds\n"
+ "# graph context. Any failure is silent (exit 0, no output).\n"
+ "BIN=\"%s\"\n"
+ "[ -x \"$BIN\" ] || exit 0\n"
+ "\"$BIN\" hook-augment 2>/dev/null\n"
+ "exit 0\n",
+ binary_path);
/* fchmod before close to avoid TOCTOU race (CodeQL cpp/toctou-race-condition) */
#ifndef _WIN32
fchmod(fileno(f), CLI_OCTAL_PERM);
diff --git a/src/cli/hook_augment.c b/src/cli/hook_augment.c
index b39015262..026516d0a 100644
--- a/src/cli/hook_augment.c
+++ b/src/cli/hook_augment.c
@@ -38,9 +38,9 @@
#define HA_MIN_TOKEN 4 /* skip short/noisy patterns before any work */
#define HA_MAX_TOKEN 96
#define HA_RESULT_LIMIT 5
-#define HA_MAX_WALKUP 8 /* cwd may be a subdir of the indexed root */
-#define HA_DEADLINE_MS 300 /* hard in-process budget (see also: the */
- /* settings.json "timeout" backstop) */
+#define HA_MAX_WALKUP 8 /* cwd may be a subdir of the indexed root */
+#define HA_DEADLINE_MS 300 /* hard in-process budget (see also: the */
+ /* settings.json "timeout" backstop) */
/* ── Hard deadline ────────────────────────────────────────────────
* A slow SQLite open or query must never stall the agent. When the timer
@@ -77,8 +77,7 @@ static char *ha_read_stdin(void) {
}
size_t total = 0;
size_t n;
- while (total < HA_STDIN_CAP &&
- (n = fread(buf + total, 1, HA_STDIN_CAP - total, stdin)) > 0) {
+ while (total < HA_STDIN_CAP && (n = fread(buf + total, 1, HA_STDIN_CAP - total, stdin)) > 0) {
total += n;
}
buf[total] = '\0';
@@ -101,8 +100,7 @@ static bool ha_extract_token(const char *pattern, char *out, size_t out_sz) {
while (pattern[i]) {
if (isalpha((unsigned char)pattern[i]) || pattern[i] == '_') {
size_t start = i;
- while (pattern[i] &&
- (isalnum((unsigned char)pattern[i]) || pattern[i] == '_')) {
+ while (pattern[i] && (isalnum((unsigned char)pattern[i]) || pattern[i] == '_')) {
i++;
}
size_t len = i - start;
@@ -160,8 +158,7 @@ static char *ha_build_args(const char *project, const char *token) {
*
* *is_error is set when the envelope is an MCP error (e.g. project not
* indexed) so the caller can try a parent directory. */
-static char *ha_format_context(const char *envelope, const char *token,
- bool *is_error) {
+static char *ha_format_context(const char *envelope, const char *token, bool *is_error) {
*is_error = false;
yyjson_doc *edoc = yyjson_read(envelope, strlen(envelope), 0);
if (!edoc) {
@@ -175,9 +172,7 @@ static char *ha_format_context(const char *envelope, const char *token,
return NULL;
}
yyjson_val *content = yyjson_obj_get(eroot, "content");
- yyjson_val *item0 = (content && yyjson_is_arr(content))
- ? yyjson_arr_get(content, 0)
- : NULL;
+ yyjson_val *item0 = (content && yyjson_is_arr(content)) ? yyjson_arr_get(content, 0) : NULL;
const char *inner = ha_obj_str(item0, "text");
if (!inner) {
yyjson_doc_free(edoc);
@@ -221,8 +216,7 @@ static char *ha_format_context(const char *envelope, const char *token,
const char *fp = ha_obj_str(r, "file_path");
const char *lb = ha_obj_str(r, "label");
const char *disp = (qn && qn[0]) ? qn : (nm ? nm : "");
- off += snprintf(text + off, (size_t)(4096 - off), "\n- %s %s%s%s",
- disp, fp ? fp : "",
+ off += snprintf(text + off, (size_t)(4096 - off), "\n- %s %s%s%s", disp, fp ? fp : "",
(lb && lb[0]) ? " " : "", (lb && lb[0]) ? lb : "");
}
@@ -253,8 +247,7 @@ static void ha_emit(const char *text) {
* search_graph until an indexed project is found (or the walk is exhausted).
* Stops at the first non-error result: a valid project with zero hits is a
* legitimate "no match" and must NOT cause a parent-directory probe. */
-static char *ha_resolve_and_query(cbm_mcp_server_t *srv, const char *start,
- const char *token) {
+static char *ha_resolve_and_query(cbm_mcp_server_t *srv, const char *start, const char *token) {
char dir[4096];
snprintf(dir, sizeof(dir), "%s", start);
diff --git a/src/foundation/hash_table.c b/src/foundation/hash_table.c
index f49e5627d..1ee33e32e 100644
--- a/src/foundation/hash_table.c
+++ b/src/foundation/hash_table.c
@@ -43,7 +43,8 @@ struct CBMHashTable {
CBMHashTable *cbm_ht_create(uint32_t initial_capacity) {
CBMHashTable *ht = (CBMHashTable *)calloc(CBM_ALLOC_ONE, sizeof(*ht));
- if (!ht) return NULL;
+ if (!ht)
+ return NULL;
cbm_vt_init(&ht->vt);
if (initial_capacity > 0) {
/* Reserve enough buckets for the requested entries. Verstable
@@ -58,13 +59,15 @@ CBMHashTable *cbm_ht_create(uint32_t initial_capacity) {
}
void cbm_ht_free(CBMHashTable *ht) {
- if (!ht) return;
+ if (!ht)
+ return;
cbm_vt_cleanup(&ht->vt);
free(ht);
}
void *cbm_ht_set(CBMHashTable *ht, const char *key, void *value) {
- if (!ht || !key) return NULL;
+ if (!ht || !key)
+ return NULL;
/* Capture previous value (if any) before overwriting.
* Verstable's _insert overwrites silently and returns an iterator
* to the (now updated) entry — we have to peek first to surface
@@ -79,49 +82,57 @@ void *cbm_ht_set(CBMHashTable *ht, const char *key, void *value) {
}
void *cbm_ht_get(const CBMHashTable *ht, const char *key) {
- if (!ht || !key) return NULL;
+ if (!ht || !key)
+ return NULL;
cbm_vt_itr itr = cbm_vt_get(&ht->vt, key);
- if (cbm_vt_is_end(itr)) return NULL;
+ if (cbm_vt_is_end(itr))
+ return NULL;
return itr.data->val;
}
bool cbm_ht_has(const CBMHashTable *ht, const char *key) {
- if (!ht || !key) return false;
+ if (!ht || !key)
+ return false;
cbm_vt_itr itr = cbm_vt_get(&ht->vt, key);
return !cbm_vt_is_end(itr);
}
const char *cbm_ht_get_key(const CBMHashTable *ht, const char *key) {
- if (!ht || !key) return NULL;
+ if (!ht || !key)
+ return NULL;
cbm_vt_itr itr = cbm_vt_get(&ht->vt, key);
- if (cbm_vt_is_end(itr)) return NULL;
+ if (cbm_vt_is_end(itr))
+ return NULL;
return itr.data->key;
}
void *cbm_ht_delete(CBMHashTable *ht, const char *key) {
- if (!ht || !key) return NULL;
+ if (!ht || !key)
+ return NULL;
cbm_vt_itr itr = cbm_vt_get(&ht->vt, key);
- if (cbm_vt_is_end(itr)) return NULL;
+ if (cbm_vt_is_end(itr))
+ return NULL;
void *prev = itr.data->val;
(void)cbm_vt_erase(&ht->vt, key);
return prev;
}
uint32_t cbm_ht_count(const CBMHashTable *ht) {
- if (!ht) return 0;
+ if (!ht)
+ return 0;
return (uint32_t)cbm_vt_size(&ht->vt);
}
void cbm_ht_foreach(const CBMHashTable *ht, cbm_ht_iter_fn fn, void *userdata) {
- if (!ht || !fn) return;
- for (cbm_vt_itr itr = cbm_vt_first(&ht->vt);
- !cbm_vt_is_end(itr);
- itr = cbm_vt_next(itr)) {
+ if (!ht || !fn)
+ return;
+ for (cbm_vt_itr itr = cbm_vt_first(&ht->vt); !cbm_vt_is_end(itr); itr = cbm_vt_next(itr)) {
fn(itr.data->key, itr.data->val, userdata);
}
}
void cbm_ht_clear(CBMHashTable *ht) {
- if (!ht) return;
+ if (!ht)
+ return;
cbm_vt_clear(&ht->vt);
}
diff --git a/src/foundation/platform.h b/src/foundation/platform.h
index 430a833e7..2511a060e 100644
--- a/src/foundation/platform.h
+++ b/src/foundation/platform.h
@@ -69,12 +69,12 @@ static inline void safe_buf_free_impl(void **buf, size_t *count) {
* For arrays of heap-allocated pointers, prefer a manual realloc+cleanup pattern.
* Usage: safe_grow(arr, count, cap, growth_factor)
* After the call, arr is the new buffer (NULL on OOM). */
-#define safe_grow(arr, n, cap, factor) \
- do { \
- if ((size_t)(n) >= (size_t)(cap)) { \
- (cap) *= (factor); \
- (arr) = safe_realloc((arr), (size_t)(cap) * sizeof(*(arr))); \
- } \
+#define safe_grow(arr, n, cap, factor) \
+ do { \
+ if ((size_t)(n) >= (size_t)(cap)) { \
+ (cap) *= (factor); \
+ (arr) = safe_realloc((arr), (size_t)(cap) * sizeof(*(arr))); \
+ } \
} while (0)
/* ── Memory mapping ────────────────────────────────────────────── */
diff --git a/src/foundation/system_info.c b/src/foundation/system_info.c
index e5ba8a658..a9238b9e5 100644
--- a/src/foundation/system_info.c
+++ b/src/foundation/system_info.c
@@ -88,9 +88,9 @@ static cbm_system_info_t detect_system_bsd(void) {
info.perf_cores = info.total_cores;
#if defined(__OpenBSD__)
- int mib[2] = { CTL_HW, HW_PHYSMEM };
+ int mib[2] = {CTL_HW, HW_PHYSMEM};
#else
- int mib[2] = { CTL_HW, HW_PHYSMEM64 };
+ int mib[2] = {CTL_HW, HW_PHYSMEM64};
#endif
uint64_t physmem = 0;
size_t len = sizeof(physmem);
diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c
index ac4ddb80e..1781e2027 100644
--- a/src/mcp/mcp.c
+++ b/src/mcp/mcp.c
@@ -877,8 +877,7 @@ static bool is_project_db_file(const char *name, size_t len) {
if (len < MCP_MIN_DB_NAME || strcmp(name + len - MCP_DB_EXT, ".db") != 0) {
return false;
}
- if (strncmp(name, "_", SLEN("_")) == 0 ||
- strncmp(name, ":memory:", SLEN(":memory:")) == 0) {
+ if (strncmp(name, "_", SLEN("_")) == 0 || strncmp(name, ":memory:", SLEN(":memory:")) == 0) {
return false;
}
return true;
@@ -1252,11 +1251,11 @@ static char *bm25_search(cbm_store_t *store, const char *project, const char *qu
if (sqlite3_prepare_v2(db, sql, BM25_SQL_AUTO_LEN, &stmt, NULL) != SQLITE_OK) {
return NULL;
}
- sqlite3_bind_text(stmt, BM25_BIND_QUERY, fts_query, BM25_SQL_AUTO_LEN, MCP_SQLITE_TRANSIENT);
- sqlite3_bind_text(stmt, BM25_BIND_PROJECT, project, BM25_SQL_AUTO_LEN, MCP_SQLITE_TRANSIENT);
- sqlite3_bind_int(stmt, BM25_BIND_LIMIT, limit > 0 ? limit : BM25_DEFAULT_LIMIT);
+ sqlite3_bind_text(stmt, BM25_BIND_QUERY, fts_query, BM25_SQL_AUTO_LEN, MCP_SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, BM25_BIND_PROJECT, project, BM25_SQL_AUTO_LEN, MCP_SQLITE_TRANSIENT);
+ sqlite3_bind_int(stmt, BM25_BIND_LIMIT, limit > 0 ? limit : BM25_DEFAULT_LIMIT);
sqlite3_bind_int(stmt, BM25_BIND_OFFSET, offset > 0 ? offset : 0);
- sqlite3_bind_int(stmt, BM25_BIND_INNER, BM25_INNER_LIMIT);
+ sqlite3_bind_int(stmt, BM25_BIND_INNER, BM25_INNER_LIMIT);
/* Count hits within the same inner-limit window — capped at BM25_INNER_LIMIT.
* Uses the identical subquery structure so the FTS5 early-exit applies here too. */
@@ -1274,9 +1273,9 @@ static char *bm25_search(cbm_store_t *store, const char *project, const char *qu
")";
sqlite3_stmt *cs = NULL;
if (sqlite3_prepare_v2(db, count_sql, BM25_SQL_AUTO_LEN, &cs, NULL) == SQLITE_OK) {
- sqlite3_bind_text(cs, BM25_BIND_QUERY, fts_query, BM25_SQL_AUTO_LEN,
+ sqlite3_bind_text(cs, BM25_BIND_QUERY, fts_query, BM25_SQL_AUTO_LEN,
MCP_SQLITE_TRANSIENT);
- sqlite3_bind_text(cs, BM25_BIND_PROJECT, project, BM25_SQL_AUTO_LEN,
+ sqlite3_bind_text(cs, BM25_BIND_PROJECT, project, BM25_SQL_AUTO_LEN,
MCP_SQLITE_TRANSIENT);
sqlite3_bind_int(cs, BM25_BIND_LIMIT, BM25_INNER_LIMIT);
if (sqlite3_step(cs) == SQLITE_ROW) {
@@ -1336,8 +1335,7 @@ static void emit_search_results(yyjson_mut_doc *doc, yyjson_mut_val *root,
const cbm_search_output_t *out, cbm_store_t *store,
const char *relationship, bool include_connected, int offset,
yyjson_doc ***out_pdocs, int *out_pdoc_count) {
- yyjson_doc **pdocs =
- out->count > 0 ? malloc((size_t)out->count * sizeof(yyjson_doc *)) : NULL;
+ yyjson_doc **pdocs = out->count > 0 ? malloc((size_t)out->count * sizeof(yyjson_doc *)) : NULL;
int pdoc_count = 0;
yyjson_mut_obj_add_int(doc, root, "total", out->total);
yyjson_mut_val *results = yyjson_mut_arr(doc);
@@ -1847,8 +1845,7 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
cbm_store_get_schema(store, project, &schema);
cbm_architecture_info_t arch = {0};
- cbm_store_get_architecture(store, project,
- aspects_strs_count > 0 ? aspects_strs : NULL,
+ cbm_store_get_architecture(store, project, aspects_strs_count > 0 ? aspects_strs : NULL,
aspects_strs_count, &arch);
int node_count = cbm_store_count_nodes(store, project);
@@ -1932,10 +1929,9 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
yyjson_mut_val *item = yyjson_mut_obj(doc);
yyjson_mut_obj_add_str(doc, item, "name",
arch.entry_points[i].name ? arch.entry_points[i].name : "");
- yyjson_mut_obj_add_str(doc, item, "qualified_name",
- arch.entry_points[i].qualified_name
- ? arch.entry_points[i].qualified_name
- : "");
+ yyjson_mut_obj_add_str(
+ doc, item, "qualified_name",
+ arch.entry_points[i].qualified_name ? arch.entry_points[i].qualified_name : "");
yyjson_mut_obj_add_str(doc, item, "file",
arch.entry_points[i].file ? arch.entry_points[i].file : "");
yyjson_mut_arr_add_val(eps, item);
@@ -1967,9 +1963,8 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
yyjson_mut_obj_add_str(doc, item, "name",
arch.hotspots[i].name ? arch.hotspots[i].name : "");
yyjson_mut_obj_add_str(doc, item, "qualified_name",
- arch.hotspots[i].qualified_name
- ? arch.hotspots[i].qualified_name
- : "");
+ arch.hotspots[i].qualified_name ? arch.hotspots[i].qualified_name
+ : "");
yyjson_mut_obj_add_int(doc, item, "fan_in", arch.hotspots[i].fan_in);
yyjson_mut_arr_add_val(hotspots, item);
}
@@ -1998,8 +1993,7 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
yyjson_mut_val *item = yyjson_mut_obj(doc);
yyjson_mut_obj_add_str(doc, item, "from",
arch.services[i].from ? arch.services[i].from : "");
- yyjson_mut_obj_add_str(doc, item, "to",
- arch.services[i].to ? arch.services[i].to : "");
+ yyjson_mut_obj_add_str(doc, item, "to", arch.services[i].to ? arch.services[i].to : "");
yyjson_mut_obj_add_str(doc, item, "type",
arch.services[i].type ? arch.services[i].type : "");
yyjson_mut_obj_add_int(doc, item, "count", arch.services[i].count);
@@ -2983,29 +2977,37 @@ static void build_grep_cmd(char *cmd, size_t cmd_sz, bool use_regex, bool scoped
const char *sm = use_regex ? "" : " -SimpleMatch";
if (scoped) {
if (file_pattern) {
- snprintf(cmd, cmd_sz,
+ snprintf(
+ cmd, cmd_sz,
"powershell -Command \"$pat = Get-Content '%s'; "
- "Get-Content '%s' | ForEach-Object { Select-String -LiteralPath $_ -Pattern $pat%s -ErrorAction SilentlyContinue }"
+ "Get-Content '%s' | ForEach-Object { Select-String -LiteralPath $_ -Pattern $pat%s "
+ "-ErrorAction SilentlyContinue }"
" | Where-Object { $_.Path -like '*%s' }"
" | ForEach-Object { $_.Path + [char]9 + $_.LineNumber + [char]9 + $_.Line }\"",
tmpfile, filelist, sm, file_pattern);
} else {
- snprintf(cmd, cmd_sz,
+ snprintf(
+ cmd, cmd_sz,
"powershell -Command \"$pat = Get-Content '%s'; "
- "Get-Content '%s' | ForEach-Object { Select-String -LiteralPath $_ -Pattern $pat%s -ErrorAction SilentlyContinue }"
+ "Get-Content '%s' | ForEach-Object { Select-String -LiteralPath $_ -Pattern $pat%s "
+ "-ErrorAction SilentlyContinue }"
" | ForEach-Object { $_.Path + [char]9 + $_.LineNumber + [char]9 + $_.Line }\"",
tmpfile, filelist, sm);
}
} else {
if (file_pattern) {
- snprintf(cmd, cmd_sz,
- "powershell -Command \"Get-ChildItem -Recurse -Path '%s\\*' -Include '%s' -File -ErrorAction SilentlyContinue"
+ snprintf(
+ cmd, cmd_sz,
+ "powershell -Command \"Get-ChildItem -Recurse -Path '%s\\*' -Include '%s' -File "
+ "-ErrorAction SilentlyContinue"
" | Select-String -Pattern (Get-Content '%s')%s -ErrorAction SilentlyContinue"
" | ForEach-Object { $_.Path + [char]9 + $_.LineNumber + [char]9 + $_.Line }\"",
root_path, file_pattern, tmpfile, sm);
} else {
- snprintf(cmd, cmd_sz,
- "powershell -Command \"Get-ChildItem -Recurse -Path '%s\\*' -File -ErrorAction SilentlyContinue"
+ snprintf(
+ cmd, cmd_sz,
+ "powershell -Command \"Get-ChildItem -Recurse -Path '%s\\*' -File -ErrorAction "
+ "SilentlyContinue"
" | Select-String -Pattern (Get-Content '%s')%s -ErrorAction SilentlyContinue"
" | ForEach-Object { $_.Path + [char]9 + $_.LineNumber + [char]9 + $_.Line }\"",
root_path, tmpfile, sm);
diff --git a/src/pipeline/lsp_resolve.h b/src/pipeline/lsp_resolve.h
index 0e94585d2..85facee81 100644
--- a/src/pipeline/lsp_resolve.h
+++ b/src/pipeline/lsp_resolve.h
@@ -45,8 +45,8 @@
* the textual callee_name as the last dot-separated segment. The
* pointer returned aliases into `arr` and stays valid as long as the
* underlying CBMFileResult is alive. */
-static inline const CBMResolvedCall *
-cbm_pipeline_find_lsp_resolution(const CBMResolvedCallArray *arr, const CBMCall *call) {
+static inline const CBMResolvedCall *cbm_pipeline_find_lsp_resolution(
+ const CBMResolvedCallArray *arr, const CBMCall *call) {
if (!arr || arr->count == 0 || !call) {
return NULL;
}
@@ -92,9 +92,9 @@ cbm_pipeline_find_lsp_resolution(const CBMResolvedCallArray *arr, const CBMCall
* external/unknown and the caller drops the edge — same as today.
*
* Returns the matching node, or NULL if neither lookup hits. */
-static inline const cbm_gbuf_node_t *
-cbm_pipeline_lsp_target_node(const cbm_gbuf_t *gbuf, const char *project_name,
- const char *callee_qn) {
+static inline const cbm_gbuf_node_t *cbm_pipeline_lsp_target_node(const cbm_gbuf_t *gbuf,
+ const char *project_name,
+ const char *callee_qn) {
if (!gbuf || !callee_qn) {
return NULL;
}
diff --git a/src/pipeline/pass_calls.c b/src/pipeline/pass_calls.c
index 7f169b175..e5cdbf76a 100644
--- a/src/pipeline/pass_calls.c
+++ b/src/pipeline/pass_calls.c
@@ -346,8 +346,8 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
res.confidence = lsp->confidence;
res.strategy = lsp->strategy;
res.candidate_count = 1;
- emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn,
- imp_keys, imp_vals, imp_count);
+ emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys,
+ imp_vals, imp_count);
return SKIP_ONE;
}
}
@@ -430,8 +430,8 @@ int cbm_pipeline_pass_calls(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *file
continue;
}
total_calls++;
- if (resolve_single_call(ctx, call, &result->resolved_calls, rel, module_qn,
- imp_keys, imp_vals, imp_count)) {
+ if (resolve_single_call(ctx, call, &result->resolved_calls, rel, module_qn, imp_keys,
+ imp_vals, imp_count)) {
resolved++;
} else {
unresolved++;
diff --git a/src/pipeline/pass_githistory.c b/src/pipeline/pass_githistory.c
index 0eb28a7ac..4be223092 100644
--- a/src/pipeline/pass_githistory.c
+++ b/src/pipeline/pass_githistory.c
@@ -584,8 +584,8 @@ int cbm_pipeline_githistory_apply(cbm_pipeline_ctx_t *ctx, const cbm_githistory_
char props[CBM_SZ_256];
snprintf(props, sizeof(props),
- "{\"extension\":\"%s\",\"last_modified\":%lld,\"change_count\":%d}",
- ext_escaped, ft->last_modified, ft->change_count);
+ "{\"extension\":\"%s\",\"last_modified\":%lld,\"change_count\":%d}", ext_escaped,
+ ft->last_modified, ft->change_count);
cbm_gbuf_upsert_node(ctx->gbuf, node->label, node->name, node->qualified_name,
node->file_path, node->start_line, node->end_line, props);
diff --git a/src/pipeline/pass_lsp_cross.c b/src/pipeline/pass_lsp_cross.c
index e340dd911..fe636801f 100644
--- a/src/pipeline/pass_lsp_cross.c
+++ b/src/pipeline/pass_lsp_cross.c
@@ -55,12 +55,12 @@ static const char *itoa_buf(int val) {
* pipeline doesn't grow a public read-file API just for this pass). */
static char *pxc_read_file(const char *path, int *out_len) {
FILE *f = fopen(path, "rb");
- if (!f) return NULL;
+ if (!f)
+ return NULL;
(void)fseek(f, 0, SEEK_END);
long size = ftell(f);
(void)fseek(f, 0, SEEK_SET);
- if (size <= 0 ||
- size > (long)PXC_MAX_FILE_BYTES_FACTOR * (long)CBM_SZ_1K * (long)CBM_SZ_1K) {
+ if (size <= 0 || size > (long)PXC_MAX_FILE_BYTES_FACTOR * (long)CBM_SZ_1K * (long)CBM_SZ_1K) {
(void)fclose(f);
return NULL;
}
@@ -71,7 +71,8 @@ static char *pxc_read_file(const char *path, int *out_len) {
}
size_t nread = fread(buf, 1, (size_t)size, f);
(void)fclose(f);
- if (nread > (size_t)size) nread = (size_t)size;
+ if (nread > (size_t)size)
+ nread = (size_t)size;
buf[nread] = '\0';
*out_len = (int)nread;
return buf;
@@ -81,14 +82,11 @@ static char *pxc_read_file(const char *path, int *out_len) {
* registrars only care about Class/Interface/Trait/Enum/Type/Protocol/
* Function/Method — variables, modules, decorators, etc. are skipped. */
static const char *pxc_map_label(const char *label) {
- if (!label) return NULL;
- if (strcmp(label, "Class") == 0 ||
- strcmp(label, "Interface") == 0 ||
- strcmp(label, "Trait") == 0 ||
- strcmp(label, "Enum") == 0 ||
- strcmp(label, "Type") == 0 ||
- strcmp(label, "Protocol") == 0 ||
- strcmp(label, "Function") == 0 ||
+ if (!label)
+ return NULL;
+ if (strcmp(label, "Class") == 0 || strcmp(label, "Interface") == 0 ||
+ strcmp(label, "Trait") == 0 || strcmp(label, "Enum") == 0 || strcmp(label, "Type") == 0 ||
+ strcmp(label, "Protocol") == 0 || strcmp(label, "Function") == 0 ||
strcmp(label, "Method") == 0) {
return label;
}
@@ -98,24 +96,28 @@ static const char *pxc_map_label(const char *label) {
/* Build the embedded_types "|"-separated string from base_classes[].
* Returns NULL when there are no bases. Allocated in the supplied arena. */
static const char *pxc_join_pipe(CBMArena *arena, const char *const *items) {
- if (!items || !items[0]) return NULL;
+ if (!items || !items[0])
+ return NULL;
int count = 0;
size_t total = 0;
for (int i = 0; items[i]; i++) {
count++;
total += strlen(items[i]);
}
- if (count == 0) return NULL;
+ if (count == 0)
+ return NULL;
/* count - 1 separators + NUL. */
size_t bufsz = total + (size_t)(count - 1) + 1;
char *buf = (char *)cbm_arena_alloc(arena, bufsz);
- if (!buf) return NULL;
+ if (!buf)
+ return NULL;
char *p = buf;
for (int i = 0; i < count; i++) {
size_t n = strlen(items[i]);
memcpy(p, items[i], n);
p += n;
- if (i + 1 < count) *p++ = '|';
+ if (i + 1 < count)
+ *p++ = '|';
}
*p = '\0';
return buf;
@@ -124,19 +126,18 @@ static const char *pxc_join_pipe(CBMArena *arena, const char *const *items) {
/* Convert one CBMDefinition into a CBMLSPDef. Returns 0 on success, -1
* to skip (unsupported label or missing required field). dst gets borrowed
* pointers into src and into `arena` for synthesised composites. */
-static int pxc_build_lsp_def(CBMArena *arena, const CBMDefinition *src,
- const char *module_qn, CBMLanguage lang,
- CBMLSPDef *dst) {
+static int pxc_build_lsp_def(CBMArena *arena, const CBMDefinition *src, const char *module_qn,
+ CBMLanguage lang, CBMLSPDef *dst) {
const char *label = pxc_map_label(src->label);
- if (!label || !src->qualified_name || !src->name) return -1;
+ if (!label || !src->qualified_name || !src->name)
+ return -1;
memset(dst, 0, sizeof(*dst));
dst->qualified_name = src->qualified_name;
dst->short_name = src->name;
dst->label = label;
dst->receiver_type = src->parent_class;
dst->def_module_qn = module_qn;
- dst->is_interface = (strcmp(label, "Interface") == 0 ||
- strcmp(label, "Protocol") == 0);
+ dst->is_interface = (strcmp(label, "Interface") == 0 || strcmp(label, "Protocol") == 0);
/* Single return-type string. The per-language registrars split on '|'
* for multi-return languages (Go); single-return languages just see one
* piece, which is what's already stored. */
@@ -149,13 +150,13 @@ static int pxc_build_lsp_def(CBMArena *arena, const CBMDefinition *src,
/* Collect a project-wide CBMLSPDef[] from all cached results. Returns a
* malloc'd array (caller frees) of length *out_count. String fields are
* borrowed from cache[i]->arena and from def_modules[i] (also borrowed). */
-CBMLSPDef *cbm_pxc_collect_all_defs(CBMFileResult **cache,
- const cbm_file_info_t *files, int file_count,
- const char *project_name,
- char **def_modules, int *out_count) {
+CBMLSPDef *cbm_pxc_collect_all_defs(CBMFileResult **cache, const cbm_file_info_t *files,
+ int file_count, const char *project_name, char **def_modules,
+ int *out_count) {
int total = 0;
for (int i = 0; i < file_count; i++) {
- if (cache[i]) total += cache[i]->defs.count;
+ if (cache[i])
+ total += cache[i]->defs.count;
}
if (total == 0) {
*out_count = 0;
@@ -168,16 +169,14 @@ CBMLSPDef *cbm_pxc_collect_all_defs(CBMFileResult **cache,
}
int idx = 0;
for (int fi = 0; fi < file_count; fi++) {
- if (!cache[fi]) continue;
+ if (!cache[fi])
+ continue;
if (!def_modules[fi]) {
def_modules[fi] = cbm_pipeline_fqn_module(project_name, files[fi].rel_path);
}
for (int di = 0; di < cache[fi]->defs.count; di++) {
- if (pxc_build_lsp_def(&cache[fi]->arena,
- &cache[fi]->defs.items[di],
- def_modules[fi],
- files[fi].language,
- &defs[idx]) == 0) {
+ if (pxc_build_lsp_def(&cache[fi]->arena, &cache[fi]->defs.items[di], def_modules[fi],
+ files[fi].language, &defs[idx]) == 0) {
idx++;
}
}
@@ -191,23 +190,26 @@ CBMLSPDef *cbm_pxc_collect_all_defs(CBMFileResult **cache,
* with *out_count = 0 when the file has no IMPORTS edges. Caller frees keys
* with pxc_free_import_map. */
static int pxc_build_import_map(const cbm_gbuf_t *gbuf, const char *project_name,
- const char *rel_path, const char ***out_keys,
- const char ***out_vals, int *out_count) {
+ const char *rel_path, const char ***out_keys,
+ const char ***out_vals, int *out_count) {
*out_keys = NULL;
*out_vals = NULL;
*out_count = 0;
char *file_qn = cbm_pipeline_fqn_compute(project_name, rel_path, "__file__");
- if (!file_qn) return 0;
+ if (!file_qn)
+ return 0;
const cbm_gbuf_node_t *file_node = cbm_gbuf_find_by_qn(gbuf, file_qn);
free(file_qn);
- if (!file_node) return 0;
+ if (!file_node)
+ return 0;
const cbm_gbuf_edge_t **edges = NULL;
int edge_count = 0;
- int rc = cbm_gbuf_find_edges_by_source_type(gbuf, file_node->id, "IMPORTS",
- &edges, &edge_count);
- if (rc != 0 || edge_count == 0) return 0;
+ int rc =
+ cbm_gbuf_find_edges_by_source_type(gbuf, file_node->id, "IMPORTS", &edges, &edge_count);
+ if (rc != 0 || edge_count == 0)
+ return 0;
const char **keys = (const char **)calloc((size_t)edge_count, sizeof(const char *));
const char **vals = (const char **)calloc((size_t)edge_count, sizeof(const char *));
@@ -220,15 +222,19 @@ static int pxc_build_import_map(const cbm_gbuf_t *gbuf, const char *project_name
for (int i = 0; i < edge_count; i++) {
const cbm_gbuf_edge_t *e = edges[i];
const cbm_gbuf_node_t *target = cbm_gbuf_find_by_id(gbuf, e->target_id);
- if (!target || !e->properties_json) continue;
+ if (!target || !e->properties_json)
+ continue;
const char *start = strstr(e->properties_json, "\"local_name\":\"");
- if (!start) continue;
+ if (!start)
+ continue;
start += strlen("\"local_name\":\"");
const char *end = strchr(start, '"');
- if (!end || end <= start) continue;
+ if (!end || end <= start)
+ continue;
size_t n = (size_t)(end - start);
char *local = (char *)malloc(n + 1);
- if (!local) continue;
+ if (!local)
+ continue;
memcpy(local, start, n);
local[n] = '\0';
keys[count] = local;
@@ -243,26 +249,26 @@ static int pxc_build_import_map(const cbm_gbuf_t *gbuf, const char *project_name
static void pxc_free_import_map(const char **keys, const char **vals, int count) {
if (keys) {
- for (int i = 0; i < count; i++) free((void *)keys[i]);
+ for (int i = 0; i < count; i++)
+ free((void *)keys[i]);
free((void *)keys);
}
free((void *)vals); /* vals strings borrowed from gbuf — don't free elements */
}
/* Detect TS dialect flags from a relative path. */
-void cbm_pxc_ts_modes(CBMLanguage lang, const char *rel_path,
- bool *out_js, bool *out_jsx, bool *out_dts) {
+void cbm_pxc_ts_modes(CBMLanguage lang, const char *rel_path, bool *out_js, bool *out_jsx,
+ bool *out_dts) {
*out_js = (lang == CBM_LANG_JAVASCRIPT);
*out_jsx = (lang == CBM_LANG_TSX);
*out_dts = false;
- if (!rel_path) return;
+ if (!rel_path)
+ return;
size_t rl = strlen(rel_path);
- if (lang == CBM_LANG_JAVASCRIPT && rl >= 4 &&
- strcmp(rel_path + rl - 4, ".jsx") == 0) {
+ if (lang == CBM_LANG_JAVASCRIPT && rl >= 4 && strcmp(rel_path + rl - 4, ".jsx") == 0) {
*out_jsx = true;
}
- if (lang == CBM_LANG_TYPESCRIPT && rl >= 5 &&
- strcmp(rel_path + rl - 5, ".d.ts") == 0) {
+ if (lang == CBM_LANG_TYPESCRIPT && rl >= 5 && strcmp(rel_path + rl - 5, ".d.ts") == 0) {
*out_dts = true;
}
}
@@ -288,13 +294,13 @@ bool cbm_pxc_has_cross_lsp(CBMLanguage lang) {
/* True when (caller_qn, callee_qn) is already present in arr. Mirrors the
* intra-LSP dedup in py_emit_resolved_call / ts_emit_resolved_call so that
* cross-file entries duplicating per-file output get dropped at append. */
-static bool pxc_already_resolved(const CBMResolvedCallArray *arr,
- const char *caller_qn, const char *callee_qn) {
- if (!arr || !caller_qn || !callee_qn) return false;
+static bool pxc_already_resolved(const CBMResolvedCallArray *arr, const char *caller_qn,
+ const char *callee_qn) {
+ if (!arr || !caller_qn || !callee_qn)
+ return false;
for (int i = 0; i < arr->count; i++) {
const CBMResolvedCall *rc = &arr->items[i];
- if (rc->caller_qn && rc->callee_qn &&
- strcmp(rc->caller_qn, caller_qn) == 0 &&
+ if (rc->caller_qn && rc->callee_qn && strcmp(rc->caller_qn, caller_qn) == 0 &&
strcmp(rc->callee_qn, callee_qn) == 0) {
return true;
}
@@ -308,12 +314,15 @@ static bool pxc_already_resolved(const CBMResolvedCallArray *arr,
* (caller_qn, callee_qn) is already in dst_calls — avoids inflating the
* array with cross-file duplicates of per-file LSP output. */
static void pxc_append_results(CBMArena *dst_arena, CBMResolvedCallArray *dst_calls,
- const CBMResolvedCallArray *src_out) {
- if (!dst_calls || !src_out) return;
+ const CBMResolvedCallArray *src_out) {
+ if (!dst_calls || !src_out)
+ return;
for (int j = 0; j < src_out->count; j++) {
const CBMResolvedCall *src = &src_out->items[j];
- if (!src->caller_qn || !src->callee_qn) continue;
- if (pxc_already_resolved(dst_calls, src->caller_qn, src->callee_qn)) continue;
+ if (!src->caller_qn || !src->callee_qn)
+ continue;
+ if (pxc_already_resolved(dst_calls, src->caller_qn, src->callee_qn))
+ continue;
CBMResolvedCall dst;
memset(&dst, 0, sizeof(dst));
dst.caller_qn = cbm_arena_strdup(dst_arena, src->caller_qn);
@@ -332,10 +341,9 @@ static void pxc_append_results(CBMArena *dst_arena, CBMResolvedCallArray *dst_ca
* directly across N files (test_incremental.c saw 3.5 GB peak on a
* 1100-file repo before this fix). Output gets copied into the file's own
* arena and merged into result->resolved_calls. */
-void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source,
- int source_len, const char *module_qn,
- CBMLSPDef *defs, int def_count,
- const char **imp_names, const char **imp_qns, int imp_count) {
+void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source, int source_len,
+ const char *module_qn, CBMLSPDef *defs, int def_count, const char **imp_names,
+ const char **imp_qns, int imp_count) {
TSTree *tree = r->cached_tree; /* may be NULL — LSP re-parses then */
CBMArena scratch;
@@ -345,9 +353,8 @@ void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source,
switch (lang) {
case CBM_LANG_GO:
- cbm_run_go_lsp_cross(&scratch, source, source_len, module_qn,
- defs, def_count, imp_names, imp_qns, imp_count, tree,
- &out);
+ cbm_run_go_lsp_cross(&scratch, source, source_len, module_qn, defs, def_count, imp_names,
+ imp_qns, imp_count, tree, &out);
break;
case CBM_LANG_C:
case CBM_LANG_CPP:
@@ -357,20 +364,17 @@ void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source,
* imports — the existing pipeline doesn't carry C-style include
* resolution as a separate map, so pass NULL/0 and let the LSP
* fall back to its own #include scan. */
- cbm_run_c_lsp_cross(&scratch, source, source_len, module_qn, cpp_mode,
- defs, def_count, NULL, NULL, 0, tree,
- &out);
+ cbm_run_c_lsp_cross(&scratch, source, source_len, module_qn, cpp_mode, defs, def_count,
+ NULL, NULL, 0, tree, &out);
break;
}
case CBM_LANG_PYTHON:
- cbm_run_py_lsp_cross(&scratch, source, source_len, module_qn,
- defs, def_count, imp_names, imp_qns, imp_count, tree,
- &out);
+ cbm_run_py_lsp_cross(&scratch, source, source_len, module_qn, defs, def_count, imp_names,
+ imp_qns, imp_count, tree, &out);
break;
case CBM_LANG_PHP:
- cbm_run_php_lsp_cross(&scratch, source, source_len, module_qn,
- defs, def_count, imp_names, imp_qns, imp_count, tree,
- &out);
+ cbm_run_php_lsp_cross(&scratch, source, source_len, module_qn, defs, def_count, imp_names,
+ imp_qns, imp_count, tree, &out);
break;
default:
break;
@@ -382,33 +386,28 @@ void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source,
/* Variant of cbm_pxc_run_one for TS/JS/JSX/TSX with explicit dialect
* flags. Same scratch-arena lifecycle as cbm_pxc_run_one. */
-void cbm_pxc_run_one_ts(CBMFileResult *r, const char *source, int source_len,
- const char *module_qn,
- CBMLSPDef *defs, int def_count,
- const char **imp_names, const char **imp_qns, int imp_count,
- bool js_mode, bool jsx_mode, bool dts_mode) {
+void cbm_pxc_run_one_ts(CBMFileResult *r, const char *source, int source_len, const char *module_qn,
+ CBMLSPDef *defs, int def_count, const char **imp_names,
+ const char **imp_qns, int imp_count, bool js_mode, bool jsx_mode,
+ bool dts_mode) {
CBMArena scratch;
cbm_arena_init(&scratch);
CBMResolvedCallArray out;
memset(&out, 0, sizeof(out));
- cbm_run_ts_lsp_cross(&scratch, source, source_len, module_qn,
- js_mode, jsx_mode, dts_mode,
- defs, def_count, imp_names, imp_qns, imp_count,
- r->cached_tree, &out);
+ cbm_run_ts_lsp_cross(&scratch, source, source_len, module_qn, js_mode, jsx_mode, dts_mode, defs,
+ def_count, imp_names, imp_qns, imp_count, r->cached_tree, &out);
pxc_append_results(&r->arena, &r->resolved_calls, &out);
cbm_arena_destroy(&scratch);
}
-int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx,
- const cbm_file_info_t *files,
- int file_count,
- CBMFileResult **cache) {
- if (!ctx || !files || file_count <= 0 || !cache) return 0;
+int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
+ int file_count, CBMFileResult **cache) {
+ if (!ctx || !files || file_count <= 0 || !cache)
+ return 0;
- cbm_log_info("pass.start", "pass", "lsp_cross", "files",
- itoa_buf(file_count));
+ cbm_log_info("pass.start", "pass", "lsp_cross", "files", itoa_buf(file_count));
/* Per-file module QN cache so we don't recompute it once per def + once
* per call. cbm_pipeline_fqn_module mallocs; freed at end. */
@@ -419,9 +418,8 @@ int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx,
}
int def_count = 0;
- CBMLSPDef *all_defs = cbm_pxc_collect_all_defs(cache, files, file_count,
- ctx->project_name, def_modules,
- &def_count);
+ CBMLSPDef *all_defs = cbm_pxc_collect_all_defs(cache, files, file_count, ctx->project_name,
+ def_modules, &def_count);
int processed = 0;
int skipped_no_lsp = 0;
@@ -429,7 +427,8 @@ int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx,
int per_lang_calls = 0;
for (int i = 0; i < file_count; i++) {
- if (!cache[i]) continue;
+ if (!cache[i])
+ continue;
CBMLanguage lang = files[i].language;
if (!cbm_pxc_has_cross_lsp(lang)) {
skipped_no_lsp++;
@@ -451,19 +450,17 @@ int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx,
const char **imp_keys = NULL;
const char **imp_vals = NULL;
int imp_count = 0;
- pxc_build_import_map(ctx->gbuf, ctx->project_name, files[i].rel_path,
- &imp_keys, &imp_vals, &imp_count);
+ pxc_build_import_map(ctx->gbuf, ctx->project_name, files[i].rel_path, &imp_keys, &imp_vals,
+ &imp_count);
- if (lang == CBM_LANG_JAVASCRIPT || lang == CBM_LANG_TYPESCRIPT ||
- lang == CBM_LANG_TSX) {
+ if (lang == CBM_LANG_JAVASCRIPT || lang == CBM_LANG_TYPESCRIPT || lang == CBM_LANG_TSX) {
bool js, jsx, dts;
cbm_pxc_ts_modes(lang, files[i].rel_path, &js, &jsx, &dts);
- cbm_pxc_run_one_ts(cache[i], source, source_len, def_modules[i],
- all_defs, def_count, imp_keys, imp_vals, imp_count,
- js, jsx, dts);
+ cbm_pxc_run_one_ts(cache[i], source, source_len, def_modules[i], all_defs, def_count,
+ imp_keys, imp_vals, imp_count, js, jsx, dts);
} else {
- cbm_pxc_run_one(lang, cache[i], source, source_len, def_modules[i],
- all_defs, def_count, imp_keys, imp_vals, imp_count);
+ cbm_pxc_run_one(lang, cache[i], source, source_len, def_modules[i], all_defs, def_count,
+ imp_keys, imp_vals, imp_count);
}
per_lang_calls++;
processed++;
@@ -473,15 +470,14 @@ int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx,
}
free(all_defs);
- for (int i = 0; i < file_count; i++) free(def_modules[i]);
+ for (int i = 0; i < file_count; i++)
+ free(def_modules[i]);
free(def_modules);
- cbm_log_info("pass.done", "pass", "lsp_cross",
- "files_processed", itoa_buf(processed),
- "files_skipped_no_lsp", itoa_buf(skipped_no_lsp),
- "files_skipped_no_source", itoa_buf(skipped_no_source),
- "defs_total", itoa_buf(def_count),
- "lsp_calls", itoa_buf(per_lang_calls));
+ cbm_log_info("pass.done", "pass", "lsp_cross", "files_processed", itoa_buf(processed),
+ "files_skipped_no_lsp", itoa_buf(skipped_no_lsp), "files_skipped_no_source",
+ itoa_buf(skipped_no_source), "defs_total", itoa_buf(def_count), "lsp_calls",
+ itoa_buf(per_lang_calls));
return 0;
}
@@ -502,25 +498,30 @@ static void pxc_module_entry_free_cb(const char *key, void *value, void *userdat
(void)key;
(void)userdata;
pxc_module_entry_t *e = (pxc_module_entry_t *)value;
- if (!e) return;
+ if (!e)
+ return;
free(e->indices);
free(e);
}
CBMModuleDefIndex *cbm_pxc_build_module_def_index(CBMLSPDef *all_defs, int def_count) {
- if (!all_defs || def_count <= 0) return NULL;
+ if (!all_defs || def_count <= 0)
+ return NULL;
CBMHashTable *ht = cbm_ht_create(64);
- if (!ht) return NULL;
+ if (!ht)
+ return NULL;
/* Single pass: append each def's index into its module's dynamic array. */
for (int i = 0; i < def_count; i++) {
const char *mod = all_defs[i].def_module_qn;
- if (!mod) continue;
+ if (!mod)
+ continue;
pxc_module_entry_t *e = (pxc_module_entry_t *)cbm_ht_get(ht, mod);
if (!e) {
e = (pxc_module_entry_t *)calloc(1, sizeof(*e));
- if (!e) continue;
+ if (!e)
+ continue;
e->cap = 16;
e->indices = (int *)malloc((size_t)e->cap * sizeof(int));
if (!e->indices) {
@@ -532,7 +533,8 @@ CBMModuleDefIndex *cbm_pxc_build_module_def_index(CBMLSPDef *all_defs, int def_c
if (e->count >= e->cap) {
int new_cap = e->cap * 2;
int *new_indices = (int *)realloc(e->indices, (size_t)new_cap * sizeof(int));
- if (!new_indices) continue; /* drop this entry, keep going */
+ if (!new_indices)
+ continue; /* drop this entry, keep going */
e->indices = new_indices;
e->cap = new_cap;
}
@@ -550,7 +552,8 @@ CBMModuleDefIndex *cbm_pxc_build_module_def_index(CBMLSPDef *all_defs, int def_c
}
void cbm_pxc_free_module_def_index(CBMModuleDefIndex *idx) {
- if (!idx) return;
+ if (!idx)
+ return;
if (idx->ht) {
cbm_ht_foreach(idx->ht, pxc_module_entry_free_cb, NULL);
cbm_ht_free(idx->ht);
@@ -558,14 +561,13 @@ void cbm_pxc_free_module_def_index(CBMModuleDefIndex *idx) {
free(idx);
}
-CBMLSPDef *cbm_pxc_filter_defs_for_file(const CBMModuleDefIndex *idx,
- CBMLSPDef *all_defs,
- const char *own_module,
- const char *const *imp_qns,
- int imp_count,
- int *out_count) {
- if (out_count) *out_count = 0;
- if (!idx || !idx->ht || !all_defs || !out_count) return NULL;
+CBMLSPDef *cbm_pxc_filter_defs_for_file(const CBMModuleDefIndex *idx, CBMLSPDef *all_defs,
+ const char *own_module, const char *const *imp_qns,
+ int imp_count, int *out_count) {
+ if (out_count)
+ *out_count = 0;
+ if (!idx || !idx->ht || !all_defs || !out_count)
+ return NULL;
/* Dedup module list (own_module may appear in imp_qns). For typical
* imp_count ~10 this O(N²) scan is fine and avoids registering the
@@ -576,7 +578,8 @@ CBMLSPDef *cbm_pxc_filter_defs_for_file(const CBMModuleDefIndex *idx,
seen[seen_count++] = own_module;
}
for (int i = 0; i < imp_count && seen_count < (int)(sizeof(seen) / sizeof(seen[0])); i++) {
- if (!imp_qns[i]) continue;
+ if (!imp_qns[i])
+ continue;
bool dup = false;
for (int s = 0; s < seen_count; s++) {
if (strcmp(seen[s], imp_qns[i]) == 0) {
@@ -584,26 +587,31 @@ CBMLSPDef *cbm_pxc_filter_defs_for_file(const CBMModuleDefIndex *idx,
break;
}
}
- if (!dup) seen[seen_count++] = imp_qns[i];
+ if (!dup)
+ seen[seen_count++] = imp_qns[i];
}
/* Pass 1: total relevant defs. */
int total = 0;
for (int s = 0; s < seen_count; s++) {
pxc_module_entry_t *e = (pxc_module_entry_t *)cbm_ht_get(idx->ht, seen[s]);
- if (e) total += e->count;
+ if (e)
+ total += e->count;
}
- if (total == 0) return NULL;
+ if (total == 0)
+ return NULL;
/* Pass 2: copy CBMLSPDef structs (string fields stay borrowed from the
* caller's all_defs[] arena). */
CBMLSPDef *out = (CBMLSPDef *)malloc((size_t)total * sizeof(CBMLSPDef));
- if (!out) return NULL;
+ if (!out)
+ return NULL;
int n = 0;
for (int s = 0; s < seen_count; s++) {
pxc_module_entry_t *e = (pxc_module_entry_t *)cbm_ht_get(idx->ht, seen[s]);
- if (!e) continue;
+ if (!e)
+ continue;
for (int j = 0; j < e->count; j++) {
out[n++] = all_defs[e->indices[j]];
}
diff --git a/src/pipeline/pass_lsp_cross.h b/src/pipeline/pass_lsp_cross.h
index f3ba6e17f..adca0801b 100644
--- a/src/pipeline/pass_lsp_cross.h
+++ b/src/pipeline/pass_lsp_cross.h
@@ -48,16 +48,13 @@ bool cbm_pxc_has_cross_lsp(CBMLanguage lang);
* use. Returns the malloc'd array (free() it) and writes the entry
* count to *out_count. Returns NULL on alloc failure or when no defs
* exist. */
-CBMLSPDef *cbm_pxc_collect_all_defs(CBMFileResult **cache,
- const cbm_file_info_t *files,
- int file_count,
- const char *project_name,
- char **def_modules,
+CBMLSPDef *cbm_pxc_collect_all_defs(CBMFileResult **cache, const cbm_file_info_t *files,
+ int file_count, const char *project_name, char **def_modules,
int *out_count);
/* Detect TS dialect flags from a relative path. */
-void cbm_pxc_ts_modes(CBMLanguage lang, const char *rel_path,
- bool *out_js, bool *out_jsx, bool *out_dts);
+void cbm_pxc_ts_modes(CBMLanguage lang, const char *rel_path, bool *out_js, bool *out_jsx,
+ bool *out_dts);
/* ── Per-module def index (the gopls "package summary" pattern) ──
*
@@ -79,8 +76,7 @@ void cbm_pxc_ts_modes(CBMLanguage lang, const char *rel_path,
* 110k → ~50× per-file speedup on the dominant cost. */
typedef struct CBMModuleDefIndex CBMModuleDefIndex;
-CBMModuleDefIndex *cbm_pxc_build_module_def_index(CBMLSPDef *all_defs,
- int def_count);
+CBMModuleDefIndex *cbm_pxc_build_module_def_index(CBMLSPDef *all_defs, int def_count);
void cbm_pxc_free_module_def_index(CBMModuleDefIndex *idx);
@@ -90,12 +86,9 @@ void cbm_pxc_free_module_def_index(CBMModuleDefIndex *idx);
* (caller keeps it alive). Caller frees the returned array with
* free(). Writes the entry count to *out_count. Returns NULL if no
* matches (with *out_count = 0). */
-CBMLSPDef *cbm_pxc_filter_defs_for_file(const CBMModuleDefIndex *idx,
- CBMLSPDef *all_defs,
- const char *own_module,
- const char *const *imp_qns,
- int imp_count,
- int *out_count);
+CBMLSPDef *cbm_pxc_filter_defs_for_file(const CBMModuleDefIndex *idx, CBMLSPDef *all_defs,
+ const char *own_module, const char *const *imp_qns,
+ int imp_count, int *out_count);
/* ── Tier 2 full: pre-built per-language cross-LSP registries ─────
*
@@ -116,21 +109,29 @@ typedef struct {
/* Return the appropriate pre-built registry for a language, or NULL
* if none was built (or language has no cross-LSP entrypoint). */
-static inline CBMTypeRegistry *cbm_pxc_registry_for_lang(
- const CBMCrossLspRegistries *r, CBMLanguage lang) {
- if (!r) return NULL;
+static inline CBMTypeRegistry *cbm_pxc_registry_for_lang(const CBMCrossLspRegistries *r,
+ CBMLanguage lang) {
+ if (!r)
+ return NULL;
switch (lang) {
- case CBM_LANG_GO: return r->go;
- case CBM_LANG_C: /* fallthrough */
- case CBM_LANG_CPP: /* fallthrough */
- case CBM_LANG_CUDA: return r->c;
- case CBM_LANG_PYTHON: return r->python;
+ case CBM_LANG_GO:
+ return r->go;
+ case CBM_LANG_C: /* fallthrough */
+ case CBM_LANG_CPP: /* fallthrough */
+ case CBM_LANG_CUDA:
+ return r->c;
+ case CBM_LANG_PYTHON:
+ return r->python;
case CBM_LANG_JAVASCRIPT: /* fallthrough */
case CBM_LANG_TYPESCRIPT: /* fallthrough */
- case CBM_LANG_TSX: return r->ts;
- case CBM_LANG_PHP: return r->php;
- case CBM_LANG_CSHARP: return r->cs;
- default: return NULL;
+ case CBM_LANG_TSX:
+ return r->ts;
+ case CBM_LANG_PHP:
+ return r->php;
+ case CBM_LANG_CSHARP:
+ return r->cs;
+ default:
+ return NULL;
}
}
@@ -139,20 +140,14 @@ static inline CBMTypeRegistry *cbm_pxc_registry_for_lang(
* owns source, module_qn, all_defs, imp_keys, imp_vals.
* NOTE: all_defs is read-only in practice but typed non-const to match
* the existing cbm_run_X_lsp_cross callee signatures. */
-void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r,
- const char *source, int source_len,
- const char *module_qn,
- CBMLSPDef *all_defs, int def_count,
- const char **imp_keys, const char **imp_vals,
- int imp_count);
+void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source, int source_len,
+ const char *module_qn, CBMLSPDef *all_defs, int def_count,
+ const char **imp_keys, const char **imp_vals, int imp_count);
/* TS / JS / JSX / TSX variant with explicit dialect flags. */
-void cbm_pxc_run_one_ts(CBMFileResult *r,
- const char *source, int source_len,
- const char *module_qn,
- CBMLSPDef *all_defs, int def_count,
- const char **imp_keys, const char **imp_vals,
- int imp_count,
- bool js_mode, bool jsx_mode, bool dts_mode);
+void cbm_pxc_run_one_ts(CBMFileResult *r, const char *source, int source_len, const char *module_qn,
+ CBMLSPDef *all_defs, int def_count, const char **imp_keys,
+ const char **imp_vals, int imp_count, bool js_mode, bool jsx_mode,
+ bool dts_mode);
#endif /* CBM_PIPELINE_PASS_LSP_CROSS_H */
diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.c
index 2d8d6edcd..52075d31e 100644
--- a/src/pipeline/pass_parallel.c
+++ b/src/pipeline/pass_parallel.c
@@ -536,24 +536,21 @@ static void extract_worker(int worker_id, void *ctx_ptr) {
* Skipping retention just means cross-file LSP no-ops for this
* file — defs/calls already extracted are unaffected. */
if (source_len > 0 && (int64_t)source_len <= PP_RETAIN_PER_FILE_MAX_BYTES) {
- int64_t prior = atomic_fetch_add_explicit(
- &ec->retained_bytes, (int64_t)source_len, memory_order_relaxed);
+ int64_t prior = atomic_fetch_add_explicit(&ec->retained_bytes, (int64_t)source_len,
+ memory_order_relaxed);
if (prior + (int64_t)source_len <= PP_RETAIN_TOTAL_BUDGET_BYTES) {
- char *copy = (char *)cbm_arena_alloc(&result->arena,
- (size_t)source_len + 1);
+ char *copy = (char *)cbm_arena_alloc(&result->arena, (size_t)source_len + 1);
if (copy) {
memcpy(copy, source, (size_t)source_len);
copy[source_len] = '\0';
result->source = copy;
result->source_len = source_len;
} else {
- atomic_fetch_sub_explicit(&ec->retained_bytes,
- (int64_t)source_len,
+ atomic_fetch_sub_explicit(&ec->retained_bytes, (int64_t)source_len,
memory_order_relaxed);
}
} else {
- atomic_fetch_sub_explicit(&ec->retained_bytes,
- (int64_t)source_len,
+ atomic_fetch_sub_explicit(&ec->retained_bytes, (int64_t)source_len,
memory_order_relaxed);
}
}
@@ -924,16 +921,16 @@ typedef struct {
* setup, or — most likely — workers waiting on the
* cbm_parallel_for synchronization barrier at the end. */
_Atomic uint64_t time_ns_total_loop;
- _Atomic int total_files_visited;
+ _Atomic int total_files_visited;
/* Sub-breakdowns inside resolve_file_calls — finds the 553µs-per-
* iteration hot path that the high-level resolve_calls counter
* doesn't pinpoint. */
- _Atomic uint64_t time_ns_rc_lsp_lookup; /* lsp_idx + fallback scan */
- _Atomic uint64_t time_ns_rc_resolve; /* lsp_target_node OR registry_resolve */
- _Atomic uint64_t time_ns_rc_hint; /* try_field_type_hint */
- _Atomic uint64_t time_ns_rc_target; /* gbuf_find_by_qn for target */
- _Atomic uint64_t time_ns_rc_emit; /* emit_service_edge */
- _Atomic uint64_t time_ns_rc_source; /* find_source_node */
+ _Atomic uint64_t time_ns_rc_lsp_lookup; /* lsp_idx + fallback scan */
+ _Atomic uint64_t time_ns_rc_resolve; /* lsp_target_node OR registry_resolve */
+ _Atomic uint64_t time_ns_rc_hint; /* try_field_type_hint */
+ _Atomic uint64_t time_ns_rc_target; /* gbuf_find_by_qn for target */
+ _Atomic uint64_t time_ns_rc_emit; /* emit_service_edge */
+ _Atomic uint64_t time_ns_rc_source; /* find_source_node */
} resolve_ctx_t;
/* Minimum buffer space needed per arg JSON object */
@@ -1581,16 +1578,19 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
short_name = short_name ? short_name + 1 : rc_e->callee_qn;
char key[1024];
int kn = snprintf(key, sizeof(key), "%s|%s", rc_e->caller_qn, short_name);
- if (kn <= 0 || kn >= (int)sizeof(key)) continue;
+ if (kn <= 0 || kn >= (int)sizeof(key))
+ continue;
CBMResolvedCall *existing = (CBMResolvedCall *)cbm_ht_get(lsp_idx, key);
if (!existing) {
/* New entry — strdup so the key outlives the loop body. */
char *kdup = strdup(key);
- if (kdup) cbm_ht_set(lsp_idx, kdup, rc_e);
+ if (kdup)
+ cbm_ht_set(lsp_idx, kdup, rc_e);
} else if (rc_e->confidence > existing->confidence) {
/* Update value; reuse stored key pointer to avoid leak. */
const char *skey = cbm_ht_get_key(lsp_idx, key);
- if (skey) cbm_ht_set(lsp_idx, skey, rc_e);
+ if (skey)
+ cbm_ht_set(lsp_idx, skey, rc_e);
}
}
}
@@ -1604,7 +1604,8 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
uint64_t _rc_t0 = extract_now_ns();
const cbm_gbuf_node_t *source_node =
find_source_node(rc->main_gbuf, rc->project_name, rel, call->enclosing_func_qn);
- atomic_fetch_add_explicit(&rc->time_ns_rc_source, extract_now_ns() - _rc_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_rc_source, extract_now_ns() - _rc_t0,
+ memory_order_relaxed);
if (!source_node) {
continue;
}
@@ -1619,8 +1620,8 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
_rc_t0 = extract_now_ns();
if (lsp_idx && call->enclosing_func_qn) {
char key[1024];
- int kn = snprintf(key, sizeof(key), "%s|%s",
- call->enclosing_func_qn, call->callee_name);
+ int kn =
+ snprintf(key, sizeof(key), "%s|%s", call->enclosing_func_qn, call->callee_name);
if (kn > 0 && kn < (int)sizeof(key)) {
lsp = (const CBMResolvedCall *)cbm_ht_get(lsp_idx, key);
}
@@ -1631,7 +1632,8 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
* name). Keeps semantics identical. */
lsp = cbm_pipeline_find_lsp_resolution(&result->resolved_calls, call);
}
- atomic_fetch_add_explicit(&rc->time_ns_rc_lsp_lookup, extract_now_ns() - _rc_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_rc_lsp_lookup, extract_now_ns() - _rc_t0,
+ memory_order_relaxed);
_rc_t0 = extract_now_ns();
const cbm_gbuf_node_t *lsp_target = NULL;
if (lsp) {
@@ -1651,14 +1653,16 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
ws->lsp_overrides++;
}
} else {
- res = cbm_registry_resolve(rc->registry, call->callee_name, module_qn,
- imp_keys, imp_vals, imp_count);
+ res = cbm_registry_resolve(rc->registry, call->callee_name, module_qn, imp_keys,
+ imp_vals, imp_count);
}
- atomic_fetch_add_explicit(&rc->time_ns_rc_resolve, extract_now_ns() - _rc_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_rc_resolve, extract_now_ns() - _rc_t0,
+ memory_order_relaxed);
_rc_t0 = extract_now_ns();
try_field_type_hint(rc, &res, call->callee_name, source_node->id);
- atomic_fetch_add_explicit(&rc->time_ns_rc_hint, extract_now_ns() - _rc_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_rc_hint, extract_now_ns() - _rc_t0,
+ memory_order_relaxed);
if (!res.qualified_name || res.qualified_name[0] == '\0') {
if (cbm_service_pattern_route_method(call->callee_name) != NULL) {
@@ -1682,14 +1686,16 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
} else {
target_node = cbm_gbuf_find_by_qn(rc->main_gbuf, res.qualified_name);
}
- atomic_fetch_add_explicit(&rc->time_ns_rc_target, extract_now_ns() - _rc_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_rc_target, extract_now_ns() - _rc_t0,
+ memory_order_relaxed);
if (!target_node || source_node->id == target_node->id) {
continue;
}
_rc_t0 = extract_now_ns();
emit_service_edge(ws->local_edge_buf, source_node, target_node, call, &res, module_qn,
rc->registry, rc->main_gbuf, imp_keys, imp_vals, imp_count);
- atomic_fetch_add_explicit(&rc->time_ns_rc_emit, extract_now_ns() - _rc_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_rc_emit, extract_now_ns() - _rc_t0,
+ memory_order_relaxed);
ws->calls_resolved++;
}
if (lsp_idx) {
@@ -1901,8 +1907,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
CBMFileResult *result = rc->result_cache[file_idx];
if (!result) {
- atomic_fetch_add_explicit(&rc->time_ns_total_loop,
- extract_now_ns() - _loop_t0,
+ atomic_fetch_add_explicit(&rc->time_ns_total_loop, extract_now_ns() - _loop_t0,
memory_order_relaxed);
continue;
}
@@ -1921,17 +1926,12 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
bool is_generated = false;
if (rel) {
is_generated =
- (strstr(rel, ".pb.go") != NULL) ||
- (strstr(rel, "zz_generated") != NULL) ||
- (strstr(rel, "_generated.go") != NULL) ||
- (strstr(rel, ".gen.go") != NULL) ||
+ (strstr(rel, ".pb.go") != NULL) || (strstr(rel, "zz_generated") != NULL) ||
+ (strstr(rel, "_generated.go") != NULL) || (strstr(rel, ".gen.go") != NULL) ||
(strstr(rel, "/applyconfigurations/") != NULL) ||
- (strstr(rel, "_pb2.py") != NULL) ||
- (strstr(rel, "_pb2_grpc.py") != NULL) ||
- (strstr(rel, ".pb.cc") != NULL) ||
- (strstr(rel, ".pb.h") != NULL) ||
- (strstr(rel, ".pb-c.c") != NULL) ||
- (strstr(rel, ".pb-c.h") != NULL);
+ (strstr(rel, "_pb2.py") != NULL) || (strstr(rel, "_pb2_grpc.py") != NULL) ||
+ (strstr(rel, ".pb.cc") != NULL) || (strstr(rel, ".pb.h") != NULL) ||
+ (strstr(rel, ".pb-c.c") != NULL) || (strstr(rel, ".pb-c.h") != NULL);
}
/* Cross-file LSP is a per-file tree-sitter re-parse + AST walk +
@@ -1946,8 +1946,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
* resolve once per-file LSP has run). */
bool cross_lsp_eligible =
(rc->all_defs && rc->def_count > 0 && cbm_pxc_has_cross_lsp(lang) &&
- result->calls.count > 0 &&
- result->resolved_calls.count < result->calls.count &&
+ result->calls.count > 0 && result->resolved_calls.count < result->calls.count &&
!is_generated);
/* Skip files with nothing else to resolve and no cross-LSP work. */
@@ -1957,7 +1956,6 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
continue;
}
-
/* Build import map ONCE (read-only access to main_gbuf). The
* same imp_keys/imp_vals feed both the fused cross-file LSP
* step below AND the resolve_file_* chain — no duplicate build. */
@@ -1966,8 +1964,8 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
int imp_count = 0;
uint64_t _imp_t0 = extract_now_ns();
build_import_map(rc->main_gbuf, rc->project_name, rel, &imp_keys, &imp_vals, &imp_count);
- atomic_fetch_add_explicit(&rc->time_ns_import_map,
- extract_now_ns() - _imp_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_import_map, extract_now_ns() - _imp_t0,
+ memory_order_relaxed);
/* Per-file is_import_reachable memoization. Spans all 5 resolve
* sub-passes (calls/usages/throws/rw/semantic) which all flow
@@ -1988,8 +1986,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
* within a file (module_qn is fixed) — first call walks the
* strategy chain, repeats are O(1). On K8s this targets the
* 98.7% hot spot in resolve_file_calls (881 of 893s CPU). */
- cbm_registry_resolve_cache_begin(
- result->calls.count + result->usages.count + 64);
+ cbm_registry_resolve_cache_begin(result->calls.count + result->usages.count + 64);
char *module_qn = cbm_pipeline_fqn_module(rc->project_name, rel);
@@ -2009,9 +2006,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
* walks across thousands of files in a single worker thread. */
if (cross_lsp_eligible) {
if (result->source && result->source_len > 0) {
- const char *def_module = rc->def_modules
- ? rc->def_modules[file_idx]
- : module_qn;
+ const char *def_module = rc->def_modules ? rc->def_modules[file_idx] : module_qn;
uint64_t lsp_t0 = extract_now_ns();
@@ -2020,8 +2015,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
* and pass the shared finalized registry. Dispatch per-lang
* to the appropriate _with_registry variant. */
bool used_prebuilt = false;
- CBMTypeRegistry *prebuilt =
- cbm_pxc_registry_for_lang(rc->cross_registries, lang);
+ CBMTypeRegistry *prebuilt = cbm_pxc_registry_for_lang(rc->cross_registries, lang);
if (prebuilt) {
switch (lang) {
case CBM_LANG_GO: {
@@ -2038,36 +2032,32 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
* just re-derive the same metadata via a second
* AST walk and arrive at the same answers — it
* is now skipped entirely for Go. */
- cbm_go_fast_resolve_qualified_calls(
- result, prebuilt,
- imp_keys, imp_vals, imp_count);
+ cbm_go_fast_resolve_qualified_calls(result, prebuilt, imp_keys, imp_vals,
+ imp_count);
used_prebuilt = true;
break;
}
case CBM_LANG_PYTHON:
cbm_run_py_lsp_cross_with_registry(
- &result->arena, result->source, result->source_len,
- def_module, prebuilt,
- imp_keys, imp_vals, imp_count,
- result->cached_tree, &result->resolved_calls);
+ &result->arena, result->source, result->source_len, def_module,
+ prebuilt, imp_keys, imp_vals, imp_count, result->cached_tree,
+ &result->resolved_calls);
used_prebuilt = true;
break;
case CBM_LANG_C:
case CBM_LANG_CPP:
case CBM_LANG_CUDA:
cbm_run_c_lsp_cross_with_registry(
- &result->arena, result->source, result->source_len,
- def_module, (lang != CBM_LANG_C), prebuilt,
- imp_keys, imp_vals, imp_count,
+ &result->arena, result->source, result->source_len, def_module,
+ (lang != CBM_LANG_C), prebuilt, imp_keys, imp_vals, imp_count,
result->cached_tree, &result->resolved_calls);
used_prebuilt = true;
break;
case CBM_LANG_CSHARP:
- cbm_run_cs_lsp_cross_with_registry(
- &result->arena, result->source, result->source_len,
- def_module, prebuilt,
- imp_vals, imp_count,
- result->cached_tree, &result->resolved_calls);
+ cbm_run_cs_lsp_cross_with_registry(&result->arena, result->source,
+ result->source_len, def_module, prebuilt,
+ imp_vals, imp_count, result->cached_tree,
+ &result->resolved_calls);
used_prebuilt = true;
break;
case CBM_LANG_JAVASCRIPT:
@@ -2086,16 +2076,17 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
CBMLSPDef *ts_filtered = NULL;
if (rc->module_def_index) {
int fc = 0;
- ts_filtered = cbm_pxc_filter_defs_for_file(
- rc->module_def_index, rc->all_defs,
- def_module, imp_vals, imp_count, &fc);
- if (ts_filtered) { ts_defs = ts_filtered; ts_def_count = fc; }
+ ts_filtered =
+ cbm_pxc_filter_defs_for_file(rc->module_def_index, rc->all_defs,
+ def_module, imp_vals, imp_count, &fc);
+ if (ts_filtered) {
+ ts_defs = ts_filtered;
+ ts_def_count = fc;
+ }
}
cbm_run_ts_lsp_cross_with_registry(
- &result->arena, result->source, result->source_len,
- def_module, js, jsx, dts, prebuilt,
- ts_defs, ts_def_count,
- imp_keys, imp_vals, imp_count,
+ &result->arena, result->source, result->source_len, def_module, js, jsx,
+ dts, prebuilt, ts_defs, ts_def_count, imp_keys, imp_vals, imp_count,
result->cached_tree, &result->resolved_calls);
free(ts_filtered);
used_prebuilt = true;
@@ -2115,10 +2106,9 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
int file_def_count = rc->def_count;
if (rc->module_def_index) {
int filtered_count = 0;
- filtered = cbm_pxc_filter_defs_for_file(
- rc->module_def_index, rc->all_defs,
- def_module, imp_vals, imp_count,
- &filtered_count);
+ filtered = cbm_pxc_filter_defs_for_file(rc->module_def_index, rc->all_defs,
+ def_module, imp_vals, imp_count,
+ &filtered_count);
if (filtered) {
file_defs = filtered;
file_def_count = filtered_count;
@@ -2128,28 +2118,26 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
lang == CBM_LANG_TSX) {
bool js, jsx, dts;
cbm_pxc_ts_modes(lang, rel, &js, &jsx, &dts);
- cbm_pxc_run_one_ts(result, result->source, result->source_len,
- def_module, file_defs, file_def_count,
- imp_keys, imp_vals, imp_count, js, jsx, dts);
+ cbm_pxc_run_one_ts(result, result->source, result->source_len, def_module,
+ file_defs, file_def_count, imp_keys, imp_vals, imp_count,
+ js, jsx, dts);
} else {
cbm_pxc_run_one(lang, result, result->source, result->source_len,
- def_module, file_defs, file_def_count,
- imp_keys, imp_vals, imp_count);
+ def_module, file_defs, file_def_count, imp_keys, imp_vals,
+ imp_count);
}
}
free(filtered);
cbm_slab_reclaim();
uint64_t lsp_elapsed_ns = extract_now_ns() - lsp_t0;
- atomic_fetch_add_explicit(&rc->time_ns_cross_lsp,
- lsp_elapsed_ns, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_cross_lsp, lsp_elapsed_ns,
+ memory_order_relaxed);
uint64_t lsp_elapsed_ms = lsp_elapsed_ns / PP_USEC_PER_MS;
if (lsp_elapsed_ms > PP_TIMER_THRESH) {
- cbm_log_info("parallel.resolve.lsp_cross.slow",
- "elapsed_ms", itoa_log((int)lsp_elapsed_ms),
- "path", rel);
+ cbm_log_info("parallel.resolve.lsp_cross.slow", "elapsed_ms",
+ itoa_log((int)lsp_elapsed_ms), "path", rel);
}
- atomic_fetch_add_explicit(&rc->lsp_cross_processed, SKIP_ONE,
- memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->lsp_cross_processed, SKIP_ONE, memory_order_relaxed);
} else {
atomic_fetch_add_explicit(&rc->lsp_cross_skipped_no_source, SKIP_ONE,
memory_order_relaxed);
@@ -2162,17 +2150,20 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
/* ── CALLS resolution ──────────────────────────────────── */
_ph_t0 = extract_now_ns();
resolve_file_calls(rc, ws, result, rel, module_qn, imp_keys, imp_vals, imp_count);
- atomic_fetch_add_explicit(&rc->time_ns_calls, extract_now_ns() - _ph_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_calls, extract_now_ns() - _ph_t0,
+ memory_order_relaxed);
/* ── USAGE resolution ──────────────────────────────────── */
_ph_t0 = extract_now_ns();
resolve_file_usages(rc, ws, result, rel, module_qn, imp_keys, imp_vals, imp_count);
- atomic_fetch_add_explicit(&rc->time_ns_usages, extract_now_ns() - _ph_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_usages, extract_now_ns() - _ph_t0,
+ memory_order_relaxed);
/* ── THROWS / RAISES ───────────────────────────────────── */
_ph_t0 = extract_now_ns();
resolve_file_throws(rc, ws, result, module_qn, imp_keys, imp_vals, imp_count);
- atomic_fetch_add_explicit(&rc->time_ns_throws, extract_now_ns() - _ph_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_throws, extract_now_ns() - _ph_t0,
+ memory_order_relaxed);
/* ── READS / WRITES ────────────────────────────────────── */
_ph_t0 = extract_now_ns();
@@ -2182,7 +2173,8 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
/* ── INHERITS + DECORATES + IMPLEMENTS ──────────────────── */
_ph_t0 = extract_now_ns();
resolve_file_semantic(rc, ws, result, module_qn, imp_keys, imp_vals, imp_count);
- atomic_fetch_add_explicit(&rc->time_ns_semantic, extract_now_ns() - _ph_t0, memory_order_relaxed);
+ atomic_fetch_add_explicit(&rc->time_ns_semantic, extract_now_ns() - _ph_t0,
+ memory_order_relaxed);
cbm_registry_reach_cache_end();
cbm_registry_import_map_cache_end();
@@ -2191,8 +2183,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
free(module_qn);
free_import_map(imp_keys, imp_vals, imp_count);
- atomic_fetch_add_explicit(&rc->time_ns_total_loop,
- extract_now_ns() - _loop_t0,
+ atomic_fetch_add_explicit(&rc->time_ns_total_loop, extract_now_ns() - _loop_t0,
memory_order_relaxed);
}
@@ -2202,8 +2193,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
int cbm_parallel_resolve(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files, int file_count,
CBMFileResult **result_cache, _Atomic int64_t *shared_ids,
int worker_count, CBMLSPDef *all_defs, int def_count,
- char *const *def_modules,
- struct CBMModuleDefIndex *module_def_index,
+ char *const *def_modules, struct CBMModuleDefIndex *module_def_index,
void *cross_registries_v) {
/* See header: typed as void* across the TU boundary; cast back here. */
CBMCrossLspRegistries *cross_registries = (CBMCrossLspRegistries *)cross_registries_v;
@@ -2282,13 +2272,12 @@ int cbm_parallel_resolve(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
* log line — surfaces how many files the fused cross-file LSP step
* actually processed vs skipped (e.g. because their source bytes
* were not retained at extract time due to the per-file/total cap). */
- cbm_log_info("parallel.resolve.lsp_cross_done",
- "files_processed",
- itoa_log(atomic_load_explicit(&rc.lsp_cross_processed, memory_order_relaxed)),
- "files_skipped_no_source",
- itoa_log(atomic_load_explicit(&rc.lsp_cross_skipped_no_source,
- memory_order_relaxed)),
- "defs_total", itoa_log(def_count));
+ cbm_log_info(
+ "parallel.resolve.lsp_cross_done", "files_processed",
+ itoa_log(atomic_load_explicit(&rc.lsp_cross_processed, memory_order_relaxed)),
+ "files_skipped_no_source",
+ itoa_log(atomic_load_explicit(&rc.lsp_cross_skipped_no_source, memory_order_relaxed)),
+ "defs_total", itoa_log(def_count));
cbm_log_info("parallel.resolve.done", "calls", itoa_log(total_calls), "usages",
itoa_log(total_usages), "semantic", itoa_log(total_semantic + go_impl),
@@ -2300,75 +2289,72 @@ int cbm_parallel_resolve(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
* ring buffer — more than 4 values per log_info call would alias
* each other (we hit that bug in the first profiling run). */
char loop_buf[32], visits_buf[32];
- snprintf(loop_buf, sizeof(loop_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_total_loop,
- memory_order_relaxed) / 1000000ULL));
+ snprintf(
+ loop_buf, sizeof(loop_buf), "%llu",
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_total_loop, memory_order_relaxed) /
+ 1000000ULL));
snprintf(visits_buf, sizeof(visits_buf), "%d",
atomic_load_explicit(&rc.total_files_visited, memory_order_relaxed));
- cbm_log_info("parallel.resolve.phase_summary",
- "total_loop_cpu_ms", loop_buf,
- "files_visited", visits_buf);
+ cbm_log_info("parallel.resolve.phase_summary", "total_loop_cpu_ms", loop_buf, "files_visited",
+ visits_buf);
char imp_buf[32], xls_buf[32], cal_buf[32];
- snprintf(imp_buf, sizeof(imp_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_import_map,
- memory_order_relaxed) / 1000000ULL));
- snprintf(xls_buf, sizeof(xls_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_cross_lsp,
- memory_order_relaxed) / 1000000ULL));
+ snprintf(
+ imp_buf, sizeof(imp_buf), "%llu",
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_import_map, memory_order_relaxed) /
+ 1000000ULL));
+ snprintf(
+ xls_buf, sizeof(xls_buf), "%llu",
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_cross_lsp, memory_order_relaxed) /
+ 1000000ULL));
snprintf(cal_buf, sizeof(cal_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_calls,
- memory_order_relaxed) / 1000000ULL));
- cbm_log_info("parallel.resolve.phase_ms_a",
- "import_map", imp_buf,
- "cross_lsp", xls_buf,
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_calls, memory_order_relaxed) /
+ 1000000ULL));
+ cbm_log_info("parallel.resolve.phase_ms_a", "import_map", imp_buf, "cross_lsp", xls_buf,
"resolve_calls", cal_buf);
char use_buf[32], thr_buf[32], rw_buf[32], sem_buf[32];
snprintf(use_buf, sizeof(use_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_usages,
- memory_order_relaxed) / 1000000ULL));
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_usages, memory_order_relaxed) /
+ 1000000ULL));
snprintf(thr_buf, sizeof(thr_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_throws,
- memory_order_relaxed) / 1000000ULL));
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_throws, memory_order_relaxed) /
+ 1000000ULL));
snprintf(rw_buf, sizeof(rw_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_rw,
- memory_order_relaxed) / 1000000ULL));
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_rw, memory_order_relaxed) /
+ 1000000ULL));
snprintf(sem_buf, sizeof(sem_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_semantic,
- memory_order_relaxed) / 1000000ULL));
- cbm_log_info("parallel.resolve.phase_ms_b",
- "resolve_usages", use_buf,
- "resolve_throws", thr_buf,
- "resolve_rw", rw_buf,
- "resolve_semantic", sem_buf);
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_semantic, memory_order_relaxed) /
+ 1000000ULL));
+ cbm_log_info("parallel.resolve.phase_ms_b", "resolve_usages", use_buf, "resolve_throws",
+ thr_buf, "resolve_rw", rw_buf, "resolve_semantic", sem_buf);
char src_buf[32], lsp_buf[32], rsv_buf[32], hnt_buf[32], tgt_buf[32], emt_buf[32];
- snprintf(src_buf, sizeof(src_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_source,
- memory_order_relaxed) / 1000000ULL));
- snprintf(lsp_buf, sizeof(lsp_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_lsp_lookup,
- memory_order_relaxed) / 1000000ULL));
- snprintf(rsv_buf, sizeof(rsv_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_resolve,
- memory_order_relaxed) / 1000000ULL));
+ snprintf(
+ src_buf, sizeof(src_buf), "%llu",
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_source, memory_order_relaxed) /
+ 1000000ULL));
+ snprintf(
+ lsp_buf, sizeof(lsp_buf), "%llu",
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_lsp_lookup, memory_order_relaxed) /
+ 1000000ULL));
+ snprintf(
+ rsv_buf, sizeof(rsv_buf), "%llu",
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_resolve, memory_order_relaxed) /
+ 1000000ULL));
snprintf(hnt_buf, sizeof(hnt_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_hint,
- memory_order_relaxed) / 1000000ULL));
- snprintf(tgt_buf, sizeof(tgt_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_target,
- memory_order_relaxed) / 1000000ULL));
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_hint, memory_order_relaxed) /
+ 1000000ULL));
+ snprintf(
+ tgt_buf, sizeof(tgt_buf), "%llu",
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_target, memory_order_relaxed) /
+ 1000000ULL));
snprintf(emt_buf, sizeof(emt_buf), "%llu",
- (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_emit,
- memory_order_relaxed) / 1000000ULL));
- cbm_log_info("parallel.resolve.calls_breakdown",
- "find_source", src_buf,
- "lsp_lookup", lsp_buf,
+ (unsigned long long)(atomic_load_explicit(&rc.time_ns_rc_emit, memory_order_relaxed) /
+ 1000000ULL));
+ cbm_log_info("parallel.resolve.calls_breakdown", "find_source", src_buf, "lsp_lookup", lsp_buf,
"resolve", rsv_buf);
- cbm_log_info("parallel.resolve.calls_breakdown2",
- "field_hint", hnt_buf,
- "find_target", tgt_buf,
+ cbm_log_info("parallel.resolve.calls_breakdown2", "field_hint", hnt_buf, "find_target", tgt_buf,
"emit_edge", emt_buf);
return 0;
}
diff --git a/src/pipeline/path_alias.c b/src/pipeline/path_alias.c
index 106ecf2ae..2d3f2d438 100644
--- a/src/pipeline/path_alias.c
+++ b/src/pipeline/path_alias.c
@@ -36,10 +36,10 @@
* (Next.js Skyline, large nx workspaces) while bounding worst-case
* memory and walk time. Cap hits are logged. */
enum {
- CBM_PATH_ALIAS_MAX_ENTRIES = 256, /* per single config file */
- CBM_PATH_ALIAS_MAX_FILES = 256, /* config files per repo walk */
+ CBM_PATH_ALIAS_MAX_ENTRIES = 256, /* per single config file */
+ CBM_PATH_ALIAS_MAX_FILES = 256, /* config files per repo walk */
CBM_PATH_ALIAS_MAX_FILE_BYTES = 64 * 1024,
- CBM_PATH_ALIAS_MAX_DEPTH = 32, /* directory recursion depth */
+ CBM_PATH_ALIAS_MAX_DEPTH = 32, /* directory recursion depth */
};
/* ── Helpers ───────────────────────────────────────────────────── */
@@ -50,14 +50,13 @@ static char *strip_resolved_ext(char *path) {
return path;
}
size_t len = strlen(path);
- if (len > 3 && path[len - 3] == '.' &&
- (path[len - 2] == 't' || path[len - 2] == 'j') && path[len - 1] == 's') {
+ if (len > 3 && path[len - 3] == '.' && (path[len - 2] == 't' || path[len - 2] == 'j') &&
+ path[len - 1] == 's') {
path[len - 3] = '\0';
return path;
}
- if (len > 4 && path[len - 4] == '.' &&
- (path[len - 3] == 't' || path[len - 3] == 'j') && path[len - 2] == 's' &&
- path[len - 1] == 'x') {
+ if (len > 4 && path[len - 4] == '.' && (path[len - 3] == 't' || path[len - 3] == 'j') &&
+ path[len - 2] == 's' && path[len - 1] == 'x') {
path[len - 4] = '\0';
}
return path;
@@ -179,8 +178,7 @@ static cbm_path_alias_map_t *load_tsconfig_file(const char *abs_path, const char
if (paths_obj && yyjson_is_obj(paths_obj)) {
size_t obj_size = yyjson_obj_size(paths_obj);
bool capped = obj_size > CBM_PATH_ALIAS_MAX_ENTRIES;
- int capacity =
- (int)(capped ? (size_t)CBM_PATH_ALIAS_MAX_ENTRIES : obj_size);
+ int capacity = (int)(capped ? (size_t)CBM_PATH_ALIAS_MAX_ENTRIES : obj_size);
if (capacity > 0) {
map->entries = calloc((size_t)capacity, sizeof(cbm_path_alias_t));
if (!map->entries) {
@@ -205,8 +203,7 @@ static cbm_path_alias_map_t *load_tsconfig_file(const char *abs_path, const char
const char *star = strchr(alias_pattern, '*');
if (star) {
entry->has_wildcard = true;
- entry->alias_prefix =
- strndup(alias_pattern, (size_t)(star - alias_pattern));
+ entry->alias_prefix = strndup(alias_pattern, (size_t)(star - alias_pattern));
entry->alias_suffix = strdup(star + 1);
} else {
entry->has_wildcard = false;
@@ -363,10 +360,9 @@ static void find_alias_files(const char *abs_dir, const char *rel_dir, alias_con
continue;
}
const char *name = ent->name;
- if (name[0] == '.' || strcmp(name, "node_modules") == 0 ||
- strcmp(name, "dist") == 0 || strcmp(name, "build") == 0 ||
- strcmp(name, ".next") == 0 || strcmp(name, "coverage") == 0 ||
- strcmp(name, "target") == 0 /* Rust */) {
+ if (name[0] == '.' || strcmp(name, "node_modules") == 0 || strcmp(name, "dist") == 0 ||
+ strcmp(name, "build") == 0 || strcmp(name, ".next") == 0 ||
+ strcmp(name, "coverage") == 0 || strcmp(name, "target") == 0 /* Rust */) {
continue;
}
char child_abs[CBM_SZ_512];
@@ -393,8 +389,7 @@ cbm_path_alias_collection_t *cbm_load_path_aliases(const char *repo_path) {
int count = 0;
find_alias_files(repo_path, "", hits, &count, CBM_PATH_ALIAS_MAX_FILES, 0);
if (count >= CBM_PATH_ALIAS_MAX_FILES) {
- cbm_log_warn("path_alias.files.cap_hit", "repo", repo_path, "kept",
- "256_of_more");
+ cbm_log_warn("path_alias.files.cap_hit", "repo", repo_path, "kept", "256_of_more");
}
if (count == 0) {
free(hits);
@@ -435,8 +430,8 @@ cbm_path_alias_collection_t *cbm_load_path_aliases(const char *repo_path) {
return coll;
}
-const cbm_path_alias_map_t *cbm_path_alias_find_for_file(
- const cbm_path_alias_collection_t *coll, const char *rel_path) {
+const cbm_path_alias_map_t *cbm_path_alias_find_for_file(const cbm_path_alias_collection_t *coll,
+ const char *rel_path) {
if (!coll || !rel_path) {
return NULL;
}
diff --git a/src/pipeline/path_alias.h b/src/pipeline/path_alias.h
index 015b75e83..5b8e2d5df 100644
--- a/src/pipeline/path_alias.h
+++ b/src/pipeline/path_alias.h
@@ -79,8 +79,8 @@ void cbm_path_alias_collection_free(cbm_path_alias_collection_t *coll);
/* Pick the nearest ancestor scope for a file path that is relative to the
* repo root. Returns the scope's alias map, or NULL if no scope applies.
* The returned pointer is owned by the collection. */
-const cbm_path_alias_map_t *cbm_path_alias_find_for_file(
- const cbm_path_alias_collection_t *coll, const char *rel_path);
+const cbm_path_alias_map_t *cbm_path_alias_find_for_file(const cbm_path_alias_collection_t *coll,
+ const char *rel_path);
/* Resolve module_path against map. Returns a heap-allocated repo-relative
* path (caller frees), or NULL when no alias entry matches and no
diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.c
index cd3da9b49..8a6f04ae9 100644
--- a/src/pipeline/pipeline.c
+++ b/src/pipeline/pipeline.c
@@ -483,9 +483,10 @@ static void run_predump_passes(cbm_pipeline_t *p, cbm_pipeline_ctx_t *ctx) {
* launching the dispatch loop). When the cache is unavailable (e.g. if the
* pipeline opted out of caching), the pass becomes a no-op since there are
* no extracted results to feed cross-file resolution. */
-static int seq_pass_lsp_cross_dispatch(cbm_pipeline_ctx_t *ctx,
- const cbm_file_info_t *files, int file_count) {
- if (!ctx || !ctx->result_cache) return 0;
+static int seq_pass_lsp_cross_dispatch(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
+ int file_count) {
+ if (!ctx || !ctx->result_cache)
+ return 0;
/* Cross-file LSP runs in every mode. */
return cbm_pipeline_pass_lsp_cross(ctx, files, file_count, ctx->result_cache);
}
@@ -597,9 +598,9 @@ static int run_parallel_pipeline(cbm_pipeline_t *p, cbm_pipeline_ctx_t *ctx,
if (run_cross_lsp) {
def_modules = (char **)calloc((size_t)file_count, sizeof(char *));
all_defs = def_modules
- ? cbm_pxc_collect_all_defs(cache, files, file_count, ctx->project_name,
- def_modules, &def_count)
- : NULL;
+ ? cbm_pxc_collect_all_defs(cache, files, file_count, ctx->project_name,
+ def_modules, &def_count)
+ : NULL;
}
/* Build inverted index: module_qn → defs. The fused resolve_worker
* uses this to filter the global all_defs[] down to just the defs
@@ -618,23 +619,18 @@ static int run_parallel_pipeline(cbm_pipeline_t *p, cbm_pipeline_ctx_t *ctx,
cbm_arena_init(&cross_lsp_arena);
CBMCrossLspRegistries cross_registries = {0};
if (all_defs) {
- cross_registries.go =
- cbm_go_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
+ cross_registries.go = cbm_go_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
cross_registries.python =
cbm_py_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
- cross_registries.c =
- cbm_c_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
- cross_registries.cs =
- cbm_cs_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
- cross_registries.ts =
- cbm_ts_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
+ cross_registries.c = cbm_c_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
+ cross_registries.cs = cbm_cs_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
+ cross_registries.ts = cbm_ts_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
}
cbm_log_info("pass.timing", "pass", "lsp_cross_prepare", "elapsed_ms",
itoa_buf((int)elapsed_ms(*t)));
cbm_clock_gettime(CLOCK_MONOTONIC, t);
- rc = cbm_parallel_resolve(ctx, files, file_count, cache, &shared_ids,
- worker_count, all_defs, def_count, def_modules,
- module_def_index, &cross_registries);
+ rc = cbm_parallel_resolve(ctx, files, file_count, cache, &shared_ids, worker_count, all_defs,
+ def_count, def_modules, module_def_index, &cross_registries);
cbm_log_info("pass.timing", "pass", "parallel_resolve", "elapsed_ms",
itoa_buf((int)elapsed_ms(*t)));
cbm_pxc_free_module_def_index(module_def_index);
diff --git a/src/pipeline/pipeline_incremental.c b/src/pipeline/pipeline_incremental.c
index d274b47e4..34668bf05 100644
--- a/src/pipeline/pipeline_incremental.c
+++ b/src/pipeline/pipeline_incremental.c
@@ -237,8 +237,7 @@ static int find_deleted_files(const char *repo_path, cbm_file_info_t *files, int
ms_cap *= PAIR_LEN;
cbm_file_hash_t *tmp = realloc(mode_skipped, (size_t)ms_cap * sizeof(*tmp));
if (!tmp) {
- cbm_log_error("incremental.err", "msg",
- "find_deleted_files_realloc_oom_ms");
+ cbm_log_error("incremental.err", "msg", "find_deleted_files_realloc_oom_ms");
break;
}
mode_skipped = tmp;
@@ -250,8 +249,8 @@ static int find_deleted_files(const char *repo_path, cbm_file_info_t *files, int
* row with a NULL rel_path that would silently fail the
* NOT NULL constraint in upsert and reintroduce the
* orphaned-node bug. */
- cbm_log_error("incremental.err", "msg", "find_deleted_files_strdup_oom",
- "rel_path", stored[i].rel_path);
+ cbm_log_error("incremental.err", "msg", "find_deleted_files_strdup_oom", "rel_path",
+ stored[i].rel_path);
free(rp);
free(sh);
break;
@@ -348,13 +347,13 @@ static void persist_hashes(cbm_store_t *store, const char *project, cbm_file_inf
* with scope=mode_skipped so the warning is searchable. */
if (mode_skipped) {
for (int i = 0; i < mode_skipped_count; i++) {
- int rc = cbm_store_upsert_file_hash(store, project, mode_skipped[i].rel_path,
- mode_skipped[i].sha256 ? mode_skipped[i].sha256
- : "",
- mode_skipped[i].mtime_ns, mode_skipped[i].size);
+ int rc =
+ cbm_store_upsert_file_hash(store, project, mode_skipped[i].rel_path,
+ mode_skipped[i].sha256 ? mode_skipped[i].sha256 : "",
+ mode_skipped[i].mtime_ns, mode_skipped[i].size);
if (rc != CBM_STORE_OK) {
- cbm_log_warn("incremental.persist_hash_failed", "scope", "mode_skipped",
- "rel_path", mode_skipped[i].rel_path, "rc", itoa_buf(rc));
+ cbm_log_warn("incremental.persist_hash_failed", "scope", "mode_skipped", "rel_path",
+ mode_skipped[i].rel_path, "rc", itoa_buf(rc));
ms_failed++;
}
}
@@ -414,9 +413,8 @@ static void run_extract_resolve(cbm_pipeline_ctx_t *ctx, cbm_file_info_t *change
* next full re-index. Pass NULL/0/NULL to make the fused
* step in resolve_worker a no-op. */
cbm_clock_gettime(CLOCK_MONOTONIC, &t);
- cbm_parallel_resolve(ctx, changed_files, ci, cache, &shared_ids,
- worker_count, NULL, 0, NULL,
- NULL /* module_def_index */,
+ cbm_parallel_resolve(ctx, changed_files, ci, cache, &shared_ids, worker_count, NULL, 0,
+ NULL, NULL /* module_def_index */,
NULL /* cross_registries — incremental skips Tier 2 prebuild */);
cbm_gbuf_set_next_id(ctx->gbuf, atomic_load(&shared_ids));
cbm_log_info("pass.timing", "pass", "incr_resolve", "elapsed_ms",
@@ -633,8 +631,7 @@ int cbm_pipeline_run_incremental(cbm_pipeline_t *p, const char *db_path, cbm_fil
cbm_log_info("incremental.registry_seed", "symbols", itoa_buf(cbm_registry_size(registry)),
"elapsed_ms", itoa_buf((int)elapsed_ms(t)));
- cbm_path_alias_collection_t *path_aliases =
- cbm_load_path_aliases(cbm_pipeline_repo_path(p));
+ cbm_path_alias_collection_t *path_aliases = cbm_load_path_aliases(cbm_pipeline_repo_path(p));
cbm_pipeline_ctx_t ctx = {
.project_name = project,
diff --git a/src/pipeline/pipeline_internal.h b/src/pipeline/pipeline_internal.h
index c89c0c050..48c3f8a2e 100644
--- a/src/pipeline/pipeline_internal.h
+++ b/src/pipeline/pipeline_internal.h
@@ -380,8 +380,7 @@ int cbm_parallel_resolve(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
* shared read-only across workers (typed non-const to match
* the existing cbm_run_X_lsp_cross signatures the resolve
* worker forwards them to). Pass NULL/0/NULL to skip. */
- CBMLSPDef *all_defs, int def_count,
- char *const *def_modules,
+ CBMLSPDef *all_defs, int def_count, char *const *def_modules,
/* Optional inverted index module_qn → defs[] — fallback
* path when there's no pre-built registry for this lang. */
struct CBMModuleDefIndex *module_def_index,
@@ -411,10 +410,8 @@ int cbm_pipeline_pass_calls(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *file
/* Cross-file LSP type-aware call resolution pass. Augments per-file
* resolved_calls with cross-file resolutions before call edges are emitted.
* Implementation: src/pipeline/pass_lsp_cross.c. */
-int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx,
- const cbm_file_info_t *files,
- int file_count,
- CBMFileResult **cache);
+int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
+ int file_count, CBMFileResult **cache);
/* Sub-passes called from pass_calls: pattern-based edge extraction */
void cbm_pipeline_pass_fastapi_depends(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
diff --git a/src/pipeline/registry.c b/src/pipeline/registry.c
index 537bac443..2e2a7fb71 100644
--- a/src/pipeline/registry.c
+++ b/src/pipeline/registry.c
@@ -17,7 +17,7 @@ enum { REG_INIT_CAP = 16, REG_MIN_CANDIDATES = 3, REG_RESOLVED = 1, REG_SUFFIX_A
#define DEFAULT_CONFIDENCE 0.5
#include "pipeline/pipeline.h"
-#include "foundation/compat.h" /* CBM_TLS */
+#include "foundation/compat.h" /* CBM_TLS */
#include "foundation/hash_table.h"
#include "foundation/dyn_array.h"
#include "foundation/platform.h"
@@ -166,7 +166,7 @@ static CBM_TLS CBMHashTable *_reach_cache = NULL;
/* Sentinels stored as values in the cache. NULL means "not cached".
* We need two distinct non-NULL pointers to encode true/false. */
-#define REACH_CACHE_TRUE ((void *)(uintptr_t)1)
+#define REACH_CACHE_TRUE ((void *)(uintptr_t)1)
#define REACH_CACHE_FALSE ((void *)(uintptr_t)2)
static void reach_cache_free_key(const char *key, void *val, void *ud) {
@@ -182,12 +182,14 @@ void cbm_registry_reach_cache_begin(int estimated_capacity) {
cbm_ht_clear(_reach_cache);
return;
}
- if (estimated_capacity < 16) estimated_capacity = 16;
+ if (estimated_capacity < 16)
+ estimated_capacity = 16;
_reach_cache = cbm_ht_create((uint32_t)estimated_capacity);
}
void cbm_registry_reach_cache_end(void) {
- if (!_reach_cache) return;
+ if (!_reach_cache)
+ return;
cbm_ht_foreach(_reach_cache, reach_cache_free_key, NULL);
cbm_ht_free(_reach_cache);
_reach_cache = NULL;
@@ -210,9 +212,11 @@ void cbm_registry_import_map_cache_begin(const char **keys, const char **vals, i
cbm_ht_free(_import_map_cache);
_import_map_cache = NULL;
}
- if (!keys || !vals || count <= 0) return;
+ if (!keys || !vals || count <= 0)
+ return;
_import_map_cache = cbm_ht_create((uint32_t)count * 2u + 8u);
- if (!_import_map_cache) return;
+ if (!_import_map_cache)
+ return;
for (int i = 0; i < count; i++) {
if (keys[i] && vals[i]) {
cbm_ht_set(_import_map_cache, keys[i], (void *)(uintptr_t)vals[i]);
@@ -221,7 +225,8 @@ void cbm_registry_import_map_cache_begin(const char **keys, const char **vals, i
}
void cbm_registry_import_map_cache_end(void) {
- if (!_import_map_cache) return;
+ if (!_import_map_cache)
+ return;
/* Keys/values borrowed from caller — no free callback needed. */
cbm_ht_free(_import_map_cache);
_import_map_cache = NULL;
@@ -260,12 +265,14 @@ void cbm_registry_resolve_cache_begin(int estimated_capacity) {
cbm_ht_free(_resolve_cache);
_resolve_cache = NULL;
}
- if (estimated_capacity < 32) estimated_capacity = 32;
+ if (estimated_capacity < 32)
+ estimated_capacity = 32;
_resolve_cache = cbm_ht_create((uint32_t)estimated_capacity);
}
void cbm_registry_resolve_cache_end(void) {
- if (!_resolve_cache) return;
+ if (!_resolve_cache)
+ return;
cbm_ht_foreach(_resolve_cache, resolve_cache_free_entry, NULL);
cbm_ht_free(_resolve_cache);
_resolve_cache = NULL;
@@ -280,8 +287,10 @@ static bool is_import_reachable(const char *candidate_qn, const char **import_va
int import_count) {
if (_reach_cache) {
void *cached = cbm_ht_get(_reach_cache, candidate_qn);
- if (cached == REACH_CACHE_TRUE) return true;
- if (cached == REACH_CACHE_FALSE) return false;
+ if (cached == REACH_CACHE_TRUE)
+ return true;
+ if (cached == REACH_CACHE_FALSE)
+ return false;
}
char cand_mod[CBM_SZ_512];
@@ -307,8 +316,7 @@ static bool is_import_reachable(const char *candidate_qn, const char **import_va
if (_reach_cache) {
char *kdup = strdup(candidate_qn);
if (kdup) {
- cbm_ht_set(_reach_cache, kdup,
- reachable ? REACH_CACHE_TRUE : REACH_CACHE_FALSE);
+ cbm_ht_set(_reach_cache, kdup, reachable ? REACH_CACHE_TRUE : REACH_CACHE_FALSE);
}
}
return reachable;
diff --git a/src/store/store.c b/src/store/store.c
index 30fddad80..0ced405db 100644
--- a/src/store/store.c
+++ b/src/store/store.c
@@ -445,7 +445,7 @@ static void regex_free_cb(void *p) {
static void sqlite_regexp(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
(void)argc;
const char *pattern = (const char *)sqlite3_value_text(argv[0]);
- const char *text = (const char *)sqlite3_value_text(argv[SKIP_ONE]);
+ const char *text = (const char *)sqlite3_value_text(argv[SKIP_ONE]);
if (!pattern || !text) {
sqlite3_result_int(ctx, 0);
return;
@@ -454,7 +454,10 @@ static void sqlite_regexp(sqlite3_context *ctx, int argc, sqlite3_value **argv)
cbm_regex_t *re = (cbm_regex_t *)sqlite3_get_auxdata(ctx, 0);
if (!re) {
re = malloc(sizeof(cbm_regex_t));
- if (!re) { sqlite3_result_error_nomem(ctx); return; }
+ if (!re) {
+ sqlite3_result_error_nomem(ctx);
+ return;
+ }
if (cbm_regcomp(re, pattern, CBM_REG_EXTENDED | CBM_REG_NOSUB) != 0) {
free(re);
sqlite3_result_error(ctx, "invalid regex", CBM_NOT_FOUND);
@@ -470,7 +473,7 @@ static void sqlite_regexp(sqlite3_context *ctx, int argc, sqlite3_value **argv)
static void sqlite_iregexp(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
(void)argc;
const char *pattern = (const char *)sqlite3_value_text(argv[0]);
- const char *text = (const char *)sqlite3_value_text(argv[SKIP_ONE]);
+ const char *text = (const char *)sqlite3_value_text(argv[SKIP_ONE]);
if (!pattern || !text) {
sqlite3_result_int(ctx, 0);
return;
@@ -479,7 +482,10 @@ static void sqlite_iregexp(sqlite3_context *ctx, int argc, sqlite3_value **argv)
cbm_regex_t *re = (cbm_regex_t *)sqlite3_get_auxdata(ctx, 0);
if (!re) {
re = malloc(sizeof(cbm_regex_t));
- if (!re) { sqlite3_result_error_nomem(ctx); return; }
+ if (!re) {
+ sqlite3_result_error_nomem(ctx);
+ return;
+ }
if (cbm_regcomp(re, pattern, CBM_REG_EXTENDED | CBM_REG_NOSUB | CBM_REG_ICASE) != 0) {
free(re);
sqlite3_result_error(ctx, "invalid regex", CBM_NOT_FOUND);
@@ -675,12 +681,11 @@ bool cbm_store_check_integrity(cbm_store_t *s) {
if (ok) {
/* Check that root_path in projects table starts with '/' or a drive letter.
* Corrupt DBs often have numeric strings like "826" in root_path. */
- rc = sqlite3_prepare_v2(
- s->db,
- "SELECT root_path FROM projects WHERE root_path != '' "
- "AND NOT (substr(root_path, 1, 1) = '/' "
- "OR (substr(root_path, 1, 1) BETWEEN 'A' AND 'Z')) LIMIT 1;",
- CBM_NOT_FOUND, &stmt, NULL);
+ rc = sqlite3_prepare_v2(s->db,
+ "SELECT root_path FROM projects WHERE root_path != '' "
+ "AND NOT (substr(root_path, 1, 1) = '/' "
+ "OR (substr(root_path, 1, 1) BETWEEN 'A' AND 'Z')) LIMIT 1;",
+ CBM_NOT_FOUND, &stmt, NULL);
if (rc == SQLITE_OK) {
if (sqlite3_step(stmt) == SQLITE_ROW) {
const char *bad_path = (const char *)sqlite3_column_text(stmt, 0);
@@ -2171,7 +2176,7 @@ typedef struct {
* Freed in one shot after both statements are finalized. */
typedef struct {
char *ptrs[ST_LIKE_POOL_MAX];
- int count;
+ int count;
} search_like_pool_t;
static void like_pool_add(search_like_pool_t *pool, char *ptr) {
@@ -2276,16 +2281,17 @@ static void where_add_regex(char *where, int where_sz, int *wlen, int *nparams,
* The idx_nodes_name index satisfies LIKE '%literal%', cutting the rows that
* reach the (more expensive) iregexp call to only those containing the literal.
* cbm_extract_like_hints bails on alternation, so no false negatives. */
-static void where_add_like_hints(const char *column, const char *pattern, char *where,
- int where_sz, int *wlen, int *nparams, search_bind_t *binds,
- int *bind_idx, search_like_pool_t *pool) {
+static void where_add_like_hints(const char *column, const char *pattern, char *where, int where_sz,
+ int *wlen, int *nparams, search_bind_t *binds, int *bind_idx,
+ search_like_pool_t *pool) {
char *hints[ST_LIKE_HINT_MAX];
int nhints = cbm_extract_like_hints(pattern, hints, ST_LIKE_HINT_MAX);
char bind_buf[CBM_SZ_64];
for (int i = 0; i < nhints; i++) {
char *lp = make_like_hint(hints[i]);
free(hints[i]);
- if (!lp) continue;
+ if (!lp)
+ continue;
like_pool_add(pool, lp);
snprintf(bind_buf, sizeof(bind_buf), "%s LIKE ?%d", column, *bind_idx + SKIP_ONE);
*wlen = where_append(where, where_sz, *wlen, nparams, bind_buf);
@@ -2310,14 +2316,14 @@ static int search_where_basic(const cbm_search_params_t *params, char *where, in
where_bind_text(binds, bind_idx, params->label);
}
if (params->name_pattern) {
- where_add_like_hints("n.name", params->name_pattern, where, where_sz, wlen, nparams,
- binds, bind_idx, pool);
+ where_add_like_hints("n.name", params->name_pattern, where, where_sz, wlen, nparams, binds,
+ bind_idx, pool);
where_add_regex(where, where_sz, wlen, nparams, binds, bind_idx, "n.name",
params->name_pattern, params->case_sensitive);
}
if (params->qn_pattern) {
- where_add_like_hints("n.qualified_name", params->qn_pattern, where, where_sz, wlen,
- nparams, binds, bind_idx, pool);
+ where_add_like_hints("n.qualified_name", params->qn_pattern, where, where_sz, wlen, nparams,
+ binds, bind_idx, pool);
where_add_regex(where, where_sz, wlen, nparams, binds, bind_idx, "n.qualified_name",
params->qn_pattern, params->case_sensitive);
}