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
fix(lsp): nested-class enclosing QN + constructor resolution to the class node
Martin Vogelb9b4669a20cb
diff --git a/internal/cbm/helpers.c b/internal/cbm/helpers.cindex b8c41aa24..724a71eb2 100644--- a/internal/cbm/helpers.c+++ b/internal/cbm/helpers.c@@ -834,22 +834,39 @@ const char *cbm_enclosing_func_qn(CBMArena *a, TSNode node, CBMLanguage lang, coreturn module_qn;}- // Check if the function is inside a class — compute classQN.funcName+ // Check if the function is inside a class — compute classQN.funcName.+ // For nested classes the class QN must carry the FULL nesting chain+ // (Outer.Inner, not just Inner) so it matches the class/method node QN the+ // def walk produces via compute_class_qn (extract_defs.c). Qualifying with+ // only the innermost class under-qualified the enclosing QN, so a call+ // inside a nested-class method sourced to the file node instead of its+ // method node and failed to join the LSP-resolved call by caller QN.const CBMLangSpec *spec = cbm_lang_spec(lang);if (spec && spec->class_node_types) {- TSNode cur = ts_node_parent(func_node);- while (!ts_node_is_null(cur)) {- if (cbm_kind_in_set(cur, spec->class_node_types)) {- TSNode class_name = ts_node_child_by_field_name(cur, TS_FIELD("name"));- if (!ts_node_is_null(class_name)) {- char *cname = cbm_node_text(a, class_name, source);- if (cname && cname[0]) {- const char *class_qn = cbm_fqn_compute(a, project, rel_path, cname);- return cbm_arena_sprintf(a, "%s.%s", class_qn, name);- }- }+ // Build the dotted class chain from the outermost enclosing class down+ // to the innermost. Walk parents collecting class names innermost-first,+ // then prepend each as we ascend so the result reads Outer.Inner.+ const char *class_chain = NULL;+ for (TSNode cur = ts_node_parent(func_node); !ts_node_is_null(cur);+ cur = ts_node_parent(cur)) {+ if (!cbm_kind_in_set(cur, spec->class_node_types)) {+ continue;+ }+ TSNode class_name = ts_node_child_by_field_name(cur, TS_FIELD("name"));+ if (ts_node_is_null(class_name)) {+ continue;}- cur = ts_node_parent(cur);+ char *cname = cbm_node_text(a, class_name, source);+ if (!cname || !cname[0]) {+ continue;+ }+ class_chain = class_chain+ ? cbm_arena_sprintf(a, "%s.%s", cname, class_chain)+ : cname;+ }+ if (class_chain) {+ const char *class_qn = cbm_fqn_compute(a, project, rel_path, class_chain);+ return cbm_arena_sprintf(a, "%s.%s", class_qn, name);}}diff --git a/internal/cbm/lsp/cs_lsp.c b/internal/cbm/lsp/cs_lsp.cindex 0a4bcc9ba..78d0bddbd 100644--- a/internal/cbm/lsp/cs_lsp.c+++ b/internal/cbm/lsp/cs_lsp.c@@ -1585,8 +1585,8 @@ static void cs_resolve_invocation(CSLSPContext *ctx, TSNode call) {}static void cs_resolve_object_creation(CSLSPContext *ctx, TSNode call) {- /* `new Foo(...)` adds an implicit Foo..ctor edge. We synth a constructor- * call to give the pipeline a high-confidence target when Foo is known. */+ /* `new Foo(...)` adds an implicit constructor CALLS edge: to Foo's ctor+ * Method node when one is indexed, otherwise to the Foo class node. */TSNode tnode = ts_node_child_by_field_name(call, "type", 4);if (ts_node_is_null(tnode)) return;const CBMType *t = cs_parse_type_node(ctx, tnode);@@ -1594,14 +1594,24 @@ static void cs_resolve_object_creation(CSLSPContext *ctx, TSNode call) {if (t && t->kind == CBM_TYPE_NAMED) tqn = t->data.named.qualified_name;else if (t && t->kind == CBM_TYPE_TEMPLATE) tqn = t->data.template_type.template_name;if (!tqn) return;- const CBMRegisteredFunc *f = cs_lookup_method(ctx, tqn, ".ctor");+ /* A C# constructor is extracted as a Method whose short name is the class's+ * short name (the constructor_declaration `name` field is the class+ * identifier), so the ctor QN is `<type_qn>.<ShortName>` — never ".ctor".+ * Look it up by the class short name, mirroring the Java resolver. */+ const char *dot = strrchr(tqn, '.');+ const char *short_name = dot ? dot + 1 : tqn;+ const CBMRegisteredFunc *f = cs_lookup_method(ctx, tqn, short_name);if (f) {cs_emit_resolved(ctx, f->qualified_name, "cs_ctor", 0.95f);return;}- /* Synthesize: Foo..ctor. */- cs_emit_resolved(ctx, cbm_arena_sprintf(ctx->arena, "%s..ctor", tqn),- "cs_ctor_synthetic", 0.50f);+ /* No explicit constructor in the registry. Resolve the `new Foo()` call to+ * the Foo CLASS node (`tqn`): its short name equals the call's textual+ * callee_name ("Foo"), so the pipeline join matches, and the class node+ * always exists, so a CALLS edge forms carrying the strategy — rather than+ * the old `Foo..ctor`, whose ".ctor" short name joined nothing and resolved+ * to no node. */+ cs_emit_resolved(ctx, tqn, "cs_ctor_synthetic", 0.85f);}static void cs_resolve_calls_in_node(CSLSPContext *ctx, TSNode node) {diff --git a/internal/cbm/lsp/java_lsp.c b/internal/cbm/lsp/java_lsp.cindex ef3539741..342297aac 100644--- a/internal/cbm/lsp/java_lsp.c+++ b/internal/cbm/lsp/java_lsp.c@@ -2786,10 +2786,13 @@ static void java_resolve_calls_in_node_inner(JavaLSPContext *ctx, TSNode node) {if (cf) {java_emit_resolved(ctx, cf->qualified_name, "lsp_constructor", 0.95f);} else {- /* Synth a constructor QN — Class.Class — so downstream- * still gets a resolvable edge. */- java_emit_resolved(ctx, cbm_arena_sprintf(ctx->arena, "%s.%s", qn, short_name),- "lsp_constructor_synth", 0.85f);+ /* No explicit constructor in the registry, so there is no+ * `Class.Class` ctor node to point at. Resolve the `new Foo()`+ * call to the Foo CLASS node (`qn`) instead: its short name+ * equals the textual callee_name ("Foo"), so the pipeline+ * join matches, and the class node always exists, so a CALLS+ * edge forms carrying the strategy. */+ java_emit_resolved(ctx, qn, "lsp_constructor_synth", 0.85f);}}}