Skip to content

Support string enums in LiquidDoc parameter types - #1315

Merged
charlespwd merged 5 commits into
mainfrom
cp-liquiddoc-enum-review-fixes
Sep 30, 2026
Merged

charlespwd merged 5 commits into
mainfrom
cp-liquiddoc-enum-review-fixes

Conversation

@charlespwd

@charlespwd charlespwd commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

In this PR

Add string enums to LiquidDoc parameter types:

{% doc %}
  @param {'heading' | 'small'} [variant] - Text style
{% enddoc %}

The parser preserves these declarations, Theme Check validates literal arguments against them, and the language server carries the allowed values through direct references, assignments, hovers, documentation, and completions.

Inspired by Claudéric's #1310. This PR carries the full feature independently and includes the parser and validation simplifications from reviewing that work.

Problem

LiquidDoc parameter types only represented named types and arrays. There was no way to document a finite set of string values, validate callers against those values, or preserve those choices as the language server inferred variables.

Quoted braces add one parser constraint: a } inside a closed string such as 'a}b' belongs to the string. Incomplete quoted types should remain unparsed rather than guessing a boundary from the parameter name or description.

Solution

Parser and type model

  • Read type content once from the current tokenizer position.
  • When a quote opens, advance to the matching quote. When } appears outside a quote, close the type.
  • Leave types with a missing outer brace unparsed. If a quote is incomplete, use the next } as the invalid type boundary so semantic validation can reject it.
  • Represent documented enums as unions of string literal types without adding general union type math.

Theme Check

  • Accept string-literal unions in @param declarations.
  • Validate literal arguments for render, including with and for aliases, content_for, and block.
  • Suggest every allowed replacement and use the first value when inserting a required argument.
  • Leave dynamic values unchecked and keep schema-backed block parameter types authoritative.
  • Use an explicit checkArgumentType result for compatible, incompatible, named, and unchecked arguments.
  • Validate string-literal syntax without requiring a Liquid docset while leaving named Liquid types to docset validation.

Language server

  • Preserve documented values through direct references and assignments.
  • Render the union in hovers and completion documentation.
  • Insert the first allowed value for render, content_for, and block parameter completions.
  • Widen default filter results to the fallback type, with documented string enums widening to string. General union and discriminated-union type math remain out of scope.

General named-type unions such as {product | collection} and discriminated unions remain follow-up work.

@charlespwd charlespwd changed the title Simplify LiquidDoc string enum handling Support string enums in LiquidDoc parameter types Sep 30, 2026
@charlespwd
charlespwd changed the base branch from liquiddoc-string-literal-unions to main September 30, 2026 18:50
Comment thread packages/liquid-html-parser/src/liquid-doc/tokenizer.ts Outdated
@charlespwd
charlespwd force-pushed the cp-liquiddoc-enum-review-fixes branch from 2bcf0d1 to 733e4ec Compare September 30, 2026 19:47
Comment thread packages/liquid-html-parser/src/liquid-doc/tokenizer.ts Outdated
@charlespwd
charlespwd force-pushed the cp-liquiddoc-enum-review-fixes branch 2 times, most recently from 26558be to 6b6f2d0 Compare September 30, 2026 20:18
@charlespwd
charlespwd marked this pull request as ready for review September 30, 2026 20:19
@charlespwd
charlespwd requested a review from a team as a code owner September 30, 2026 20:19
@charlespwd
charlespwd force-pushed the cp-liquiddoc-enum-review-fixes branch from 6b6f2d0 to d662f4f Compare September 30, 2026 20:29
@charlespwd
charlespwd force-pushed the cp-liquiddoc-enum-review-fixes branch from d662f4f to 27eb283 Compare September 30, 2026 20:40
@charlespwd
charlespwd merged commit d3ec265 into main Sep 30, 2026
8 checks passed
@charlespwd
charlespwd deleted the cp-liquiddoc-enum-review-fixes branch September 30, 2026 20:45
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.

2 participants