Skip to content

Feature: setting for CollapseEmptyBrackets style ({ } vs {}) #687

Description

@fvet

Feature: setting for CollapseEmptyBrackets style ({ } vs {})

Summary

CollapseEmptyBrackets always rewrites empty brace blocks as { } (space inside). Teams that use AL Prettier (or other Prettier-style formatters) get {} instead, so code cleanup and format-on-save fight each other on interior spacing.

Please add a non-breaking setting so AZ can emit {} when requested. The default should stay { } so existing users are unchanged. Prefer fixing this in AZ AL Dev Tools (where the string is hardcoded) rather than asking AL Prettier to adopt { }.

Background / related discussion

Raised in the AL Prettier discussion:

  • adrogin/al-prettier#11 — empty {} blocks vs AZ CollapseEmptyBrackets

  • After alPrettier.collapseEmptyBraces was added, follow-up (fvet, 14 Aug 2026):

    AZ/AL DevTools applies { } to empty triggers, where ALPrettier applies {} instead. Any chance to align?

  • AL Prettier maintainer (adrogin, 27 Aug 2026) was open to adding the space in AL Prettier to match AZ.

Request here: please do not rely on fixing this in AL Prettier. Prettier’s convention across languages is tight empty braces ({}). AZ owns the literal in CollapseEmptyBrackets; supporting {} at the source keeps AL Prettier aligned with Prettier and avoids a second style fork.

Original feature: #493 — Command to collapse empty brackets into a single line.

Current behavior (source)

CollapseEmptyBrackets is implemented as a source-text rewrite (not the Microsoft AL formatter). Empty braces are replaced with a hardcoded string:

builder.Append(" { }");

in CollapseEmptyBracketsWorkspaceCommand (ProcessSourceCode).

So { } is an AZ choice, not BC formatter output.

Problem

Tool Collapsed empty braces
AZ CollapseEmptyBrackets { }
AL Prettier (collapseEmptyBraces: true, default) {}
Prettier (JS/TS empty objects/functions) {}

Workflow: AZ code cleanup → { } → format on save (AL Prettier) → {} → next cleanup → { } again → noisy diffs.

Proposed solution

Add a setting; keep current default (breaking change if default flips).

Setting

"alOutline.collapseEmptyBracketsStyle": {
  "type": "string",
  "enum": ["spaced", "compact"],
  "default": "spaced",
  "markdownDescription": "Style used by **CollapseEmptyBrackets** for empty brace blocks.\n- `spaced` — `{ }` (current behavior)\n- `compact` — `{}` (aligns with Prettier / AL Prettier)"
}

Implementation sketch

  1. Language server — in CollapseEmptyBracketsWorkspaceCommand, choose the replacement from a command parameter (same pattern as other workspace commands that read parameters):
var style = parameters != null && parameters.TryGetValue("emptyBracketsStyle", out var v)
    ? v
    : "spaced";
builder.Append(string.Equals(style, "compact", StringComparison.OrdinalIgnoreCase)
    ? " {}"
    : " { }");
  1. VS Code modifier — override getParameters on CollapseEmptyBracketsModifier (same pattern as SortVariablesModifier):
protected getParameters(uri: vscode.Uri): any {
    let parameters = super.getParameters(uri);
    let config = vscode.workspace.getConfiguration('alOutline', uri);
    parameters.emptyBracketsStyle =
        config.get<string>('collapseEmptyBracketsStyle') ?? 'spaced';
    return parameters;
}
  1. Docs — document under CollapseEmptyBrackets / alOutline.codeCleanupActions in the README.

Optional nicety

Treat both { } and {} as already collapsed (idempotent) so switching the setting does not require an expand/collapse dance.

Why a setting (not a silent change)?

Changing the hardcoded " { }" to " {}" would mass-diff every project that already runs CollapseEmptyBrackets in cleanup / CI. Opt-in compact avoids that while unblocking AL Prettier users.

Why fix in AZ, not AL Prettier?

  • The spacing is produced here (builder.Append(" { }")).
  • Prettier ecosystem standard is {}; asking AL Prettier to emit { } would diverge from Prettier for AZ compatibility only.
  • One opt-in AZ setting lets teams that use AL Prettier align cleanup + format without changing AL Prettier defaults for everyone else.

Suggested config for AL Prettier users

{
  "alOutline.collapseEmptyBracketsStyle": "compact",
  "alPrettier.collapseEmptyBraces": true
}

Acceptance criteria

  • Default remains { } (spaced) — no behavior change for existing users.
  • With collapseEmptyBracketsStyle = compact, cleanup emits {}.
  • Setting works for both editor and project Collapse Empty Brackets commands and when included in alOutline.codeCleanupActions.
  • README / setting description documents both values and the AL Prettier interoperability case.

Workaround today

None for interior space: disable CollapseEmptyBrackets, or accept flip-flopping with AL Prettier format-on-save.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions