Skip to content

Use plain usings instead of global:: names in generated code (1.2.2) - #15

Merged
Severnbli merged 1 commit into
mainfrom
fix/remove-global-namespaces
Oct 26, 2026
Merged

Severnbli merged 1 commit into
mainfrom
fix/remove-global-namespaces

Conversation

@Severnbli

Copy link
Copy Markdown
Owner

Summary

Generated files now have ordinary using directives at the top and use short type names everywhere below, instead of global::-qualified names and the __LT alias:

using Severnbli.LocalizationCodegen;
using UnityEngine.Localization;

namespace Localization
{
    public static class Ui
    {
        public const string TableName = "Ui";

        public static string HelloWorld => LocalizedTables.GetString(TableName, "HelloWorld");
    }
}
  • Emitter: each file is emitted in two passes. The first pass records which types the file uses. The second pass writes short names and one using per namespace, with System.* namespaces first.
  • Collision safety: a type stays global::-qualified only when its short name could bind to another type. That happens when:
    • two asset types share a name,
    • a key separator creates a nested class with that name, or
    • the generated namespace (or one of its parents) contains a type with that name. Generation checks this against the loaded assemblies.
  • Class names: table classes no longer take the name of a type the generated code uses (Dictionary, UniTask, Sprite, …). Such a class gets a Table suffix.
  • Settings: removed the Use Runtime Alias setting.
  • Model: EntryModel.AssetTypeName no longer carries global::. The new AssetTypeNamespace field lets nested asset types import the correct namespace.
  • Release: version bumped to 1.2.2, and CHANGELOG and README updated.

Test plan

  • EmitterTests, run outside Unity with small NUnit stand-ins: all 29 pass, including new tests for usings and the collision fallbacks
  • Emitted the GeneratedCodeCompilationTests variants and compiled them against stub Unity, Localization and UniTask types with warnings treated as errors: both builds succeed
  • Run the editor tests in Unity (GeneratedCodeCompilationTests, GenerationIntegrationTests)

🤖 Generated with Claude Code

Generated files now import namespaces with using directives at the top and
refer to types by their short names. A type stays global::-qualified only when
its short name could bind to another type. Removes the Use Runtime Alias
setting, and bumps the version to 1.2.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Severnbli Severnbli added the fix Something needs to be fixed label Oct 26, 2026
@Severnbli Severnbli self-assigned this Oct 26, 2026
@Severnbli
Severnbli merged commit a210b8e into main Oct 26, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Something needs to be fixed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant