Fix autocomplete for variables whose names match grammar keywords #15
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-autocomplete-on-keywords"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
When a user-provided variable has the same name as a Liquid keyword (e.g.
case,assign,render,for), typingcase.inside{{ }}produced no property completions. The variable name itself would autocomplete, but member access failed entirely.Root cause: The
kw<word>template uses@specializeto replace identifier tokens with keyword tokens. In theliquidDirectivesection, this creates specializations for ~25 keywords (case,if,for,echo,assign, etc.) on the identifier token. Lezer's@specializeshould fall back to the original identifier when the keyword isn't valid in the current parse context, but it wasn't doing so — the parser would close theInterpolationwith an error node and the content fell through to the HTML parser asText.Fix: Introduce a
kwx<word>template using@extend(instead of@specialize).@extendmakes both the keyword token and the original identifier token available simultaneously, letting the GLR parser choose the correct interpretation per context. TheliquidDirectivesection andRenderParameternow usekwx<>, while expression-context keywords (empty,forloop,tablerowloop,continue,contains) retain@specializeso they're still preferred overVariableName.Test plan
{{ case.id }}), tag context ({% if case.id %}), liquid tag ({% liquid\necho case.id %}), and multiple keywords as variables.case/for/ifdirectives, operators, render parameters, liquid tags, etc.).Wow, that's an interesting feature. Are you sure this doesn't also apply to the remaining tag keywords?
{{ continue.length }}, for example, seems to be supported.Good catch. I tested against the LiquidJS playground and confirmed that
continue,forloop,tablerowloop, andinall work as variable names in Liquid. Onlyemptyandcontainsare truly reserved in expression context.I've updated the PR to switch those four to @extend as well. The only keywords still using
@specialize(viakw<>) areemptyandcontains, which LiquidJS rejects as variable names.Thanks. I've merged this as
4ff79e865aPull request closed