Skip to content

Register each generator once when AddCoder is called twice [patch] - #198

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/150-idempotent-registration
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/150-idempotent-registration

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #150

What changed

  • AddLanguageGenerators now registers each generator with TryAddEnumerable(ServiceDescriptor.Singleton<ILanguageGenerator, …>()). Calling AddCoder() twice, say once from a library and once from the host, used to resolve 14 generators. That made the documented .Single(g => g.LanguageId == …) selection throw and showed every language twice in the editor.
  • AddCoderSerialization uses TryAddSingleton for the serializer and deserializer.
  • AddCoder_ShouldBeIdempotent used to assert only Count > 0. It now asserts exactly 7 generators, that Single by LanguageId succeeds for each of them, and exactly one serializer and one deserializer.

Verification

  • With the fix reverted, the tightened test fails (Assert.HasCount(7, generators)). With the fix in place, it passes.
  • Full Coder.Test suite: 1100 passed, 0 failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ACXyQBPWSqFJuF51Mx6FNh


Generated by Claude Code

AddLanguageGenerators appended a descriptor per call, so calling AddCoder
from both a library and its host resolved fourteen generators and the
documented .Single(g => g.LanguageId == ...) lookup threw. Register the
generators with TryAddEnumerable and the serializers with TryAddSingleton,
and make the idempotency test assert one registration of each.

Fixes #150

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ACXyQBPWSqFJuF51Mx6FNh
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 778b91d into main Oct 9, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/150-idempotent-registration branch October 9, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant