Skip to content

[Feature]: Support safe XAML resource-key rename across theme dictionary variants #328

Open

Description

Is your feature request related to a problem? Please describe.

Deferred follow-up from the review of PR #276.

A resource key can represent a theme family with separate declarations in Default, Light, Dark, or HighContrast dictionaries. Renaming only one declaration while changing shared {ThemeResource ...} references can leave other themes broken.

The pre-merge approach for PR #276 is deliberately conservative: refuse these renames at both prepareRename and direct rename rather than return partial edits. This issue tracks full support beyond that safety guard, not removal of the guard without equivalent protection.

For example, renaming Accent to BrandAccent should update all corresponding theme variants and references bound to that family, while preserving an unrelated page-local resource also named Accent.

Describe the solution you'd like

Provide one complete, scope-aware rename across a logical theme-resource family.

Proposed approach

  • Extend resource ownership resolution to identify corresponding declarations within a theme family, including supported external ResourceDictionary.Source graphs.
  • Reuse the existing resource-scope index and trust-checked dictionary traversal. Respect local shadowing, dictionary ownership, and open unsaved buffers; do not treat all same-named resources in the project as one symbol.
  • Resolve affected {ThemeResource ...} and {StaticResource ...} usages according to their binding scopes.
  • Preflight every affected scope for rename collisions and unresolved or inaccessible ownership, then return one complete WorkspaceEdit. If completeness cannot be proven, retain an explicit refusal with no partial edits.
  • Keep prepareRename and direct rename consistent, and update the documented limitation when support is available.

Acceptance criteria

  • Renaming from a theme declaration or a bound usage updates every declaration in the same family and all affected usages.
  • Cover inline and external theme dictionaries, including nested merged dictionaries and unsaved buffers.
  • Preserve unrelated same-key resources in page-local, nested, and separate dictionary scopes.
  • Handle destination-name collisions and missing, cyclic, ambiguous, or out-of-root dictionary graphs without partial changes or unauthorized reads.
  • Preserve the current refusal behavior for cases that remain unsupported.
  • Add semantic ownership/edit-set tests plus managed and Native AOT stdio regressions for both rename entry points. Verify that every supported theme variant resolves the new key after applying the edit.

Additional context

Relevant implementation areas: server/src/WinUiXaml.LanguageServer/XamlRename.cs (EnsureSafeRename, EnsureNoThemeAlternatives), XamlLanguageServer.DocumentFeatures.cs, XamlSemanticFacts.cs, and XamlResourceGraph.cs.

This is a non-blocking enhancement once the conservative refusal is in place. The current workaround is to update the related theme declarations and usages together manually. Full support for arbitrary ambiguous external-dictionary renames is not implied by this issue; unresolved ownership should continue to fail safely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions