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

Aperta
#336 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
78
Fork
43
Merge medio
34m
PR unite (30g)
1

Descrizione

### 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|;

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia riproducendo l'esempio C# top-level fornito e analizza le regole grammaticali per le dichiarazioni using top-level, gli inizializzatori di oggetti, gli inizializzatori di raccolte e le stringhe. Verifica il comportamento con i casi ";", "{", "}" e "//", quindi conferma che la corrispondenza delle parentesi graffe rimanga corretta sia a livello top-level sia all'interno di uno scope esplicito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, typescript
Ambito
developer-experience, tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.