razor icon indicating copy to clipboard operation
razor copied to clipboard

`IDE` diagnostics/codefixes don't work in razor files

Open DoctorKrolic opened this issue 3 years ago • 2 comments

Version used: VS 2022 v17.3 Preview 4

To reproduce:

  1. Create blazor server app
  2. Go to FetchData.razor
  3. In OnInitializedAsync method add if (forecasts is object) {}:
protected override async Task OnInitializedAsync()
{
    forecasts = await ForecastService.GetForecastAsync(DateTime.Now);

    if (forecasts is object)
    {
        
    }
}

Expected behavior: IDE0150 Null check can be simplified & a corresponding codefix

Actual behavior: No diagnostic even on rebuild

DoctorKrolic avatar Jul 26 '22 10:07 DoctorKrolic

We currently only allow specific code fixes, so its not surprising that they don't show up. The diagnostic probably should, but is probably not running on the generated file because it is marked as auto generated. We need some way to tell Roslyn to avoid this behaviour.

davidwengier avatar Jul 28 '22 21:07 davidwengier