razor icon indicating copy to clipboard operation
razor copied to clipboard

Bracket coloring is missing in Razor Code files

Open jtsom-do opened this issue 4 months ago • 2 comments

Is this a Bug or Feature request?:

Bug

Steps to reproduce:

------------------- Please fill in this section ------------------------- Open any .razor file that has a @code { } section

Description of the problem:

------------------- Please fill in this section -------------------------

Image

Beyond the opening and closing braces for the @code block, the rest of the braces are the default color. Also the indication of bracket pairs is not shown when clicked inside a pair of brackets (setting "editor.guides.bracketPairs")

Image

Expected behavior: Colorized brackets

Actual behavior: Not colorized

Logs

OmniSharp

------------------- Please fill in this section ------------------------- To find the OmniSharp log, open VS Code's "Output" pane, then in the dropdown choose "OmniSharp Log".

Razor

Expand

-- Starting Issue Data Collection-- 
[Razor.LanguageClient.Cohost.CohostDocumentPullDiagnosticsEndpointBase`2[[Roslyn.LanguageServer.Protocol.DocumentDiagnosticParams, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Roslyn.LanguageServer.Protocol.FullDocumentDiagnosticReport, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]] Getting diagnostics for E:\source\DownloadExam\Components\Pages\Error.razor
[LanguageServices.Razor.LanguageClient.Cohost.CohostOnAutoInsertEndpoint] Resolving auto-insertion for E:\source\DownloadExam\Components\Pages\Error.razor
[LanguageServices.Razor.LanguageClient.Cohost.CohostOnAutoInsertEndpoint] Calling OOP to resolve insertion at (41, 2) invoked by typing '
'
[Razor.LanguageClient.Cohost.CohostDocumentPullDiagnosticsEndpointBase`2[[Roslyn.LanguageServer.Protocol.DocumentDiagnosticParams, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Roslyn.LanguageServer.Protocol.FullDocumentDiagnosticReport, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]] Getting C# diagnostics for E:\source\DownloadExam\obj\Debug\net9.0\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Components_Pages_Error_razor.g.cs
[Razor.LanguageClient.Cohost.CohostDocumentPullDiagnosticsEndpointBase`2[[Roslyn.LanguageServer.Protocol.DocumentDiagnosticParams, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Roslyn.LanguageServer.Protocol.FullDocumentDiagnosticReport, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]] Calling OOP with the 0 C# and 0 Html diagnostics
[Diagnostics.RazorTranslateDiagnosticsService] No diagnostics remaining after filtering.
[Diagnostics.RazorTranslateDiagnosticsService] No diagnostics remaining after filtering.
[Microsoft.CodeAnalysis.Remote.Razor.SemanticTokens.RazorSemanticTokensInfoService] Requesting C# semantic tokens for host version -999, correlation ID 580f05e6-8f0d-44e5-a97e-55093d2ae98f, and the server thinks there are 174 lines of C#
[Microsoft.CodeAnalysis.Remote.Razor.SemanticTokens.RazorSemanticTokensInfoService] Returned 215 semantic tokens for span (0,0)-(46,0) in file:///E:/source/DownloadExam/Components/Pages/Error.razor.
[Razor.LanguageClient.Cohost.CohostFoldingRangeEndpoint] Getting folding ranges for E:\source\DownloadExam\Components\Pages\Error.razor
[Razor.LanguageClient.Cohost.HtmlDocumentSynchronizer] TrySynchronize for E:\source\DownloadExam\Components\Pages\Error.razor as at Checksum aNqXi9Qi79a0s1EbmIJ/5w== from workspace version 130
[Razor.LanguageClient.Cohost.HtmlDocumentSynchronizer] Going to start working on Html for E:\source\DownloadExam\Components\Pages\Error.razor as at Checksum aNqXi9Qi79a0s1EbmIJ/5w== from workspace version 130
New content for 'file:///e%3A/source/DownloadExam/Components/Pages/Error.razor', updating 'e:\source\DownloadExam\Components\Pages\Error.razor__virtual.html', checksum 'aNqXi9Qi79a0s1EbmIJ/5w=='.
[Services.HtmlRequestInvoker] Making Html request for textDocument/foldingRange on E:\source\DownloadExam\Components\Pages\Error.razor, checksum aNqXi9Qi79a0s1EbmIJ/5w==
[Razor.LanguageClient.Cohost.CohostFoldingRangeEndpoint] Calling OOP with the 3 html ranges, so it can fill in the rest
[Razor.LanguageClient.Cohost.CohostFoldingRangeEndpoint] Got a total of 8 ranges back from OOP
[Razor.LanguageClient.Cohost.HtmlDocumentSynchronizer] TrySynchronize for E:\source\DownloadExam\Components\Pages\Error.razor as at Checksum aNqXi9Qi79a0s1EbmIJ/5w== from workspace version 130
[Razor.LanguageClient.Cohost.HtmlDocumentSynchronizer] Already finished that version for E:\source\DownloadExam\Components\Pages\Error.razor
[Services.HtmlRequestInvoker] Making Html request for textDocument/documentColor on E:\source\DownloadExam\Components\Pages\Error.razor, checksum aNqXi9Qi79a0s1EbmIJ/5w==
[Razor.LanguageClient.Cohost.CohostDocumentPullDiagnosticsEndpointBase`2[[Roslyn.LanguageServer.Protocol.DocumentDiagnosticParams, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Roslyn.LanguageServer.Protocol.FullDocumentDiagnosticReport, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]] Getting diagnostics for E:\source\DownloadExam\Components\Pages\Error.razor
[LanguageServices.Razor.LanguageClient.Cohost.CohostOnAutoInsertEndpoint] Resolving auto-insertion for E:\source\DownloadExam\Components\Pages\Error.razor
[LanguageServices.Razor.LanguageClient.Cohost.CohostOnAutoInsertEndpoint] Calling OOP to resolve insertion at (42, 2) invoked by typing '
'
[Razor.LanguageClient.Cohost.CohostDocumentPullDiagnosticsEndpointBase`2[[Roslyn.LanguageServer.Protocol.DocumentDiagnosticParams, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Roslyn.LanguageServer.Protocol.FullDocumentDiagnosticReport, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]] Getting C# diagnostics for E:\source\DownloadExam\obj\Debug\net9.0\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Components_Pages_Error_razor.g.cs
[Razor.LanguageClient.Cohost.CohostDocumentPullDiagnosticsEndpointBase`2[[Roslyn.LanguageServer.Protocol.DocumentDiagnosticParams, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Roslyn.LanguageServer.Protocol.FullDocumentDiagnosticReport, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]] Calling OOP with the 0 C# and 0 Html diagnostics
[Diagnostics.RazorTranslateDiagnosticsService] No diagnostics remaining after filtering.
[Diagnostics.RazorTranslateDiagnosticsService] No diagnostics remaining after filtering.
[Microsoft.CodeAnalysis.Remote.Razor.SemanticTokens.RazorSemanticTokensInfoService] Requesting C# semantic tokens for host version -999, correlation ID a3e36ae3-5500-4b6c-808a-6c72334aa582, and the server thinks there are 175 lines of C#
[Microsoft.CodeAnalysis.Remote.Razor.SemanticTokens.RazorSemanticTokensInfoService] Returned 215 semantic tokens for span (0,0)-(47,0) in file:///E:/source/DownloadExam/Components/Pages/Error.razor.
[Razor.LanguageClient.Cohost.CohostFoldingRangeEndpoint] Getting folding ranges for E:\source\DownloadExam\Components\Pages\Error.razor
[Razor.LanguageClient.Cohost.HtmlDocumentSynchronizer] TrySynchronize for E:\source\DownloadExam\Components\Pages\Error.razor as at Checksum PMnAjYL2LbJ7ZcyVmS5VMQ== from workspace version 131
[Razor.LanguageClient.Cohost.HtmlDocumentSynchronizer] Going to start working on Html for E:\source\DownloadExam\Components\Pages\Error.razor as at Checksum PMnAjYL2LbJ7ZcyVmS5VMQ== from workspace version 131
New content for 'file:///e%3A/source/DownloadExam/Components/Pages/Error.razor', updating 'e:\source\DownloadExam\Components\Pages\Error.razor__virtual.html', checksum 'PMnAjYL2LbJ7ZcyVmS5VMQ=='.
[Services.HtmlRequestInvoker] Making Html request for textDocument/foldingRange on E:\source\DownloadExam\Components\Pages\Error.razor, checksum PMnAjYL2LbJ7ZcyVmS5VMQ==
[Razor.LanguageClient.Cohost.CohostFoldingRangeEndpoint] Calling OOP with the 3 html ranges, so it can fill in the rest
[Razor.LanguageClient.Cohost.CohostFoldingRangeEndpoint] Got a total of 8 ranges back from OOP
[Razor.LanguageClient.Cohost.CohostDocumentPullDiagnosticsEndpointBase`2[[Roslyn.LanguageServer.Protocol.DocumentDiagnosticParams, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Roslyn.LanguageServer.Protocol.FullDocumentDiagnosticReport, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]] Getting diagnostics for E:\source\DownloadExam\Components\Pages\Error.razor
[Razor.LanguageClient.Cohost.CohostDocumentPullDiagnosticsEndpointBase`2[[Roslyn.LanguageServer.Protocol.DocumentDiagnosticParams, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Roslyn.LanguageServer.Protocol.FullDocumentDiagnosticReport, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]] Getting C# diagnostics for E:\source\DownloadExam\obj\Debug\net9.0\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Components_Pages_Error_razor.g.cs
[Razor.LanguageClient.Cohost.CohostDocumentPullDiagnosticsEndpointBase`2[[Roslyn.LanguageServer.Protocol.DocumentDiagnosticParams, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Roslyn.LanguageServer.Protocol.FullDocumentDiagnosticReport, Microsoft.CodeAnalysis.LanguageServer.Protocol, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]] Calling OOP with the 0 C# and 0 Html diagnostics
[Diagnostics.RazorTranslateDiagnosticsService] No diagnostics remaining after filtering.
[Diagnostics.RazorTranslateDiagnosticsService] No diagnostics remaining after filtering.
[Razor.LanguageClient.Cohost.HtmlDocumentSynchronizer] TrySynchronize for E:\source\DownloadExam\Components\Pages\Error.razor as at Checksum PMnAjYL2LbJ7ZcyVmS5VMQ== from workspace version 131
[Razor.LanguageClient.Cohost.HtmlDocumentSynchronizer] Already finished that version for E:\source\DownloadExam\Components\Pages\Error.razor
[Services.HtmlRequestInvoker] Making Html request for textDocument/documentColor on E:\source\DownloadExam\Components\Pages\Error.razor, checksum PMnAjYL2LbJ7ZcyVmS5VMQ==
-- Stopping Issue Data Collection-- 

Workspace information

Razor document:

Expand

@page "/Error"
@using System.Diagnostics

<PageTitle>Error</PageTitle>

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (ShowRequestId)
{
    <p>
        <strong>Request ID:</strong> <code>@RequestId</code>
    </p>
}

<h3>Development Mode</h3>
<p>
    Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
    <strong>The Development environment shouldn't be enabled for deployed applications.</strong>
    It can result in displaying sensitive information from exceptions to end users.
    For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
    and restarting the app.
</p>

@code{
    [CascadingParameter]
    private HttpContext? HttpContext { get; set; }

    private string? RequestId { get; set; }
    private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

    protected override void OnInitialized() =>
        RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;

    private void Test()
    {
        Console.WriteLine("Test");
        for(var i=0; i < 10; i++)
        {



        }
    }
}

Projected CSharp document:

Expand

Cohosting is on, client has no access to CSharp content

Projected Html document:

Expand

/*~*/ /*~~~~*/
/*~~*/ /*~~~~~~~~~~~~~~*/

<PageTitle>Error</PageTitle>

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

~~~ /*~~~~~~~~~~~*/
~
    <p>
        <strong>Request ID:</strong> <code>/*~~~~~~*/</code>
    </p>
~

<h3>Development Mode</h3>
<p>
    Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
    <strong>The Development environment shouldn't be enabled for deployed applications.</strong>
    It can result in displaying sensitive information from exceptions to end users.
    For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
    and restarting the app.
</p>

/*~~*/
    /*~~~~~~~~~~~~~~~~*/
    /*~~~*/ /*~~~~~~~~*/ /*~~~~~~~*/ ~ /**/ /**/ ~

    /*~~~*/ /*~~~*/ /*~~~~~*/ ~ /**/ /**/ ~
    /*~~~*/ /**/ /*~~~~~~~~~*/ ~~ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

    /*~~~~~*/ /*~~~~*/ /**/ /*~~~~~~~~~~~*/ ~~
        /*~~~~~*/ ~ /*~~~~~~~~~~~~~~~~*/ ~~ /*~~~~~~~~~~~~~~~~~~~~~~~~~*/

    /*~~~*/ /**/ /*~~*/
    ~
        /*~~~~~~~~~~~~~~~~~~~~~~*/
        /*~~~*/ /**/ ~ ~ ~~~ /**/
        ~



        ~
    ~
~

Machine information

VSCode version: 1.103.1 Razor.VSCode version: 2.88.42

dotnet --info

Expand

.NET SDK:
 Version:           9.0.304
 Commit:            f12f5f689e
 Workload version:  9.0.300-manifests.407ced12
 MSBuild version:   17.14.16+5d8159c5f

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26100
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.304\

.NET workloads installed:
 [aspire]
   Installation Source: SDK 9.0.300, VS 17.14.36408.4, VS 17.14.36408.4
   Manifest Version:    8.2.2/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.8
  Architecture: x64
  Commit:       aae90fa090

.NET SDKs installed:
  3.1.426 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  6.0.136 [C:\Program Files\dotnet\sdk]
  6.0.321 [C:\Program Files\dotnet\sdk]
  6.0.428 [C:\Program Files\dotnet\sdk]
  7.0.120 [C:\Program Files\dotnet\sdk]
  7.0.317 [C:\Program Files\dotnet\sdk]
  7.0.410 [C:\Program Files\dotnet\sdk]
  8.0.119 [C:\Program Files\dotnet\sdk]
  8.0.206 [C:\Program Files\dotnet\sdk]
  8.0.316 [C:\Program Files\dotnet\sdk]
  8.0.413 [C:\Program Files\dotnet\sdk]
  9.0.304 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Extensions

Extension Author Version
base64 m4ns0ur 1.0.0
copilot GitHub 1.356.1733
copilot-chat GitHub 0.30.1
csdevkit ms-dotnettools 1.50.11
csharp ms-dotnettools 2.88.42
data-workspace-vscode ms-mssql 0.6.3
hexeditor ms-vscode 1.11.1
hl7tools RobHolme 2.0.7
live-server ms-vscode 0.4.15
markdown-all-in-one yzhang 3.6.3
material-icon-theme PKief 5.25.0
mssql ms-mssql 1.34.0
night-owl sdras 2.1.1
quicktype quicktype 23.0.170
rest-client humao 0.25.1
sql-bindings-vscode ms-mssql 0.4.1
sql-database-projects-vscode ms-mssql 1.5.3
TabOut albert 0.2.2
vscode-azureappservice ms-azuretools 0.26.3
vscode-azurefunctions ms-azuretools 1.18.1
vscode-azureresourcegroups ms-azuretools 0.11.1
vscode-dotnet-runtime ms-dotnettools 2.3.7
vscodeintellicode-csharp ms-dotnettools 2.2.3
vsctoix a-bentofreire 4.0.13
xml DotJoshJohnson 2.5.1

jtsom-do avatar Aug 13 '25 18:08 jtsom-do

Can confirm, this repros for me with and without cohosting, so not a regression. I would have expected our language-configuration.json to enable brace matching and related features.

davidwengier avatar Aug 13 '25 22:08 davidwengier

Okay, I see whats going on. We never set up for this (C# only did so in April this year), but its pretty trivial to add colorizedBracketPairs to our language-configuration.json. That would work, except we explicit brand all of Razor as having unmatched brackets, because otherwise things get weird in Html:

Image

So to fix this we need to:

  • Add colorizedBracketPairs to our language-configuration.json as appropriate
  • Be more specific with the list of scopes in our unmatchedBracketPairs entry to just include Html, not all of Razor, if that's possible: https://github.com/dotnet/vscode-csharp/blob/97d36f143f87160e1429ca2540c4b8cedce926e5/package.json#L5568-L5570

It's going to take a lot of work in our grammar though I think, to have more detailed scopes:

Image

davidwengier avatar Aug 13 '25 22:08 davidwengier