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.

fix(extract): extract Java method references as calls (#lsp_method_ref)

Martin Vogelc4608070a9ce
diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.c
index 2aee75d79..0a4a2d93a 100644
--- a/internal/cbm/extract_calls.c
+++ b/internal/cbm/extract_calls.c
@@ -1696,6 +1696,36 @@ static void extract_kotlin_desugared_calls(CBMExtractCtx *ctx, TSNode node, cons
}
}
+// Java method reference `Lhs::name` (e.g. `String::length`, `Foo::new`). The
+// call walk only visits call_expression-like nodes, so a method_reference never
+// becomes a call and the LSP's lsp_method_ref resolution has no call site to
+// attach to. Record a textual call to the referenced method's bare name (the
+// constructor ref `Lhs::new` uses the unnamed `new` token); the LSP join then
+// matches on the bare name. The referenced method IS invoked indirectly, so
+// this is an accurate call edge (mirrors java_lsp.c resolve_method_reference).
+static void extract_java_method_reference(CBMExtractCtx *ctx, TSNode node, const char *kind,
+ const char *enclosing_func_qn) {
+ if (strcmp(kind, "method_reference") != 0) {
+ return;
+ }
+ uint32_t nc = ts_node_named_child_count(node);
+ if (nc < 1) {
+ return;
+ }
+ char *mname = NULL;
+ if (nc >= 2) {
+ mname = cbm_node_text(ctx->arena, ts_node_named_child(node, nc - 1), ctx->source);
+ }
+ if (!mname || !mname[0]) {
+ mname = "new"; // constructor reference `Lhs::new` — `new` is unnamed
+ }
+ CBMCall call = {0};
+ call.callee_name = mname;
+ call.enclosing_func_qn = enclosing_func_qn;
+ call.start_line = (int)ts_node_start_point(node).row + TS_LINE_OFFSET;
+ cbm_calls_push(&ctx->result->calls, ctx->arena, call);
+}
+
void handle_calls(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, WalkState *state) {
if (!spec->call_node_types || !spec->call_node_types[0]) {
return;
@@ -1756,6 +1786,10 @@ void handle_calls(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, Walk
extract_jsx_component_ref(ctx, node, ts_node_type(node), state->enclosing_func_qn);
}
+ if (ctx->language == CBM_LANG_JAVA) {
+ extract_java_method_reference(ctx, node, ts_node_type(node), state->enclosing_func_qn);
+ }
+
if (ctx->language == CBM_LANG_KOTLIN) {
extract_kotlin_operator_call(ctx, node, ts_node_type(node), state->enclosing_func_qn);
extract_kotlin_desugared_calls(ctx, node, ts_node_type(node), state->enclosing_func_qn);