Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(ingestion): mint reference edges for Go functions in composite literals (#2363)
Rishabh Mishrad4b13e2860a6
diff --git a/packages/core/src/repowise/core/ingestion/queries/go.scm b/packages/core/src/repowise/core/ingestion/queries/go.scmindex 2ece58593..115fefa6c 100644--- a/packages/core/src/repowise/core/ingestion/queries/go.scm+++ b/packages/core/src/repowise/core/ingestion/queries/go.scm@@ -104,6 +104,42 @@))+; Function value in composite literal (keyed map/struct or slice/array element):+; template.FuncMap{"greet": greet, "handler": pkg.Handler}, Config{fn: greet}, []func(){greet}+(keyed_element+ value: (literal_element+ (identifier) @reference.name+ )+)++(keyed_element+ value: (literal_element+ (selector_expression+ operand: (_) @reference.receiver+ field: (field_identifier) @reference.name+ )+ )+)++(composite_literal+ body: (literal_value+ (literal_element+ (identifier) @reference.name+ )+ )+)++(composite_literal+ body: (literal_value+ (literal_element+ (selector_expression+ operand: (_) @reference.receiver+ field: (field_identifier) @reference.name+ )+ )+ )+)+; ---------------------------------------------------------------------------; Type references — drive file-level ``type_use`` edges; ---------------------------------------------------------------------------diff --git a/tests/unit/ingestion/test_value_reference_edges.py b/tests/unit/ingestion/test_value_reference_edges.pyindex ad2ca799c..a8a428614 100644--- a/tests/unit/ingestion/test_value_reference_edges.py+++ b/tests/unit/ingestion/test_value_reference_edges.py@@ -119,6 +119,80 @@ class TestGoFunctionValues:assert _inbound(graph, "handlers/handlers.go::Index", "references")assert not _inbound(graph, "handlers/handlers.go::Index", "calls")+ def test_func_value_in_keyed_map_composite_literal(self, tmp_path: Path) -> None:+ (tmp_path / "go.mod").write_text("module example.com/app\n\ngo 1.21\n")+ (tmp_path / "handlers").mkdir()+ (tmp_path / "handlers" / "handlers.go").write_text(+ "package handlers\n\nfunc Index() {}\n"+ )+ (tmp_path / "server.go").write_text(+ "package app\n"+ "\n"+ 'import "example.com/app/handlers"\n'+ "\n"+ "func Greet() {}\n"+ "\n"+ "func Setup() {\n"+ '\t_ = map[string]any{"greet": Greet, "handler": handlers.Index}\n'+ "}\n"+ )+ graph = _build(tmp_path)+ assert _inbound(graph, "server.go::Greet", "references")+ assert not _inbound(graph, "server.go::Greet", "calls")+ assert _inbound(graph, "handlers/handlers.go::Index", "references")+ assert not _inbound(graph, "handlers/handlers.go::Index", "calls")++ def test_func_value_in_struct_composite_literal(self, tmp_path: Path) -> None:+ (tmp_path / "go.mod").write_text("module example.com/app\n\ngo 1.21\n")+ (tmp_path / "handlers").mkdir()+ (tmp_path / "handlers" / "handlers.go").write_text(+ "package handlers\n\nfunc Index() {}\n"+ )+ (tmp_path / "server.go").write_text(+ "package app\n"+ "\n"+ 'import "example.com/app/handlers"\n'+ "\n"+ "type Config struct {\n"+ " OnEvent func()\n"+ " Handler func()\n"+ "}\n"+ "\n"+ "func Greet() {}\n"+ "\n"+ "func Setup() {\n"+ "\t_ = Config{OnEvent: Greet, Handler: handlers.Index}\n"+ "}\n"+ )+ graph = _build(tmp_path)+ assert _inbound(graph, "server.go::Greet", "references")+ assert not _inbound(graph, "server.go::Greet", "calls")+ assert _inbound(graph, "handlers/handlers.go::Index", "references")+ assert not _inbound(graph, "handlers/handlers.go::Index", "calls")++ def test_func_value_in_slice_composite_literal(self, tmp_path: Path) -> None:+ (tmp_path / "go.mod").write_text("module example.com/app\n\ngo 1.21\n")+ (tmp_path / "handlers").mkdir()+ (tmp_path / "handlers" / "handlers.go").write_text(+ "package handlers\n\nfunc Index() {}\n"+ )+ (tmp_path / "server.go").write_text(+ "package app\n"+ "\n"+ 'import "example.com/app/handlers"\n'+ "\n"+ "func Greet() {}\n"+ "\n"+ "func Setup() {\n"+ "\t_ = []func(){Greet, handlers.Index}\n"+ "}\n"+ )+ graph = _build(tmp_path)+ assert _inbound(graph, "server.go::Greet", "references")+ assert not _inbound(graph, "server.go::Greet", "calls")+ assert _inbound(graph, "handlers/handlers.go::Index", "references")+ assert not _inbound(graph, "handlers/handlers.go::Index", "calls")+def test_an_ordinary_qualified_call_is_still_a_call(self, tmp_path: Path) -> None:self._layout(tmp_path, "\thandlers.Index()\n")graph = _build(tmp_path)