razor icon indicating copy to clipboard operation
razor copied to clipboard

VS Code Razor syntax incorrectly highlighting code blocks without preceding @ symbol

Open TrieBr opened this issue 3 years ago • 4 comments

Describe the bug

I'm posting this based on aspnet/Razor.VSCode pointing to this repository. Apologies if its the wrong location.

I recently stared using VSCode instead of Visual studio and noticed the razor syntax highlighting is sub optimal. In one particular case, it was highlighting content totally different of how the compiler would interpret it, leading to subtle bugs.

This particular case involves the @ symbol that precedes code blocks and statements in razor templates.

In the following case, this if statement is not actually compiled as an if statement, yet Razor syntax highlighting in VS Code shows it as an if statement instead of plaintext.

image

Here is the same snippet in Visual Studio 2019. Syntax highlighting is correctly marking it as plaintext.

image

To Reproduce

  1. Install the C# Extension for VS Code (I'm using v1.23.11).
  2. Create a new file
  3. Select a language aspnetcorerazor (Do not select Razor, that one seems to work correctly, but is missing some blazor stuff)
  4. Add some minimal code:
<div>
if (true) {


}
</div>
  1. Observe that the if statement is highlighted as if it was a code block when in reality it is compiled as plaintext.

Further technical details

  • C# Extension for VS Code v1.23.11
  • ASP.NET Core version: 5.0.201
  • Include the output of dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.201
 Commit:    a09bd5c86c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.201\

Host (useful for support):
  Version: 5.0.4
  Commit:  f27d337295

.NET SDKs installed:
  5.0.101 [C:\Program Files\dotnet\sdk]
  5.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
  • VS Code:
Version: 1.55.2 (user setup)
Commit: 3c4e3df9e89829dce27b7b5c24508306b151f30d
Date: 2021-04-13T09:35:57.887Z
Electron: 11.3.0
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.19042

TrieBr avatar Apr 25 '21 16:04 TrieBr

Thanks for contacting us. We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

ghost avatar Apr 26 '21 22:04 ghost

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Apr 27 '21 21:04 ghost

Yeah, this kinda thing is all over the ASP.NET Core Razor stuff. It's largely unusable.

hammypants avatar Jun 01 '21 06:06 hammypants

This isn't specific to vscode anymore. In VS 2022 (17.3.0 Preview 2.0 for me right now) this is also the case:

image

Tragetaschen avatar Jun 28 '22 10:06 Tragetaschen

This is tracked by https://github.com/dotnet/razor-tooling/issues/4581.

allisonchou avatar Oct 19 '22 22:10 allisonchou