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] Add snippet hover support inside of {% render %} tag #703

Merged
merged 5 commits into from
Jan 27, 2025

Conversation

jamesmengo
Copy link
Contributor

@jamesmengo jamesmengo commented Jan 13, 2025

What are you adding in this PR?

https://github.com/Shopify/develop-advanced-edits/issues/496

1) Hover support for Liquid snippets inside of a {% render %} tag. Users will now see:

  • The snippet name as a header
  • A list of parameters with their types and descriptions (if
    documented)

If there is no {% doc %} present in the snippet, we will just render the snippet name

2) Caching for fetching LiquidDoc definitions

Example snippet documentation:
{% doc %}
  @param {String} title - The title of the product
  @param {Number} border-radius - The border radius in px
{% enddoc %}
When hovering over product-card in {% render 'product-card' %}, users will see:
### product-card

**Parameters:**
- `title`: String - The title of the product
- `border-radius`: Number - The border radius in px

Uploading Cursor - liquidDoc.ts — theme-tools.mp4…

Hovering a snippet with docs

image.png

Hovering a snippet without liquiddoc

image.png

What's next? Any followup issues?

  • Consider adding validation for param types
  • Add support for return value documentation
  • Add support for example usage documentation

What did you learn?

This is my first time working with the hover API in VS code. Pretty cool to read up on!

Before you deploy

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

Copy link
Contributor Author

jamesmengo commented Jan 13, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jamesmengo jamesmengo changed the base branch from jm/implement_fallbackNode to graphite-base/703 January 16, 2025 22:17
@jamesmengo jamesmengo changed the base branch from graphite-base/703 to main January 16, 2025 22:20
@jamesmengo jamesmengo force-pushed the jm/param_hover branch 3 times, most recently from b6ca8f0 to 35d1735 Compare January 17, 2025 01:29
@jamesmengo jamesmengo requested a review from karreiro January 22, 2025 00:24
@jamesmengo jamesmengo changed the title [LiquidDoc] Render @Param tag on hover [LiquidDoc] Add snippet hover support inside of {% render %} tag Jan 22, 2025
@jamesmengo jamesmengo force-pushed the jm/param_hover branch 2 times, most recently from 3afb318 to a167761 Compare January 22, 2025 00:46
'@shopify/theme-check-common': minor
---

Cache liquidDoc fetch results
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this comes from the upstream PR I merged in


import { LiquidDocParamNode } from '@shopify/liquid-html-parser';

export type GetSnippetDefinitionForURI = (
Copy link
Contributor Author

@jamesmengo jamesmengo Jan 22, 2025

Choose a reason for hiding this comment

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

I'm placing the types within its own module since this follows the pattern we're using for translations - link

This keeps everything self-contained while it's still subject to change as we continue building functionality into theme check, etc.

@jamesmengo jamesmengo self-assigned this Jan 22, 2025
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.

Did basic tophatting seems good
image

Minor comments

Copy link
Contributor

@karreiro karreiro left a comment

Choose a reason for hiding this comment

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

Thank you for this PR, @jamesmengo! Great stuff 🎩

I've left only two minor comments that I'd love to know your thoughts :)

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.

Looking good James 😎 Small comments, but none blocking merge

image image
  • I put a breakpoint in the memoized getLiquidDoc and looks like it's working well.

Comment on lines +14 to +15
description: string | null;
type: string | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
description: string | null;
type: string | null;
description?: string;
type?: string;

Comment on lines +38 to +39
description: node.paramDescription?.value ?? null,
type: node.paramType?.value ?? null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
description: node.paramDescription?.value ?? null,
type: node.paramType?.value ?? null,
description: node.paramDescription?.value,
type: node.paramType?.value,

@param {String} firstParam - The first param
@param {Number} secondParam - The second param
@param paramWithNoType - param with no type
@param paramWithOnlyName
Copy link
Contributor

Choose a reason for hiding this comment

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

You should also have:

  • 1 param with type but no description
  • 1 @unsupport-param
  • 1 free-form text
image

Comment on lines +13 to +24
parameters: [
{
name: 'title',
description: 'The title of the product',
type: 'string',
},
{
name: 'border-radius',
description: 'The border radius in px',
type: 'number',
},
],
Copy link
Contributor

Choose a reason for hiding this comment

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

You should add more iterations of parameters (e.g. without description, type, etc) since you have logic behind the templating around them.

See review comment above for the ones I've done during tophatting.

Add util function to read liquid doc definitions for a snippet

Implement SnippetHoverProvider

Connect SnippetHoverProvider with server

Add changeset

Provide default value for getLiquidDocDefinitionsForURI

Rename SnippetHoverProvider -> RenderSnippetHoverProvider
…wn module

----
We didn't need to use the make pattern at least at this stage, so I'm removing the code in ThemeCheckCommon and placing it in its own module.

We may need to revisit this when we are writing theme checks. However, for the purpose of hover, this is where the code should live.
…clarity

- Renamed `GetLiquidDocDefinitionsForURI` to `GetSnippetDefinitionForURI`
- Introduced `SnippetDefinition` type to replace `LiquidDocDefinition`, enhancing type specificity.
Copy link
Contributor

@karreiro karreiro left a comment

Choose a reason for hiding this comment

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

Thank you, @jamesmengo! LGTM and works as expected as well 🎩 :)

Copy link
Contributor Author

jamesmengo commented Jan 27, 2025

Merge activity

  • Jan 27, 12:13 PM EST: A user started a stack merge that includes this pull request via Graphite.
  • Jan 27, 12:14 PM EST: A user merged this pull request with Graphite.

@jamesmengo jamesmengo merged commit a42459e into main Jan 27, 2025
7 checks passed
@jamesmengo jamesmengo deleted the jm/param_hover branch January 27, 2025 17:14
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.

4 participants