Skip to content

Preserve hash brace padding and pad auto-closed Twig delimiters - #125

Merged
mblode merged 2 commits into
masterfrom
claude/new-session-v4p7h8
Sep 24, 2026
Merged

mblode merged 2 commits into
masterfrom
claude/new-session-v4p7h8

Conversation

@mblode

@mblode mblode commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Fixes #124, fixes #123.

#124 — space inside with hashes removed

formatTwig unconditionally tightened {/}, so {% include 'tooltip.twig' with { "content": "my tooltip" } %} became {"content": "my tooltip"}. Brace pairs are now matched and keep a single space when the author padded either side; unpadded hashes stay tight, empty { } becomes {}. Both styles are idempotent.

#123 — cursor after auto-closing {{, {%, {#

The auto-closing pair " }}" left the cursor as {{| }}. The extension now detects that auto-close edit (VS Code emits it as "{ }", "% %", "# #"), waits for the typing command to move the cursor to the expected offset, then inserts a space without an undo stop. Result: {{ | }}. Multi-cursor supported; undo/redo edits are ignored.

Other changes

  • .twig-core.json hashes refreshed via scripts/sync-core.mjs (format.js and extension.js are shared core). vscode-twig-language and vscode-pretty-formatter still need a sync to pick these fixes up.
  • test/provider.test.js vscode mock stubs the two new event APIs.

Testing

🤖 Generated with Claude Code

https://claude.ai/code/session_01NCo2qCP2ZkpV2b8hrk3UBS


Generated by Claude Code


Note

Low Risk
Localized formatter spacing rules and optional document edits on Twig auto-close; no security or persistence changes, with new unit and integration tests.

Overview
Release 0.12.2 fixes two Twig editing/formatting UX issues.

The formatter no longer strips intentional spaces inside hash braces: padded with { "content": "x" } stays padded, tight {"content":"x"} stays tight, and empty { } still collapses to {}. Brace pairs are tracked so padding is preserved when either side had whitespace in the source.

The extension adds listeners on document change and selection change so that after VS Code auto-closes {{, {%, or {#, a space is inserted inside the opening delimiter (without a separate undo stop), leaving the cursor in {{ | }} instead of {{| }}. Shared core hashes in .twig-core.json and the bundled extension/ output are updated accordingly.

Regression coverage includes formatter cases for #124 and VS Code integration tests that type delimiters and assert padded auto-close behavior; provider tests stub the new workspace/window subscriptions.

Reviewed by Cursor Bugbot for commit 7880673. Bugbot is set up for automated code reviews on this repo. Configure here.

Fixes #124: the formatter stripped spaces inside hash literals such as
`with { "content": "my tooltip" }`. Brace pairs now keep a single space
when the author padded either side, and stay tight otherwise.

Fixes #123: auto-closing {{, {% and {# left the cursor as {{| }}. The
extension now inserts the missing space once the cursor settles, giving
{{ | }}.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCo2qCP2ZkpV2b8hrk3UBS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCo2qCP2ZkpV2b8hrk3UBS
@mblode
mblode marked this pull request as ready for review September 24, 2026 20:23
@mblode
mblode merged commit 4fc9d7d into master Sep 24, 2026
1 check passed
mblode pushed a commit to mblode/vscode-twig-language that referenced this pull request Sep 24, 2026
Synchronized from mblode/vscode-twig-language-2#125 with scripts/sync-core.mjs.
Ports the fixes for vscode-twig-language-2#124 (formatter stripped spaces
inside hash literals) and #123 (cursor left at {{| }} after auto-close).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCo2qCP2ZkpV2b8hrk3UBS
@cursor

cursor Bot commented Sep 24, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_1d97c009-da1b-471e-9150-61f8ca7842b4)

mblode pushed a commit to mblode/vscode-pretty-formatter that referenced this pull request Sep 24, 2026
Synchronized from mblode/vscode-twig-language-2#125 with scripts/sync-core.mjs.
Ports the formatter fix for vscode-twig-language-2#124 (spaces inside hash
literals such as with { "content": "x" } were removed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCo2qCP2ZkpV2b8hrk3UBS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Space inside with object gets incorrectly removed Cursor position when auto-closing curly

2 participants