Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LiquidDoc] Parser support for optional parameters #733

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

jamesmengo
Copy link
Contributor

@jamesmengo jamesmengo commented Jan 24, 2025

What are you adding in this PR?

Part of https://github.com/Shopify/develop-advanced-edits/issues/525

Adds LiquidDoc parsing support to allow users to define optional parameters.

Optional Parameters - @param [optional_param]

  • By default, parameters are now required unless they have [] around the name
  • Parameters with incomplete delimiters e.g. ([missingTail) will map to a TextNode

Adds parser support for [ and ] delimiters around the stringName, which indicate that a param is optional

Within the code, I'm storing this as 'required' rather than 'optional'. The default will be required: true

@param [paramName]

What's next? Any followup issues?

Before you deploy

  • I included a minor bump changeset
  • My feature is backward compatible

@jamesmengo jamesmengo changed the title Add optional param delimiters to ohm parser [LiquidDoc] Parser support for optional parameters Jan 24, 2025
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch from 04f5d07 to 9b8824b Compare January 24, 2025 22:36
@jamesmengo jamesmengo marked this pull request as ready for review January 24, 2025 22:53
@jamesmengo jamesmengo requested a review from a team as a code owner January 24, 2025 22:53
@jamesmengo jamesmengo marked this pull request as draft January 24, 2025 22:53
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch 2 times, most recently from c0e6ed0 to 720b222 Compare January 25, 2025 00:17
@jamesmengo jamesmengo changed the base branch from main to jm/prevent_hover_nonexistent_snippets January 25, 2025 00:17
@jamesmengo jamesmengo force-pushed the jm/prevent_hover_nonexistent_snippets branch 2 times, most recently from 6414426 to 9560ce1 Compare January 27, 2025 17:15
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch from 720b222 to 31d1bd9 Compare January 27, 2025 17:15
@jamesmengo jamesmengo force-pushed the jm/prevent_hover_nonexistent_snippets branch from 9560ce1 to 6f1ddbb Compare January 27, 2025 17:53
@jamesmengo jamesmengo changed the base branch from jm/prevent_hover_nonexistent_snippets to graphite-base/733 January 27, 2025 17:53
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch from 31d1bd9 to a62068b Compare January 27, 2025 17:54
@jamesmengo jamesmengo changed the base branch from graphite-base/733 to main January 27, 2025 17:54
@jamesmengo jamesmengo marked this pull request as ready for review January 27, 2025 17:54
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch from a62068b to 5426ddb Compare January 27, 2025 17:54
@jamesmengo jamesmengo marked this pull request as draft January 27, 2025 17:54
@jamesmengo jamesmengo marked this pull request as ready for review January 27, 2025 18:04
@jamesmengo jamesmengo added the #gsd:44310 LiquidDoc label Jan 27, 2025 — with Graphite App
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch from 5426ddb to dcb46c0 Compare January 27, 2025 20:36
graygilmore
graygilmore previously approved these changes Jan 27, 2025
packages/liquid-html-parser/grammar/liquid-html.ohm Outdated Show resolved Hide resolved
packages/liquid-html-parser/src/stage-1-cst.spec.ts Outdated Show resolved Hide resolved
packages/liquid-html-parser/src/stage-1-cst.ts Outdated Show resolved Hide resolved
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch 2 times, most recently from e91db5d to 374d89f Compare January 28, 2025 01:45
@jamesmengo jamesmengo self-assigned this Jan 28, 2025
@jamesmengo jamesmengo requested a review from aswamy January 28, 2025 02:40
Copy link
Contributor

@graygilmore graygilmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not get a 🎩 in yet but since this is just parser changes maybe the tests are all we need here!

.changeset/smart-onions-pump.md Outdated Show resolved Hide resolved
packages/liquid-html-parser/grammar/liquid-html.ohm Outdated Show resolved Hide resolved
@jamesmengo jamesmengo marked this pull request as draft January 28, 2025 21:19
@jamesmengo
Copy link
Contributor Author

Closing in favour of #753

@jamesmengo jamesmengo closed this Feb 4, 2025
@jamesmengo jamesmengo reopened this Feb 4, 2025
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch 2 times, most recently from ada22c8 to 26abb91 Compare February 4, 2025 20:12
@jamesmengo jamesmengo marked this pull request as ready for review February 4, 2025 20:13
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch from 26abb91 to c1106c6 Compare February 4, 2025 20:16
@jamesmengo jamesmengo marked this pull request as draft February 4, 2025 20:16
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch 4 times, most recently from a963b38 to c67d319 Compare February 4, 2025 20:24
@jamesmengo jamesmengo marked this pull request as ready for review February 4, 2025 20:31
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch from c67d319 to 2e69f9d Compare February 4, 2025 20:35
paramDescription: ConcreteTextNode | null;
paramType: ConcreteTextNode | null;
}

export interface ConcreteLiquidDocParamNameNode
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may look kind of weird to have required live in this node, however this is consistent with how the parsing logic works, and allows us to use the mappings in stage-1.

We do this because it aligns with the parsing grammar, and allows us to leverage the Mappings mechanism. We map this to a more sensible location in stage-2 here (node.paramName.required -> node.required)

----
- Added a parameter `required` to the LiquidDocParamNode
- Parameters with `[]` around the name will return `required: true`
- Parameters with incomplete delimiters `e.g. ([missingTail)` will map to a `TextNode`
@jamesmengo jamesmengo force-pushed the jm/parse_optional_params branch from 2e69f9d to 8c9f5bc Compare February 4, 2025 20:44
Copy link
Contributor

@aswamy aswamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Can't wait for prettier PR!

@jamesmengo jamesmengo merged commit d5e8ec9 into main Feb 4, 2025
7 checks passed
@jamesmengo jamesmengo deleted the jm/parse_optional_params branch February 4, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#gsd:44310 LiquidDoc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants