-
Notifications
You must be signed in to change notification settings - Fork 63
Support code completion for inline snippet render arguments #1075
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
base: main
Are you sure you want to change the base?
Conversation
402e7be to
b332d3d
Compare
| function getInlineSnippetDocParams( | ||
| params: LiquidCompletionParams, | ||
| snippet: LiquidVariableLookup, | ||
| ): LiquidDocParameter[] { | ||
| const ast = params.document.ast; | ||
| if (ast instanceof Error || ast.type !== NodeTypes.Document) return []; | ||
|
|
||
| if (!snippet.name) return []; | ||
|
|
||
| let snippetNode: LiquidTagSnippet | undefined; | ||
|
|
||
| visit(ast, { | ||
| LiquidTag(node: LiquidTag) { | ||
| if ( | ||
| node.name === 'snippet' && | ||
| typeof node.markup !== 'string' && | ||
| node.markup.type === NodeTypes.VariableLookup && | ||
| node.markup.name === snippet.name | ||
| ) { | ||
| snippetNode = node as LiquidTagSnippet; | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| if (!snippetNode?.children) return []; | ||
|
|
||
| const docNode = snippetNode.children.find( | ||
| (node): node is LiquidRawTag => node.type === NodeTypes.LiquidRawTag && node.name === 'doc', | ||
| ); | ||
|
|
||
| if (!docNode) return []; | ||
|
|
||
| const paramNodes = (docNode.body.nodes as LiquidHtmlNode[]).filter( | ||
| (node): node is LiquidDocParamNode => node.type === NodeTypes.LiquidDocParamNode, | ||
| ); | ||
|
|
||
| return paramNodes.map( | ||
| (node): LiquidDocParameter => ({ | ||
| nodeType: 'param', | ||
| name: node.paramName.value, | ||
| description: node.paramDescription?.value ?? null, | ||
| type: node.paramType?.value ?? null, | ||
| required: node.required, | ||
| }), | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be worth moving this helper function into an utils file like liquidDoc since this could be a very helpful function for hovering and some theme checks like MissingRenderSnippetArguments or UnrecognizedRenderSnippetArgument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! I moved it out:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a nit comment, but overall looks good for me! Tophatting also worked as expected 👍
Argument completion suggestions should be offered while rendering an inline snippet. This commit adds this functionality by selecting and displaying arguments defined in an inline snippets doc tag
b332d3d to
50e2939
Compare
What are you adding in this PR?
While rendering an inline snippet that contains a doc tag we should be offered argument completion suggestions
Demo
render-arguments-completion-demo.mov
How to test
Pull down the branch
gh pr checkout 1075Before you deploy
changeset