Skip to content

Commit 1cf6573

Browse files
authored
Merge branch 'main' into fix/opencode-augment-timeout
2 parents 6513104 + 4c80d89 commit 1cf6573

23 files changed

Lines changed: 1488 additions & 136 deletions

‎internal/cbm/doclink_go.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
* drops these lines and so carries no line number
4444
* at all.
4545
* G path go.mod: the module path
46-
* w says who keeps the node. A Go method node has a FLAT qualified name
47-
* (<dir>.<Method>), so a function, the methods of every receiver, a type and
48-
* a value of one name all claim the node <dir>.<name>, and within a file the
49-
* declaration on the LAST line keeps it (cbm_gbuf_upsert_node). w is 1 for
46+
* w says who keeps the node <dir>.<name>. A function, a type and a value of
47+
* one name all claim it, and within a file the declaration on the LAST line
48+
* keeps it (cbm_gbuf_upsert_node). A method claims nothing: its node is
49+
* receiver-qualified (<dir>.<Recv>.<Method>, #1913), and its w is `-`. w is 1 for
5050
* that declaration, 0 for the others of that name, x when two of them start
5151
* on that last line, and - for a value the extractor gives no node at all
5252
* (it gives one to the first name of a constant spec and of a parenthesis-
@@ -1511,9 +1511,11 @@ static void go_scan_method(go_scan_t *s, TSNode m) {
15111511
recv = "?";
15121512
recv_len = SKIP_ONE;
15131513
}
1514-
go_push_claim(s,
1515-
cbm_arena_sprintf(s->tmp, "M\t%.*s\t%.*s", (int)recv_len, recv, (int)len, name),
1516-
name, len, m);
1514+
/* #1913: a Go method node is receiver-qualified (<dir>.<Recv>.<Method>),
1515+
* so a method claims no flat name: w is `-`, and the method is found
1516+
* through its receiver (the member table), never through <dir>.<name>. */
1517+
(void)go_push_rec(
1518+
s, cbm_arena_sprintf(s->tmp, "M\t%.*s\t%.*s\t-", (int)recv_len, recv, (int)len, name));
15171519
}
15181520

15191521
/* The implied name of an embedded field: the type's own name, without

‎internal/cbm/extract_calls.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4493,6 +4493,24 @@ CBMInvocationDescriptor handle_calls(CBMExtractCtx *ctx, TSNode node, const CBML
44934493
}
44944494
}
44954495
}
4496+
// Go receiver-aware guard (same direction as the TS/JS flag above).
4497+
// Flag a selector call x.foo(). The Go AST cannot separate a method
4498+
// call on a value from a package-qualified call — but every selector
4499+
// call the Go LSP or the import/qualified registry strategies CAN
4500+
// place never reaches the weak short-name guards, so the flag only
4501+
// bites on unresolvable receivers (`f.Close()` on an os.File,
4502+
// `sha256.New()` behind an unindexed import), where a project-wide
4503+
// short-name match fabricates an edge to an unrelated project
4504+
// symbol sharing the name. Bare calls (helper()) keep
4505+
// is_method=false and resolve same-module/import paths as before.
4506+
if (ctx->language == CBM_LANG_GO &&
4507+
strcmp(ts_node_type(node), "call_expression") == 0) {
4508+
TSNode gofn = ts_node_child_by_field_name(node, TS_FIELD("function"));
4509+
if (!ts_node_is_null(gofn) &&
4510+
strcmp(ts_node_type(gofn), "selector_expression") == 0) {
4511+
call.is_method = true;
4512+
}
4513+
}
44964514

44974515
TSNode args = ts_node_child_by_field_name(node, TS_FIELD("arguments"));
44984516
/* tree-sitter-elixir attaches NO field name to a call's arguments

‎internal/cbm/extract_defs.c‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5772,7 +5772,7 @@ static void set_def_complexity(CBMDefinition *def, TSNode body, const CBMLangSpe
57725772
* Walks to the parameter_declaration's `type` field, unwrapping pointer_type
57735773
* and generic_type, and returns the type_identifier text (e.g. "OrderService").
57745774
* Returns NULL if no type_identifier is found. */
5775-
static char *go_receiver_type_name(CBMArena *a, TSNode recv, const char *source) {
5775+
char *cbm_go_receiver_type_name(CBMArena *a, TSNode recv, const char *source) {
57765776
uint32_t nc = ts_node_child_count(recv);
57775777
for (uint32_t i = 0; i < nc; i++) {
57785778
TSNode child = ts_node_child(recv, i);
@@ -7006,12 +7006,27 @@ static void extract_func_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec
70067006
* (and downstream Go IMPLEMENTS/OVERRIDE) link the method to its owning
70077007
* struct/type node. The parent QN must match the type's node QN, which
70087008
* is computed the same way (cbm_fqn_compute on the type name). */
7009-
char *recv_type = go_receiver_type_name(a, recv, ctx->source);
7009+
char *recv_type = cbm_go_receiver_type_name(a, recv, ctx->source);
70107010
if (recv_type && recv_type[0]) {
70117011
/* Must match the Go type node QN (directory-based module) so the
70127012
* DEFINES_METHOD edge links the method to its owning type. */
70137013
def.parent_class = cbm_fqn_compute_source_lang(a, ctx->project, ctx->rel_path,
70147014
recv_type, ctx->language);
7015+
/* Receiver-qualify the method QN (proj.pkg.Recv.method) — same
7016+
* shape as the C++ out-of-line path below and Go interface
7017+
* members. With the flat proj.pkg.method QN every same-name
7018+
* method in a package collided in the graph upsert: one body
7019+
* survived and the twins' call edges accreted onto it. The
7020+
* call-scope side (compute_func_qn in extract_unified.c) mirrors
7021+
* this formula, and go_lsp consumers read the def QN and
7022+
* parent_class (receiver_type) verbatim, so resolution joins
7023+
* stay exact. Go only: templ's Go-derived grammar reaches this
7024+
* branch too, but its call-scope QN (compute_func_qn) stays flat,
7025+
* and a def QN the calls do not share would orphan every call
7026+
* inside a templ method. */
7027+
if (ctx->language == CBM_LANG_GO && def.parent_class) {
7028+
def.qualified_name = cbm_arena_sprintf(a, "%s.%s", def.parent_class, name);
7029+
}
70157030
}
70167031
}
70177032

0 commit comments

Comments
 (0)