Skip to content

Include namespace in generated source filename to prevent duplicate hint-name collisions#44

Merged
GeertvanHorrik merged 2 commits into
developfrom
copilot/include-namespace-in-file-name
May 28, 2026
Merged

Include namespace in generated source filename to prevent duplicate hint-name collisions#44
GeertvanHorrik merged 2 commits into
developfrom
copilot/include-namespace-in-file-name

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 28, 2026

When two classes share the same name across different namespaces (e.g. MyNamespace1.WelcomeWizardPage and MyNamespace2.WelcomeWizardPage), all source generators produced the same hint name, causing a Roslyn exception on AddSource.

Changes

New shared utility: SourceFileNameHelper

  • GetGeneratedFileName(namespaceName, className) replaces the per-generator ad-hoc filename logic across all five generators
  • Returns {Namespace_With_Dots_As_Underscores}_{ClassName} when combined length ≤ 100 chars
  • Falls back to {8-char-FNV-1a-hash-of-namespace}_{ClassName} for very long namespaces — hash is deterministic, preserving incremental build caching
// MyNamespace1.WelcomeWizardPage → MyNamespace1_WelcomeWizardPage_ViewModelConstructors.g.cs
// MyNamespace2.WelcomeWizardPage → MyNamespace2_WelcomeWizardPage_ViewModelConstructors.g.cs

Generators updated

All five generators (ViewModelConstructors, ViewConstructors, BehaviorConstructors, MarkupExtensionConstructors, ValueConverterConstructors) now delegate filename construction to SourceFileNameHelper.

Also corrects a pre-existing bug in ValueConverterConstructorsSourceGenerator where it was emitting _BehaviorConstructors.g.cs as the file suffix instead of _ValueConverterConstructors.g.cs.

Tests

  • SourceFileNameHelperTests — 7 unit tests covering dot replacement, short/long name thresholds, determinism, and uniqueness across namespaces
  • ViewModelCtorGeneratorTests.duplicate_class_names — integration test reproducing the exact issue: two WelcomeWizardPage ViewModels in different namespaces produce distinct, non-clashing hint names
  • All 15 existing Verify snapshot files updated to reflect the new namespace-prefixed hint names

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

- Add SourceFileNameHelper.GetGeneratedFileName(namespace, class) in Generation/ using namespace_class pattern with FNV-1a hash fallback for long names
- Update all 5 source generators to use SourceFileNameHelper instead of ad-hoc FileName/ClassName logic
- Fix pre-existing bug: ValueConverterConstructorsSourceGenerator used _BehaviorConstructors.g.cs suffix instead of _ValueConverterConstructors.g.cs
- Update all 14 verified Verify snapshots to use namespace-prefixed hint names
- Add SourceFileNameHelperTests (7 unit tests) and duplicate_class_names integration test
Copilot AI changed the title [WIP] Add namespace to generated source filename Include namespace in generated source filename to prevent duplicate hint-name collisions May 28, 2026
Copilot AI requested a review from GeertvanHorrik May 28, 2026 18:56
@GeertvanHorrik GeertvanHorrik marked this pull request as ready for review May 28, 2026 21:11
@GeertvanHorrik GeertvanHorrik merged commit fc11d09 into develop May 28, 2026
1 check was pending
@GeertvanHorrik GeertvanHorrik deleted the copilot/include-namespace-in-file-name branch May 28, 2026 21:11
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.

Include namespace as part of the generated source filename

3 participants