razor icon indicating copy to clipboard operation
razor copied to clipboard

Allow developers to properly rename razor components in the editor

Open maryamariyan opened this issue 2 years ago • 2 comments

Description

Several different rename scenarios for razor components do not work reliably today in a solution that contains a razor component.

We are currently faced with some limitations on how we handle renames for razor components. The goal for this issue is to allow developers to properly rename razor components in the editor.


Examples

Use case 1: Simply rename component in a razor file


Arrange

  1. Create or open a Blazor Server App.
  2. Add a razor component into another razor document by drag/dropping one of the razor files (e.g. Counter.razor into Index.razor file). That should add a line <Counter\> to Index.razor file.

Act (rename)

  1. Rename the component by right-clicking over <Counter/> on the Index.razor file.

image image

Assert

:white_check_mark: This will successfully rename the Counter.razor filename accordingly.


Use case 2: Rename in a razor file, while there's references to it in other files (both in/out @{ } block)

image

Problems found:

  • :x: Renaming on a razor file only renames the component references outside the @{ } block. image

  • :x: The same rename action only renames the component references in the same file. It won't properly rename any component or C# references in the other razor files (regardless of them being opened or unopened files): image


Use case 3: Rename the razor file from solution explorer back to Counter.razor

Problem found:

  • :x: Does not update any razor component references, regardless if in or outside @{ } block. image

Use case 4: Rename one of the razor component references from inside a C# context

image

Problem found:

image

  • :white_check_mark: All of the C# references get updated even in other files
  • :x: But no component references outside of the @{ } get updated
  • :x: Also, the razor file name itself does not get updated which means this action does not trigger component rename (which explains the squiggly under all the renamed items).

Use case 5: Rename a component that is defined as a partial class

Problems found:

  • :x: Renaming via solution explorer (similar to use case 3), only renames the file itself, nothing else gets triggered
  • :x: Renaming a component from outside @{ } context (similar to use case 2), changes nothing.
  • :x: Renaming a component from inside @{ } context, won't update any file names, and it won't update any component references outside the @{ } code block. The only thing it does it rename all C# references and the user-specified partial class definition will get updated, but nothing razor specific gets triggered.

Use case 6: Renaming a component from inside its own razor file just simply renames the files

(Reported in https://github.com/dotnet/razor/issues/4458 - I was only able to reproduce this with razor files under the shared folder not under the pages folder)

  • [x] (Fixed in #8954)

image

Problems found:

  • :x: The files get renamed but the component reference in the file does not get renamed: image image

  • :x: If on line 5 we don't manually apply the rename before undoing name back to original name the error list below does not get cleared (not even with rebuild), unless we close and reopen VS entirely image

maryamariyan avatar Mar 30 '23 00:03 maryamariyan