Skip to content

fix: [#1787] ref snippet no longer double-wraps in Jinja braces#1898

Draft
ralphstodomingo wants to merge 1 commit into
masterfrom
fix/1787-ref-snippet-double-braces
Draft

fix: [#1787] ref snippet no longer double-wraps in Jinja braces#1898
ralphstodomingo wants to merge 1 commit into
masterfrom
fix/1787-ref-snippet-double-braces

Conversation

@ralphstodomingo
Copy link
Copy Markdown
Contributor

Summary

  • Fixes #1787: the ref snippet inserted {{ {{ ref('my_model') }} }} when used inside auto-closed Jinja braces.
  • One-line change to snippets/snippets_sql.json — strips the outer {{ }} from the snippet body.

The bug

The jinja-sql language (contributed by the samuelcolvin.jinjahtml dependency) auto-closes {{}}. The old Ref snippet body was {{ ref('${1:model_name}') }}, so:

  1. User types {{ → editor auto-closes to {{ }} with the cursor between them.
  2. User types ref inside → completion menu offers the Ref snippet.
  3. Accepting the snippet inserts the full body including the outer braces → {{ {{ ref('my_model') }} }}.

The fix

Change the snippet body to ref('${1:model_name}'):

  • Inside auto-closed {{ }} (the bug scenario) → snippet completes to {{ ref('my_model') }}, which is what users expect.
  • On a blank line → snippet inserts ref('my_model') without the Jinja wrapper. Users wrap with {{ }} themselves, and ModelAutocompletionProvider already offers real model names once ref( is typed — so this path stays functional.

Verification

Confirmed on origin/master HEAD via static inspection:

  • snippets/snippets_sql.json:202-208 — snippet body was {{ ref('${1:model_name}') }} (single braces).
  • samuelcolvin.jinjahtml-0.20.0-universal/language-configuration.jsonautoClosingPairs includes [\"{{\", \"}}\"] for jinja-sql.

Given these two facts, typing {{ ref inside an auto-closed block deterministically yields {{ {{ ref('...') }} }}. The fix is observable from the snippet file alone.

Test plan

  • Open a .sql model file (jinja-sql mode).
  • Type {{, verify auto-closes to {{ }}.
  • Type ref between the braces, accept the Ref snippet from IntelliSense.
  • Expect: {{ ref('model_name') }} (single set of braces).
  • On a blank line, type ref + Tab → expect: ref('model_name') (no outer braces; user can wrap with {{ }}).

🤖 Generated with Claude Code

When a user typed `{{`, the jinjahtml language config auto-closed to
`{{  }}`. Typing `ref` between the braces triggered the `Ref` snippet,
which inserted its full body `{{ ref('model') }}` — producing the
nested `{{ {{ ref('model') }} }}` shown in the issue.

Strip the outer `{{ }}` from the snippet body so it composes correctly
inside an auto-closed Jinja block. Typing `{{ ref` + Tab now yields
`{{ ref('model_name') }}` as users expect. On a blank line, the
snippet inserts bare `ref('model_name')` — users can wrap with
`{{ }}`, and the `ModelAutocompletionProvider` already handles the
`ref(` context with real model names.

Refs: #1787
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d4046a2f-b89b-4f0c-94d4-fcec8598b29f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1787-ref-snippet-double-braces

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ralphstodomingo
Copy link
Copy Markdown
Contributor Author

E2E repro status on origin/master HEAD

Interactive E2E (typing {{, then ref, then accepting the snippet) couldn't be driven through code-server + Playwright MCP in this environment: code-server's keybinding dispatcher throws TypeError: a.hasAttribute is not a function on synthesized keyboard events, so typed characters don't land in Monaco's buffer. Documented in the parallel #1897 thread.

That said, the bug is provable from static facts observable in the Docker container — no timing, no runtime state required:

Fact 1 — the snippet body on origin/master

snippets/snippets_sql.json:202-208:

"Ref": {
  "prefix": "ref",
  "body": ["{{ ref('${1:model_name}') }}"],
  "description": "Ref"
}

The body has its own set of {{ }}.

Fact 2 — jinja-sql auto-close config

Inside the running container, samuelcolvin.jinjahtml-0.20.0-universal/language-configuration.json (the required dep that owns the jinja-sql language):

"autoClosingPairs": [
  ["@/", "/"],
  ["{#", "#}"],
  ["{%", "%}"],
  ["{{", "}}"],
  ...
]

Typing {{ in a jinja-sql document auto-inserts }} and parks the cursor inside.

Combined

Given those two facts, the following is deterministic:

  1. User types {{ → editor becomes {{ }} with cursor between the braces.
  2. User types ref → IntelliSense offers the Ref snippet (prefix match).
  3. Accepting the snippet inserts its full body including the outer {{ }}.
  4. Result: {{ {{ ref('my_model') }} }} — exactly what ref snippet autocomplete adds extra placeholder text that must be deleted before model selection works #1787 reports.

Post-fix behaviour

With the body changed to ref('${1:model_name}'):

  1. Same typing path produces {{ ref('my_model') }} inside the auto-closed braces.
  2. On a blank line, ref + Tab produces ref('my_model') — user wraps with {{ }} themselves. The ModelAutocompletionProvider at src/autocompletion_provider/modelAutocompletionProvider.ts:24 already handles the ref( case with actual model names, so this path stays smart.

Will mark ready once you've had a chance to confirm the typing behaviour locally — the snippet JSON is picked up on extension reload, no rebuild needed.

@github-actions
Copy link
Copy Markdown

Bundle Size Report

darwin-arm64: 70.1 MB
Category Size Compressed Files
Native: altimate-core 35.1 MB 14.0 MB 1
Media assets 29.6 MB 25.8 MB 91
Webview JS bundles 26.1 MB 8.3 MB 343
Native: zeromq 20.5 MB 8.2 MB 15
Webview images 15.3 MB 12.2 MB 18
Extension backend (JS) 2.7 MB 0.6 MB 1
Python packages 2.0 MB 0.5 MB 95
Native: other node_modules 1.0 MB 0.2 MB 139
Webview CSS 0.8 MB 0.1 MB 2
Webview other 0.5 MB 0.1 MB 5
Other 0.1 MB 26 KB 15
Total 133.6 MB 70.0 MB 725
linux-x64: 71.8 MB
Category Size Compressed Files
Native: altimate-core 41.8 MB 15.1 MB 1
Media assets 29.6 MB 25.8 MB 91
Webview JS bundles 26.1 MB 8.3 MB 343
Native: zeromq 21.9 MB 8.7 MB 16
Webview images 15.3 MB 12.2 MB 18
Extension backend (JS) 2.7 MB 0.6 MB 1
Python packages 2.0 MB 0.5 MB 95
Native: other node_modules 1.0 MB 0.2 MB 139
Webview CSS 0.8 MB 0.1 MB 2
Webview other 0.5 MB 0.1 MB 5
Other 0.1 MB 26 KB 15
Total 141.7 MB 71.7 MB 726
win32-x64: 72.7 MB
Category Size Compressed Files
Native: altimate-core 50.3 MB 16.2 MB 1
Media assets 29.6 MB 25.8 MB 91
Webview JS bundles 26.1 MB 8.3 MB 343
Native: zeromq 20.0 MB 8.1 MB 15
Webview images 15.3 MB 12.2 MB 18
Extension backend (JS) 2.7 MB 0.6 MB 1
Native: other node_modules 2.3 MB 0.7 MB 147
Python packages 2.0 MB 0.5 MB 95
Webview CSS 0.8 MB 0.1 MB 2
Webview other 0.5 MB 0.1 MB 5
Other 0.1 MB 26 KB 15
Total 149.6 MB 72.6 MB 733

@ralphstodomingo ralphstodomingo self-assigned this Apr 21, 2026
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.

ref snippet autocomplete adds extra placeholder text that must be deleted before model selection works

1 participant