-
Notifications
You must be signed in to change notification settings - Fork 32
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
Better building blocks for dealing with {% schema %}
content
#599
Conversation
- Batteries are included in `@shopify/theme-check-node` - Language server stores the information in the document manager and injects it
JSON Schema conversions of the theme-liquid-docs JSON schemas into TypeScript interfaces
0802d09
to
cbd3872
Compare
const promises = visit<SourceCodeType.JSON, Promise<void>>(jsonSchemaAst as JSONNode, { | ||
async Property(nameNode, ancestors) { | ||
if ( | ||
nameNode.key.value === 'name' && | ||
ancestors.length === ROOT_NODE_ANCESTORS_COUNT && | ||
isLiteralNode(nameNode.value) | ||
) { | ||
const name = getLiteralValue(nameNode.value); | ||
const startIndex = node.blockStartPosition.end + getLiteralLocStart(nameNode.value); | ||
const endIndex = node.blockStartPosition.end + getLiteralLocEnd(nameNode.value); |
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.
IMO this was a bit too hard just to get the "name" property of the parsed schema.
const name = validSchema.name; | ||
if (!name) return; |
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.
/** | ||
* Asynchronously get the block schema for 'blocks/${name}.liquid' | ||
* May return undefined when the theme isn't preloaded. | ||
* See {@link ThemeBlockSchema} for more information | ||
*/ | ||
getBlockSchema?: (name: string) => Promise<ThemeBlockSchema | undefined>; | ||
|
||
/** | ||
* Asynchronously get the section schema for 'section/${name}.liquid' | ||
* May return undefined when the theme isn't preloaded or if there are none. | ||
* See {@link SectionSchema} for more information | ||
*/ | ||
getSectionSchema?: (name: string) => Promise<SectionSchema | undefined>; | ||
|
||
/** | ||
* (In theme app extension mode) | ||
* Asynchronously get the block schema for 'blocks/${name}.liquid' | ||
* May return undefined when the theme isn't preloaded. | ||
* See {@link AppBlockSchema} for more information | ||
*/ | ||
getAppBlockSchema?: (name: string) => Promise<AppBlockSchema | undefined>; |
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.
The important part of the diff. New APIs that are injected into theme-check. These promises can be cached in the language server so that the result is parsed/cached/validated at most once per file version.
The result can be cached between subsequent runs if the file didn't change.
export type ValidateJSON<T extends SourceCodeType> = ( | ||
file: SourceCode<T>, | ||
export type ValidateJSON = ( | ||
uri: string, |
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.
Simplified since we only need the URI
89e7f43
to
f244557
Compare
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.
super minor things
packages/theme-check-common/src/checks/valid-schema-name/index.ts
Outdated
Show resolved
Hide resolved
f244557
to
e7b28a1
Compare
What are you adding in this PR?
getSectionSchema
andgetBlockSchema
context utils in theme checkvalidSchema
property of the returned value (when no errors happened parsing and the schema is validated by our JSON schema) is a type-safe representation of the schema.ValidSchemaName
as a proof of conceptnew.building.blocks.mp4
What's next? Any followup issues?
Before you deploy
I included a minor bump
changeset
The getBlockSchema & getSectionSchema are technically in the public API even though you don't need to provide them in theme-check-node nor to theme-language-server