Skip to content

[Bug]: Top-level brace-scoped using declaration with object initializer containing string collection initializer with ;, {, or } tokens in items break brace highlighting #336

@just-ero

Description

@just-ero

Issue Description

This seems to be an edge case that has not been noticed.
In a top-level file, a brace-scoped using declaration with an object initialized which contains a collection initializer containing strings will break brace highlighting if any of the strings contain a ;, {, }, or // (maybe others?) token.

Steps to Reproduce

  1. Open a top-level C# file.
  2. using MyClass braceScopedInstance = new() // Target-typed or not does not appear to matter.
    {
        Strings = { ";" } // <~ Brace highlighting starts breaking here.
    };
    
    class MyClass : IDisposable
    {
        public List<string> Strings { get; }
    
        public void Dispose() { }
    }

Expected Behavior

Brace highlighting continues to be correct.

Actual Behavior

Visual Studio Code highlights the closing braces after the ";" incorrectly. It also believes that the first opening brace does not have a closing match.

The behavior is slightly different for {, } and // tokens.

The expected behavior happens when the code is within any kind of scope:

// Something as simple as this in the top-level file is enough.
{
    using MyClass braceScopedInstance = new()
    {
        Strings = { ";" } // Brace highlighting is correct.
    };
}

Logs

extension-logs.zip

C# Trace Logs

c#-trace-logs.txt

C# LSP Trace Logs

c#-lsp-trace-logs.txt

Environment information

VSCode version: 1.85.2
C# Extension: 2.15.30
Using OmniSharp: false

Dotnet Information
.NET SDK:
 Version:   8.0.100-rc.2.23502.2
 Commit:    0abacfc2b6

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100-rc.2.23502.2\

.NET workloads installed:
 [wasi-experimental]
   Installation Source: SDK 8.0.100-rc.2
   Manifest Version:    8.0.0-rc.2.23479.6/8.0.100-rc.2
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.workload.mono.toolchain.current\8.0.0-rc.2.23479.6\WorkloadManifest.json
   Install Type:              Msi


Host:
  Version:      8.0.0-rc.2.23479.6
  Architecture: x64
  Commit:       0b25e38ad3

.NET SDKs installed:
  8.0.100-rc.2.23502.2 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.0-rc.2.23479.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

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

Download .NET:
  https://aka.ms/dotnet/download
Visual Studio Code Extensions
Extension Author Version Folder Name
csdevkit ms-dotnettools 1.3.6 ms-dotnettools.csdevkit-1.3.6-win32-x64
csharp ms-dotnettools 2.15.30 ms-dotnettools.csharp-2.15.30-win32-x64
vscode-dotnet-runtime ms-dotnettools 2.0.1 ms-dotnettools.vscode-dotnet-runtime-2.0.1
vscodeintellicode-csharp ms-dotnettools 0.1.26 ms-dotnettools.vscodeintellicode-csharp-0.1.26-win32-x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions