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(health): exclude C# type arguments from callee names (#3475)
ningkexin963ea5417d3412
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py b/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.pyindex dba482f7b..887db360b 100644--- a/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py+++ b/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py@@ -468,14 +468,14 @@ def _identifier_chain(node: Node, *, lower: bool = True) -> list[str]:document order.Order is load-bearing: the last entry is the name being called, the rest- the receiver path. Argument lists and ``type_arguments`` (TypeScript,- Java) are never descended into; C#'s ``type_argument_list`` still is.+ the receiver path. Value and type argument lists (including C#'s+ ``type_argument_list``) are never descended into."""names: list[str] = []stack: list[Node] = [node]while stack:cur = stack.pop()- if cur.type in ("argument_list", "arguments", "type_arguments"):+ if cur.type in ("argument_list", "arguments", "type_arguments", "type_argument_list"):continueif cur.type.endswith(_IDENTIFIER_SUFFIX) and cur.text is not None:text = cur.text.decode("utf-8", "replace")diff --git a/tests/unit/health/test_ast_callee_names.py b/tests/unit/health/test_ast_callee_names.pyindex 108c6f33e..38877e840 100644--- a/tests/unit/health/test_ast_callee_names.py+++ b/tests/unit/health/test_ast_callee_names.py@@ -46,12 +46,10 @@ def test_a_java_explicit_type_argument_never_joins_the_receivers() -> None:assert calls["Mockito.<Foo>mock(Foo.class)"] == ("mock", {"mockito"})-def test_csharp_generic_calls_are_unchanged() -> None:- """C#'s grammar names the list ``type_argument_list``, which is not- skipped, so the type argument still reads as the called name. Recorded as- the current behaviour, not endorsed."""+def test_csharp_generic_reads_its_callee_not_its_type_argument() -> None:+ """C#'s ``type_argument_list`` contains types, not callee names."""calls = _calls("csharp", "class T { void M() { var s = Substitute.For<IFoo>(); Arg.Any<MockFoo>(); } }")- assert calls["Substitute.For<IFoo>()"] == ("ifoo", {"substitute", "for"})- assert calls["Arg.Any<MockFoo>()"] == ("mockfoo", {"arg", "any"})+ assert calls["Substitute.For<IFoo>()"] == ("for", {"substitute"})+ assert calls["Arg.Any<MockFoo>()"] == ("any", {"arg"})diff --git a/tests/unit/health/test_generic_callee_names.py b/tests/unit/health/test_generic_callee_names.pynew file mode 100644index 000000000..509206744--- /dev/null+++ b/tests/unit/health/test_generic_callee_names.py@@ -0,0 +1,98 @@+"""Generic type arguments do not name a call or its receiver."""++from __future__ import annotations++import pytest+from tree_sitter import Parser++from repowise.core.analysis.health.complexity import walk_file+from repowise.core.analysis.health.complexity.ast_utils import _callee_names+from repowise.core.ingestion.parser import _get_language+++def _read_callee(source: bytes, language: str, call_type: str):+ grammar = _get_language(language)+ if grammar is None:+ pytest.skip(f"tree-sitter grammar missing for {language}")+ tree = Parser(grammar).parse(source)+ assert not tree.root_node.has_error+ stack = [tree.root_node]+ calls = []+ while stack:+ node = stack.pop()+ if node.type == call_type:+ calls.append(node)+ stack.extend(node.named_children)+ assert len(calls) == 1+ return _callee_names(calls[0])+++ ("expression", "expected"),+ [+ ("Substitute.For<IFoo>()", ("for", {"substitute"})),+ ("Mock.Of<IBar>()", ("of", {"mock"})),+ ("Assert.Equal<IFoo>(a, b)", ("equal", {"assert"})),+ (+ "Assert.Equal<System.Collections.Generic.List<IFoo>>(a, b)",+ ("equal", {"assert"}),+ ),+ ("Factory<IFoo>.Create<IBar>()", ("create", {"factory"})),+ ("Equal<IFoo>(a, b)", ("equal", set())),+ ("Helper.Make<Assert>(a)", ("make", {"helper"})),+ ("Assert.Equal(a, b)", ("equal", {"assert"})),+ ],+)+def test_csharp_callee_names(expression: str, expected: tuple[str, set[str]]) -> None:+ source = f"class Tests {{ void Test() {{ {expression}; }} }}".encode()+ assert _read_callee(source, "csharp", "invocation_expression") == expected+++ ("language", "source", "call_type", "expected"),+ [+ (+ "typescript",+ b"function test() { mock.fn<IFoo>(); }",+ "call_expression",+ ("fn", {"mock"}),+ ),+ (+ "java",+ b"class Tests { void test() { Collections.<IFoo>emptyList(); } }",+ "method_invocation",+ ("emptylist", {"collections"}),+ ),+ (+ "rust",+ b"fn test() { factory.create::<IBar>(); }",+ "call_expression",+ ("create", {"factory"}),+ ),+ ],+)+def test_other_generic_callees_unchanged(+ language: str, source: bytes, call_type: str, expected: tuple[str, set[str]]+) -> None:+ assert _read_callee(source, language, call_type) == expected+++ ("expression", "called", "assertions"),+ [+ ("Assert.Equal<IFoo>(a, b)", "equal", 1),+ ("Assert.Equal<System.Collections.Generic.List<IFoo>>(a, b)", "equal", 1),+ ("Substitute.For<IFoo>()", "for", 0),+ ("Mock.Of<IBar>()", "of", 0),+ ("Helper.Make<IFoo>(a)", "make", 0),+ ],+)+def test_csharp_generic_calls_in_walker(expression: str, called: str, assertions: int) -> None:+ if _get_language("csharp") is None:+ pytest.skip("tree-sitter C# grammar missing")+ source = f"class Tests {{ void Test() {{ {expression}; }} }}".encode()+ result = walk_file("tests/Tests.cs", "csharp", source)+ assert len(result.functions) == 1+ function = result.functions[0]+ assert function.called_names == frozenset({called})+ assert function.assertion_count == assertions