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.

feat(extract): detect typed-stub factory constructors

Martin Vogel70839551d3a4
diff --git a/internal/cbm/extract_type_assigns.c b/internal/cbm/extract_type_assigns.c
index c363c7645..74f306507 100644
--- a/internal/cbm/extract_type_assigns.c
+++ b/internal/cbm/extract_type_assigns.c
@@ -56,6 +56,25 @@ static const char *extract_constructor_type(CBMArena *a, TSNode rhs, const char
if (fname && fname[0] >= 'A' && fname[0] <= 'Z') {
return fname;
}
+ /* Lower-cased package prefix: Go-style `pb.NewFooClient(...)` and
+ * Java-style `fooGrpc.newBlockingStub(...)`. Accept the qualified
+ * name when the last segment matches a typed-stub factory pattern.
+ * Downstream passes can use this to infer the constructed type. */
+ if (fname && fname[0]) {
+ const char *last = strrchr(fname, '.');
+ last = last ? last + 1 : fname;
+ bool is_factory = false;
+ if ((strncmp(last, "New", 3) == 0 || strncmp(last, "new", 3) == 0) && last[3]) {
+ size_t llen = strlen(last);
+ if ((llen > 6 && strcmp(last + llen - 6, "Client") == 0) ||
+ (llen > 4 && strcmp(last + llen - 4, "Stub") == 0)) {
+ is_factory = true;
+ }
+ }
+ if (is_factory) {
+ return fname;
+ }
+ }
}
}