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.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
perf(lsp): C# Tier 2 — pre-built per-language cross-LSP registry
Martin Vogel7d03632597f9
diff --git a/internal/cbm/lsp/cs_lsp.c b/internal/cbm/lsp/cs_lsp.cindex 46361ec60..ef516d0f9 100644--- a/internal/cbm/lsp/cs_lsp.c+++ b/internal/cbm/lsp/cs_lsp.c@@ -2844,17 +2844,11 @@ void cbm_run_cs_lsp(CBMArena *arena, CBMFileResult *result, const char *source,/* ── cross-file entry ───────────────────────────────────────────── */-void cbm_run_cs_lsp_cross(CBMArena *arena, const char *source, int source_len,- const char *module_qn, CBMLSPDef *defs, int def_count,- const char **using_targets, int using_count,- TSTree *cached_tree, CBMResolvedCallArray *out) {- if (!source || !arena) return;-- CBMTypeRegistry reg;- cbm_registry_init(®, arena);- cbm_csharp_stdlib_register(®, arena);-- /* Register cross-file defs. */+/* Register one batch of CBMLSPDef[] into a registry. Shared by the+ * per-file cross-LSP path and the Tier 2 pre-built registry builder.+ * Def-driven (no per-file AST mutation) so deterministic per def set. */+static void cs_register_lsp_defs(CBMArena *arena, CBMTypeRegistry *reg,+ CBMLSPDef *defs, int def_count) {for (int i = 0; i < def_count; i++) {CBMLSPDef *d = &defs[i];if (!d->qualified_name || !d->short_name || !d->label) continue;@@ -2889,7 +2883,7 @@ void cbm_run_cs_lsp_cross(CBMArena *arena, const char *source, int source_len,rt.embedded_types = arr;}}- cbm_registry_add_type(®, rt);+ cbm_registry_add_type(reg, rt);}if (strcmp(d->label, "Function") == 0 || strcmp(d->label, "Method") == 0) {CBMRegisteredFunc rf;@@ -2907,9 +2901,70 @@ void cbm_run_cs_lsp_cross(CBMArena *arena, const char *source, int source_len,rets[1] = NULL;}rf.signature = cbm_type_func(arena, NULL, NULL, rets);- cbm_registry_add_func(®, rf);+ cbm_registry_add_func(reg, rf);}}+}++/* Tier 2: build a project-wide C# registry ONCE from all defs (filters+ * by lang). Shared READ-ONLY across resolve workers. Def-driven →+ * identical entries to the per-file build, zero quality loss. */+CBMTypeRegistry *cbm_cs_build_cross_registry(CBMArena *arena, CBMLSPDef *defs, int def_count) {+ if (!arena) return NULL;+ CBMTypeRegistry *reg = (CBMTypeRegistry *)cbm_arena_alloc(arena, sizeof(*reg));+ if (!reg) return NULL;+ cbm_registry_init(reg, arena);+ cbm_csharp_stdlib_register(reg, arena);+ for (int i = 0; i < def_count; i++) {+ if (defs[i].lang != CBM_LANG_CSHARP) continue;+ cs_register_lsp_defs(arena, reg, &defs[i], 1);+ }+ cbm_registry_finalize(reg);+ return reg;+}++void cbm_run_cs_lsp_cross_with_registry(CBMArena *arena, const char *source, int source_len,+ const char *module_qn, CBMTypeRegistry *reg,+ const char **using_targets, int using_count,+ TSTree *cached_tree, CBMResolvedCallArray *out) {+ if (!source || !arena || !out || !reg) return;++ TSTree *tree = cached_tree;+ bool owns = false;+ if (!tree) {+ TSParser *parser = ts_parser_new();+ if (!parser) return;+ ts_parser_set_language(parser, tree_sitter_c_sharp());+ tree = ts_parser_parse_string(parser, NULL, source,+ source_len > 0 ? (uint32_t)source_len : (uint32_t)strlen(source));+ ts_parser_delete(parser);+ owns = true;+ }+ if (!tree) return;+ TSNode root = ts_tree_root_node(tree);++ CSLSPContext ctx;+ cs_lsp_init(&ctx, arena, source, source_len, reg, module_qn, out);+ for (int i = 0; i < using_count; i++) {+ if (using_targets[i]) {+ cs_lsp_add_using(&ctx, CBM_CS_USING_NAMESPACE, "", using_targets[i], false);+ }+ }+ cs_lsp_process_file(&ctx, root);++ if (owns) ts_tree_delete(tree);+}++void cbm_run_cs_lsp_cross(CBMArena *arena, const char *source, int source_len,+ const char *module_qn, CBMLSPDef *defs, int def_count,+ const char **using_targets, int using_count,+ TSTree *cached_tree, CBMResolvedCallArray *out) {+ if (!source || !arena) return;++ CBMTypeRegistry reg;+ cbm_registry_init(®, arena);+ cbm_csharp_stdlib_register(®, arena);+ cs_register_lsp_defs(arena, ®, defs, def_count);/* Parse if needed. */TSTree *tree = cached_tree;diff --git a/internal/cbm/lsp/cs_lsp.h b/internal/cbm/lsp/cs_lsp.hindex 9b10b075b..2f1995b56 100644--- a/internal/cbm/lsp/cs_lsp.h+++ b/internal/cbm/lsp/cs_lsp.h@@ -148,6 +148,16 @@ void cbm_run_cs_lsp_cross(CBMArena *arena, const char *source, int source_len,const char **using_targets, int using_count,TSTree *cached_tree, CBMResolvedCallArray *out);+/* Tier 2: build a project-wide C# registry ONCE from all defs (filters+ * by lang), shared READ-ONLY across resolve workers. Def-driven. */+CBMTypeRegistry *cbm_cs_build_cross_registry(CBMArena *arena, CBMLSPDef *defs, int def_count);++/* Cross-file resolve using a pre-built shared registry (Tier 2). */+void cbm_run_cs_lsp_cross_with_registry(CBMArena *arena, const char *source, int source_len,+ const char *module_qn, CBMTypeRegistry *reg,+ const char **using_targets, int using_count,+ TSTree *cached_tree, CBMResolvedCallArray *out);+/* Batch cross-file entry for one CGo call from the parallel pipeline. */typedef struct {const char *source;diff --git a/src/pipeline/pass_lsp_cross.h b/src/pipeline/pass_lsp_cross.hindex e2fb5bccb..51f9f3bf2 100644--- a/src/pipeline/pass_lsp_cross.h+++ b/src/pipeline/pass_lsp_cross.h@@ -32,6 +32,7 @@#include "lsp/go_lsp.h"#include "lsp/py_lsp.h" /* cbm_py_build_cross_registry / cbm_run_py_lsp_cross_with_registry */#include "lsp/c_lsp.h" /* cbm_c_build_cross_registry / cbm_run_c_lsp_cross_with_registry */+#include "lsp/cs_lsp.h" /* cbm_cs_build_cross_registry / cbm_run_cs_lsp_cross_with_registry */#include "pipeline/pipeline_internal.h"#include <stdbool.h>diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.cindex 3408ff60f..bb7ea6d96 100644--- a/src/pipeline/pass_parallel.c+++ b/src/pipeline/pass_parallel.c@@ -2062,6 +2062,14 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {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);+ used_prebuilt = true;+ break;/* TS/JS/TSX, PHP fall through to the per-file build* path below until their _with_registry variants land. */default:diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.cindex 7fe027e0c..a0d5e18d0 100644--- a/src/pipeline/pipeline.c+++ b/src/pipeline/pipeline.c@@ -631,6 +631,8 @@ static int run_parallel_pipeline(cbm_pipeline_t *p, cbm_pipeline_ctx_t *ctx,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);}cbm_log_info("pass.timing", "pass", "lsp_cross_prepare", "elapsed_ms",itoa_buf((int)elapsed_ms(*t)));