fix: [#1787] ref snippet no longer double-wraps in Jinja braces#1898
fix: [#1787] ref snippet no longer double-wraps in Jinja braces#1898ralphstodomingo wants to merge 1 commit into
Conversation
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
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
E2E repro status on
|
Bundle Size Reportdarwin-arm64: 70.1 MB
linux-x64: 71.8 MB
win32-x64: 72.7 MB
|
Summary
refsnippet inserted{{ {{ ref('my_model') }} }}when used inside auto-closed Jinja braces.snippets/snippets_sql.json— strips the outer{{ }}from the snippet body.The bug
The
jinja-sqllanguage (contributed by thesamuelcolvin.jinjahtmldependency) auto-closes{{→}}. The oldRefsnippet body was{{ ref('${1:model_name}') }}, so:{{→ editor auto-closes to{{ }}with the cursor between them.refinside → completion menu offers theRefsnippet.{{ {{ ref('my_model') }} }}.The fix
Change the snippet body to
ref('${1:model_name}'):{{ }}(the bug scenario) → snippet completes to{{ ref('my_model') }}, which is what users expect.ref('my_model')without the Jinja wrapper. Users wrap with{{ }}themselves, andModelAutocompletionProvideralready offers real model names onceref(is typed — so this path stays functional.Verification
Confirmed on
origin/masterHEAD 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.json—autoClosingPairsincludes[\"{{\", \"}}\"]forjinja-sql.Given these two facts, typing
{{ refinside an auto-closed block deterministically yields{{ {{ ref('...') }} }}. The fix is observable from the snippet file alone.Test plan
.sqlmodel file (jinja-sql mode).{{, verify auto-closes to{{ }}.refbetween the braces, accept theRefsnippet from IntelliSense.{{ ref('model_name') }}(single set of braces).ref+ Tab → expect:ref('model_name')(no outer braces; user can wrap with{{ }}).🤖 Generated with Claude Code