Repository navigation
Index Liquid templates - #878
2 commits merged into
Conversation
code-review-graph reviewOverall risk: 0.40 (MEDIUM) — 8 changed function(s)/class(es), 17 affected flow(s), 5 test gap(s) Risk-scored changes
Affected execution flows
Test gaps
Token savings: this graph-backed report used ~174,355 fewer tokens (~89%) than reading every changed file in full (estimated, chars/4 approximation). Powered by code-review-graph — local-first analysis; no code leaves the CI runner. |
|
Outside this sweep's mission of demonstrated coding-session token savings: this adds a new Liquid parser. Bare template references, raw-block handling and a complete cross-file impact workflow need evidence before that language expansion is included. |
|
Checks pass and the code looks right. Missing: tests for the edge cases it introduces.
Every new branch in the code should have a test, including the failure branch. Disagree with any of these? Say so here first. PRs now target |
|
A file containing only a raw block: {% raw %}
{% assign should_not_exist = 1 %}
{{ should_not_be_output }}
{% render 'not-a-real-snippet' %}
{% endraw %}yields a Variable Same for {% liquid
# assign ghost_var = 1
# render 'ghost-snippet'
assign real_var = 2 %}Variables come out as Render targets still do not resolve. I built Shopify Dawn on this branch. All 127 new liquid REFERENCES edges are stored with Output names embed the line number, so qualified_name is Gates are genuinely clean: 4237 passed, 0 failed, ruff clean, mypy clean. The table diff over Dawn is purely additive. 0 node names lost, 0 edges lost, Class 51 to 51, Function 429 to 429, CALLS 2522 to 2522. Nothing existing is touched or respelled. One cost to weigh while fixing the rest. 3445 of 4352 nodes are Output nodes whose name is raw expression text. FTS hits for To merge:
|
|
Thank you for this PR. I tested it merged with the latest staging on a small Liquid repo. Before I can merge it, please fix these:
After you push the fix, I will test it again. |
There was a problem hiding this comment.
🟡 Changes recommended
The parser still extracts false variables, outputs, and dependencies from quoted values, inline comments, and raw blocks, polluting the code-review graph.
3 open issues
What changed in this PR
Adds structural Liquid template indexing to the code-review graph, addressing #348 by recognizing .liquid files and extracting graph content without a dedicated Tree-sitter grammar.
Changes:
- Registers Liquid file detection and a regex-based parser.
- Extracts file, assignment, and output nodes plus static render/include references, while masking block comments.
- Adds regression tests for ordinary tags and multiline
liquidblocks.
| File | Description |
|---|---|
tests/test_liquid.py |
Tests Liquid detection, extraction, block-comment masking, and multiline blocks. |
code_review_graph/parser.py |
Adds Liquid recognition, parser dispatch, and structural extraction. |
Review effort: Balanced
| r"""(?<!@)@(extends|include|component|livewire)\s*\(\s*(['"])([^'"]+)\2\s*\)""", | ||
| ) | ||
| _LIQUID_COMMENT_RE = re.compile( | ||
| r"\{%-?\s*comment\s*-?%\}.*?\{%-?\s*endcomment\s*-?%\}", |
| for character in match.group(0) | ||
| ) | ||
|
|
||
| return cls._LIQUID_COMMENT_RE.sub(replace_comment, text) |
| for segment in segments: | ||
| for assign in self._LIQUID_ASSIGN_RE.finditer(segment): |
d01c1fd
The review on tirth8205#878 listed what a real theme showed: - `raw` blocks and `#` lines inside `{% liquid %}` read as live code. So did inline comment tags, `doc`, `schema`, `javascript`, `stylesheet` and quoted text. Only the first word of a statement is now its directive. - `render` and `include` left bare names, so a snippet had no inbound edges and an empty impact radius. They now link to `snippets/<name>.liquid` with `IMPORTS_FROM`, as Blade includes do, and the lookup stays inside the repo. - Output names held the line number, so one new line renamed every output below it. A second `assign` to a name also overwrote the first. A repeated name is now one node that lists every line, and file nodes contain their children. - Output nodes took all ten top hits for "product" on Dawn, so search leaves them out unless asked for with `kind="Output"`. On Shopify's Dawn: 124 of 124 render and include statements link to a file, `importers_of` on `card-product` finds its 6 templates, adding a line above `image-banner` renames 0 of 33 nodes, and 2,780 nodes emitted are 2,780 stored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Summary
.liquidfiles were not recognized bydetect_language, so full builds excluded them and file summaries returned zero nodes.This adds a structural, regex-based Liquid parser that indexes:
Filenode for every template;Variablenodes forassigndeclarations, including whitespaceliquidblocks;Outputnodes for non-empty{{ ... }}expressions;REFERENCESedges for staticrenderandincludetargets.Liquid comments are masked while preserving byte offsets and line numbers, so directives inside comments are not indexed.
Fixes #348.
Testing
assign, output,render, and comment masking;{% liquid ... %}blocks.pytest tests/test_liquid.py -q— 2 passedruff check code_review_graph/parser.py tests/test_liquid.py— passesgit diff --check— passes