razor icon indicating copy to clipboard operation
razor copied to clipboard

VSCode Razor highlighting does not handle nullability well in @code blocks

Open tn-5 opened this issue 5 years ago • 8 comments

As soon as a property is declared that is of a nullable type, i.e. ? suffix, the syntax highlighting of the rest of the file seems to get confused.

Reproduce

  • Generate standard template project: dotnet new blazorserver
  • Open in VS Code
  • Open FetchData.razor
  • Observe syntax highlighting correctly highlights WeatherForecast as a class/type

Add nullable field

  • Add string? test; before the WeatherForecast declaration
  • Observe that the highlighting of WeatherForecast is still correct

Add nullable property

  • Add string? test1 {get; set;} before the WeatherForecast declaration
  • Observe that the highlighting of WeatherForecastnow reverts to generic text

It does not seem to make any difference if the setting on the project file is enabled or not.

tn-5 avatar Aug 11 '20 15:08 tn-5

I've had to turn off the new Language Services because this has made my tooling completely unusable. I was having to code blind and see if there were errors via build which is no fun.

This project builds successfully but the razor tools break at the ? on line 19: image

ChristopherHaws avatar Sep 16 '20 03:09 ChristopherHaws

@JoeRobich does O#'s C# grammar support this in VSCode?

NTaylorMullen avatar Jan 27 '21 22:01 NTaylorMullen

No the C# textmate grammar is still quite a bit behind. We would recommend enabling Semantic Highlighting.

JoeRobich avatar Jan 27 '21 23:01 JoeRobich

@tn-5 Could you open an issue against https://github.com/dotnet/csharp-tmLanguage?

JoeRobich avatar Jan 27 '21 23:01 JoeRobich

Good. I also noticed this recently. I think the nullable feature needs some more love in the toolchain if it is gonna be widely adopted.

marinasundstrom avatar Feb 04 '21 13:02 marinasundstrom

I also have this issue :(

AxelBrinck avatar Dec 06 '21 18:12 AxelBrinck

I am also having this issue as well.

zeekbrown avatar Jul 09 '22 16:07 zeekbrown

A note since it seems to have been lost, the issue was filed against csharp-tmLanguage as https://github.com/dotnet/csharp-tmLanguage/issues/191.

ryanbrandenburg avatar Oct 17 '22 21:10 ryanbrandenburg