microsoft / microsoft/vscode-cpptools

[vcFormat] `space.withinInitializerListBraces`/`space.withinSquareBrackets` are not heeded inside array initialization

Aperta
#14,412 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug Feature: Code Formatting Language Service Visual Studio
Lingua principale
TypeScript
Stelle
6.2k
Fork
1.7k
Merge medio
14h 46m
PR unite (30g)
61

Descrizione

Environment
  • OS and Version: Various (assuming all)
  • VS Code Version: 1.117.0
  • C/C++ Extension Version: 1.31.5
Bug Summary and Steps to Reproduce

Bug Summary:

When the setting C_Cpp.vcFormat.space.withinInitializerListBraces is set to true, vcFormat fails to add (and will actually remove) a space from between the opening brace and the first designated initializer of all struct members when part of the initialization of an array of structs.

Steps to reproduce:

  1. Ensure C_Cpp.vcFormat.space.withinInitializerListBraces is set to true
  2. Add the following lines to a .c file:
typedef struct {
    int member_a;
    int member_b;
} MyStruct_t;

MyStruct_t array_of_structs[] = {
    { .member_a = 0, .member_b = 1 },
    { .member_a = 2, .member_b = 3 },
    { .member_a = 4, .member_b = 5 },
};
  1. Format the file using vcFormat

Expected behavior:

  • The file should not change

Actual result:

typedef struct {
    int member_a;
    int member_b;
} MyStruct_t;

MyStruct_t array_of_structs[] = {
    {.member_a = 0, .member_b = 1 },
    {.member_a = 2, .member_b = 3 },
    {.member_a = 4, .member_b = 5 },
};

The same problem also appears to afflict the first designated initializer of an array with spaces enabled inside square brackets. Here are steps to reproduce:

  1. Ensure C_Cpp.vcFormat.space.withinSquareBrackets is set to true
  2. Add the following lines to a .c file:
int my_array[3] = {
    [ 0 ] = 100,
    [ 1 ] = 101,
    [ 2 ] = 102,
};
  1. Format the file using vcFormat

Expected behavior:

  • The file should not change

Actual result:

int my_array[3] = {
    [0] = 100,
    [ 1 ] = 101,
    [ 2 ] = 102,
};
Configuration and Logs
Configurations vary; the pertinent configuration options are mentioned above.

Logs will be provided if deemed necessary. I believe this should be very easily reproduced.
Other Extensions

No response

Additional context

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il problema in un file .c con vcFormat e l'impostazione pertinente space.withinInitializerListBraces o space.withinSquareBrackets abilitata. Traccia il modo in cui vcFormat gestisce il primo inizializzatore designato all'interno dell'inizializzazione di un array, quindi verifica che la formattazione preservi gli spazi mostrati in entrambi gli esempi previsti.

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

Valutazione

Stack tecnologico
c, cpp
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
56/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.