microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
226 stars 11 forks source link

[BUG] Refactoring components in Blazor not working #814

Closed MarkusRodler closed 1 month ago

MarkusRodler commented 9 months ago

Describe the Issue

If you rename components everything is broken like in #799

Steps To Reproduce

  1. dotnet new blazorwasm -ho -o BlazorTest
  2. Create a new component Counter2.razor with:
    
    <p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me

@code { private int currentCount = 0; private void IncrementCount() => currentCount++; }


3. Use that component in Index.razor via `<Counter2 />` => Everything is working. You can go to that component via click
4. Press CTRL+R to rename that component to Counter3 => Renaming works as expected. Filename from that component is renamed too but now it is not clickable anymore (blue instead of green). Renaming also doesn't work anymore. If you start writing a new Component with `<Counter` it says you can use `<Counter />` and the old `<Counter2 />` but not the actually existing `<Counter3 />`!
5. Adding a Counter4 component is also broken as above.

Before renaming:
![image](https://github.com/microsoft/vscode-dotnettools/assets/14873906/021431cd-7126-489a-bce0-94a5ac7253b9)

After renaming:
![image](https://github.com/microsoft/vscode-dotnettools/assets/14873906/0c9062df-47cd-44d2-94c6-9d6e9df7f2f9)

(In my tests i tried it with a different folder "Component" and a @using inside of _Imports.razor. That's the only difference from my instructions)

### Expected Behavior

I expect it to be working...

### Environment Information

WSL2 Debian
.NET 8.0
Everything latest versions used
MarkusRodler commented 9 months ago

@timheuer could be similar to #799 but with Blazor instead of .NET Web API

timheuer commented 9 months ago

Good detail, thanks @MarkusRodler -- Might be the underlying language service here and not Dev Kit. /cc @phil-allen-msft @arkalyanms to see if it should move there.

timheuer commented 9 months ago

@MarkusRodler can you see below and tell me if in your environment as well performing either of the actions returns you to normal:

https://github.com/microsoft/vscode-dotnettools/assets/4821/849e4622-07de-4a2e-bd8a-cb9f7028b313

MarkusRodler commented 9 months ago

Animation @timheuer I tried it again and it works for .NET 7 but not for .NET 8

MarkusRodler commented 9 months ago

BlazorTest.Client.csproj:

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Shared\BlazorTest.Shared.csproj" />
  </ItemGroup>

</Project>

BlazorTest.Server.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Client\BlazorTest.Client.csproj" />
    <ProjectReference Include="..\Shared\BlazorTest.Shared.csproj" />
  </ItemGroup>

</Project>

BlazorTest.Shared.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <SupportedPlatform Include="browser" />
  </ItemGroup>
</Project>
timheuer commented 9 months ago

Thanks for the pic, I'm using net8 as well -- could be a WSL specific issue at this point.

arkalyanms commented 9 months ago

Agreed, a razor first scout might be appropriate here. cc: @phil-allen-msft

github-actions[bot] commented 6 months ago

This issue has been marked as stale after 14 days of inactivity. @[ @ryzngard @], could you please take a look?

ryzngard commented 6 months ago

Still an issue afaik. WSL does seem to be a key problem here. We've also shipped some stability for our runtime targeting for dotnet 8 so that may have changed. Will have to verify if this still repros. @MarkusRodler thanks for the very detailed feedback :)

When talking about using WSL, I want to make sure I get my steps correct since I'm less familiar with the interactions there vs full linux (which I usually test in). I'm assuming this is the WSL extension which would be similar to a locally hosted code space environment?

MarkusRodler commented 6 months ago

Still an issue afaik. WSL does seem to be a key problem here. We've also shipped some stability for our runtime targeting for dotnet 8 so that may have changed. Will have to verify if this still repros. @MarkusRodler thanks for the very detailed feedback :)

When talking about using WSL, I want to make sure I get my steps correct since I'm less familiar with the interactions there vs full linux (which I usually test in). I'm assuming this is the WSL extension which would be similar to a locally hosted code space environment?

Yes it is still an issue. The procedure is as seen in the documentation.

  1. Install WSL via wsl --install 😄 Doku: https://docs.microsoft.com/en-us/windows/wsl/install
  2. Install Debian because it is "The Distro" 😄 https://www.microsoft.com/store/productId/9MSVKQC78PK6?ocid=pdpshare
  3. Install .NET https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian
  4. Install the WSL-Extension ms-vscode-remote.remote-wsl Thats all the steps that are needed.
ryzngard commented 6 months ago

Confirmed repro. It looks like we're adding the document then moving it to the misc project instead of keeping it in the current project.

LSP][LanguageServer.ProjectSystem.RazorProjectService] Document '/home/andrha/BlazorTest/Pages/Counter5.razor' no longer exists in project 'ProjectKey { Id = /home/andrha/BlazorTest/obj/Debug/net8.0/ }'. Moving to miscellaneous project.
[Info  - 2:44:41 PM] [LSP][LanguageServer.ProjectSystem.RazorProjectService] Moving '/home/andrha/BlazorTest/Pages/Counter5.razor' from the 'ProjectKey { Id = /home/andrha/BlazorTest/obj/Debug/net8.0/ }' project to 'ProjectKey { Id = /tmp/5b011264d0f340099da645416de56d3f/__MISC_RAZOR_PROJECT__/ }' project.

I don't believe this is related to the sdk, but can onfirm that it is related to wsl connection. Potentially a timing issue with notifications of documents being added/removed. Will need to dig further

ryzngard commented 1 month ago

This has been fixed in v2.39.29. Note that you may hit an issue with semantic coloring that requires you to type/scroll in the file related to https://github.com/microsoft/vscode/issues/221423