Skip to content

feat: C# first-class language support#15

Open
kehoej wants to merge 3 commits intomainfrom
feat/csharp-first-class
Open

feat: C# first-class language support#15
kehoej wants to merge 3 commits intomainfrom
feat/csharp-first-class

Conversation

@kehoej
Copy link
Copy Markdown
Owner

@kehoej kehoej commented Apr 16, 2026

Summary

Adds C# as the 6th fully supported language in Contextception, with complete extractor, resolver, analyzer integration, and benchmark validation.

What's included

Extractor (internal/extractor/csharp/)

  • Regex-based extraction of using, using static, using alias, global using, and file-scoped namespace declarations
  • Block/line comment handling, stops parsing at type declarations
  • ExtractDefinitions for class, interface, struct, enum, record, method, property, const, and delegate signatures

Resolver (internal/resolver/csharp/)

  • Auto-detects source roots from .csproj/.shproj files
  • 4-strategy resolution: project namespace mapping → namespace-to-file → namespace suffix subdirectory → filename search fallback
  • Same-namespace sibling resolution via ResolveAll (C#'s implicit type visibility within namespaces)
  • Smart stdlib detection with override for repos containing Microsoft.*/System.* projects (Roslyn, EF Core)
  • Representative file selection using stem matching, interface preference, and hash-based rotation to avoid artificial hub nodes

Analyzer integration

  • IsCSharpSameNamespace flag threaded through graph construction, categorization, and signal generation
  • Same-namespace sibling discovery with class prefix matching and small-namespace gating (mirrors Go/Java/Rust patterns)
  • C# test project mirror detection: EFCore.DesignEFCore.Design.Tests, Roslyn-style CSharpCSharpTest, Jellyfin-style renamed projects
  • csharpPrefixStemMatch for test-to-subject matching when tests use shorter CamelCase names (e.g., AutomaticLineEnderAutomaticLineEnderCommandHandler)
  • C# confidence escalation in likelyModifyConfidence for class prefix match and co-change evidence
  • IsTestFile and hasTestDirComponent extended for C# patterns (.Tests, .Test, *Spec.cs, TestFoo.cs)

Bug fixes found during review

  • Fixed GetCSharpSiblingsInDir passing "csharp" instead of "cs" as the file extension parameter, which would have made same-namespace sibling discovery return zero results
  • Fixed resolveSameNamespace using inline test detection instead of classify.IsTestFile(), missing *Spec.cs files
  • Added missing C# confidence escalation paths in likelyModifyConfidence (Go, Java, and Rust had these but C# was omitted)

Benchmarks

  • Tested against EF Core (5,708 files) and Jellyfin (1,971 files)
  • Head-to-head comparison expanded from 6 → 7 repos, 51 → 68 files, 4 → 5 languages
  • C# scoring script (scripts/score_csharp.py) with ground truth validation

Documentation

  • README, CLAUDE.md, CHANGELOG, ARCHITECTURE, features.md, mcp-tutorial.md, integrations, and issue templates updated from "5 languages" → "6 languages"

Test coverage

  • 496 extractor test cases (all using variants, block comments, definitions)
  • 335 resolver test cases (project namespace resolution, same-namespace siblings, stdlib override)
  • 44 new analyzer test cases: csharpPrefixStemMatch, isCSharpTestProjectMirror, hasTestDirComponent C# patterns, extractTestStem C# patterns, csharpProjectInfo, IsTestFile C# patterns
  • 10 new classify.IsTestFile C# cases
  • Full suite: 1,303 tests passing, make check clean (vet + lint + test)

kehoej added 3 commits April 15, 2026 19:17
…ve test file handling

- Added logic to assess coupling in C# files based on namespace and class prefix.
- Updated the method for retrieving C# sibling files to use the correct file extension.
- Improved test file identification by utilizing a dedicated classification function.
…alidation

- Introduced new tests for identifying C# test files based on naming conventions.
- Added functions to validate C# project structures and test directory components.
- Enhanced existing test cases to cover various C# scenarios, improving overall test coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant