dotnet / dotnet/csharp-tmLanguage

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

Open
#336 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
78
Forks
43
Avg merge
34m
Merged PRs (30d)
1

Description

### 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 `string`s will break brace highlighting if any of the `string`s contain a `;`, `{`, `}`, or `//` (maybe others?) token.

### Steps to Reproduce

1. Open a top-level C# file.
2.
```cs
using MyClass braceScopedInstance = new() // Target-typed or not does not appear to matter.
{
Strings = { ";" } // <~ Brace highlighting starts breaking here.
};

class MyClass : IDisposable
{
public List 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:
```cs
// 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](https://github.com/dotnet/vscode-csharp/files/14064385/extension-logs.zip)

### C# Trace Logs

[c#-trace-logs.txt](https://github.com/dotnet/vscode-csharp/files/14064425/c.-trace-logs.txt)

### C# LSP Trace Logs

[c#-lsp-trace-logs.txt](https://github.com/dotnet/vscode-csharp/files/14064428/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|;

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.