Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Shopify/theme-tools
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: @shopify/prettier-plugin-liquid@1.6.0
Choose a base ref
...
head repository: Shopify/theme-tools
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: @shopify/prettier-plugin-liquid@1.6.1
Choose a head ref

Commits on Nov 11, 2024

  1. Check for block targeting

    navdeep5 committed Nov 11, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    renovate-bot Mend Renovate
    Copy the full SHA
    3f7680e View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    36cf1b9 View commit details
  3. Remove extra import

    navdeep5 committed Nov 11, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    142036a View commit details
  4. Syntax fix

    navdeep5 committed Nov 11, 2024
    Copy the full SHA
    e65cb0c View commit details
  5. Update check order to be alphabetical

    navdeep5 committed Nov 11, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    7adbdbc View commit details

Commits on Nov 12, 2024

  1. Add ValidLocalBlocks Check

    navdeep5 committed Nov 12, 2024
    Copy the full SHA
    8a0bf78 View commit details
  2. Remove local block validation

    navdeep5 committed Nov 12, 2024
    Copy the full SHA
    697bdd5 View commit details

Commits on Nov 13, 2024

  1. Preload theme on boot with progress (#585)

    We'll do more stuff like the `{Snippet,Asset}RenameHandler`. We don't
    want those operations to feel slow.
    
    So as soon as we open a text document in a theme, we'll preload all the
    files in it.
    
    - Added new helpers in DocumentManager to handle create,delete,rename
    correctly and prevent requiring preload invalidation.
    
    - Added a `Progress` class to help with progress bars. The LSP stuff
      feels very heavy and that class makes it a bit cuter/less disruptive
      in the code. Still gotta do percent calculations (which sucks), but
      with a couple of comments it ain't so bad.
    
    - Running theme check _after_ the rename handler completes so that we no
      longer have a race condition that makes it so the file appears to not
      be there when it is.
    
    Performance wise:
    - We'll cache the preload a theme is only preloaded once (once per theme root URI)
    charlespwd authored Nov 13, 2024
    Copy the full SHA
    f09c923 View commit details
  2. Verify schema name translation

    miazbikowski committed Nov 13, 2024
    Copy the full SHA
    7317830 View commit details
  3. Gate the "preload" functionality behind themeCheck.preloadOnBoot in…

    …itialization option (#589)
    
    We probably don't want to preload all the files just yet.
    
    We can now start the `CodeMirrorLanguageClient` with the following to disable full theme preload on theme file open.
    
    ```
    const client = new CodeMirrorLanguageClient(worker, {
      initializationOptions: {
        'themeCheck.preloadOnBoot': false,
      }
    });
    ```
    charlespwd authored Nov 13, 2024
    Copy the full SHA
    0b7534b View commit details
  4. [Bug] Fix metafield definition to use key (#591)

    aswamy authored Nov 13, 2024
    Copy the full SHA
    9a07208 View commit details
  5. Remove @theme check and adjust name squiggly

    navdeep5 committed Nov 13, 2024
    Copy the full SHA
    fe52cd7 View commit details

Commits on Nov 14, 2024

  1. Fix hardcoded file: scheme in resolveConfig (#588)

    I think it should have been `file://` and is probably the cause of #586.
    
    Can't confirm this fixes it because I couldn't figure out a way to
    reproduce the issue reported. But given that I know it should have been
    `file://`, let's see if that fixes it.
    
    Fixes #586
    charlespwd authored Nov 14, 2024
    Copy the full SHA
    7a6dfe8 View commit details
  2. Support preset blocks as a hash

    navdeep5 committed Nov 14, 2024
    Copy the full SHA
    d7d77fe View commit details
  3. Support preset blocks as a hash

    navdeep5 committed Nov 14, 2024
    Copy the full SHA
    ddca7dc View commit details
  4. Refactor to make deepGet a util and use

    miazbikowski committed Nov 14, 2024
    Copy the full SHA
    753f286 View commit details
  5. Merge pull request #584 from Shopify/miaz/valid-schema-name-trans

    Verify schema name translation
    miazbikowski authored Nov 14, 2024
    Copy the full SHA
    c9ae6e8 View commit details
  6. Nit and @app fix

    navdeep5 committed Nov 14, 2024
    Copy the full SHA
    97366b0 View commit details

Commits on Nov 15, 2024

  1. Simplify CaptureOnContentForBlock & make it fail when nested (#596)

    charlespwd authored Nov 15, 2024
    Copy the full SHA
    b558bfe View commit details
  2. Warn against block.id usage

    miazbikowski committed Nov 15, 2024
    Copy the full SHA
    c4813ff View commit details

Commits on Nov 18, 2024

  1. Merge pull request #561 from Shopify/navdeep-block-targetting

    Check for Valid Block Targeting
    navdeep5 authored Nov 18, 2024
    Copy the full SHA
    be00b52 View commit details
  2. Merge pull request #587 from Shopify/navdeep-static-local-blocks

    Add ValidLocalBlocks Check
    navdeep5 authored Nov 18, 2024
    Copy the full SHA
    c383f62 View commit details
  3. Merge pull request #595 from Shopify/miaz/warn-block-id-usage

    Warn against block.id usage
    miazbikowski authored Nov 18, 2024
    Copy the full SHA
    498f48f View commit details
  4. Better building blocks for dealing with {% schema %} content (#599)

    * Add `getSectionSchema` and `getBlockSchema` context utils in theme check
    
    - Batteries are included in `@shopify/theme-check-node`
    - Language server stores the information in the document manager and injects it
    
    * Add {ThemeBlock,Section}.Schema TypeScript types
    
    JSON Schema conversions of the theme-liquid-docs JSON schemas into
    TypeScript interfaces
    
    * Provide better building blocks for dealing with schemas
    
    Fixes #572
    charlespwd authored Nov 18, 2024
    Copy the full SHA
    add2445 View commit details

Commits on Nov 19, 2024

  1. Theme Tools Release: 19-11-24 (#603)

    * Update changesets
    
    * Release 19-11-24: Updated 11 package versions
    
    @shopify/prettier-plugin-liquid: 1.6.0 -> 1.6.1 (patch)
    @shopify/theme-check-common: 3.1.0 -> 3.2.0 (minor)
    @shopify/theme-check-node: 3.1.0 -> 3.2.0 (minor)
    theme-check-vscode: 3.1.0 -> 3.2.0 (minor)
    @shopify/theme-language-server-common: 2.1.0 -> 2.2.0 (minor)
    @shopify/liquid-html-parser: 2.1.0 -> 2.1.1 (patch)
    @shopify/codemirror-language-client: 0.7.0 -> 0.7.1 (patch)
    @shopify/theme-check-docs-updater: 3.1.0 -> 3.2.0 (minor)
    @shopify/theme-check-browser: 3.1.0 -> 3.2.0 (minor)
    @shopify/theme-language-server-browser: 2.1.0 -> 2.2.0 (minor)
    @shopify/theme-language-server-node: 2.1.0 -> 2.2.0 (minor)
    charlespwd authored Nov 19, 2024
    Copy the full SHA
    49d3d4b View commit details
Showing with 3,497 additions and 408 deletions.
  1. +6 −0 packages/codemirror-language-client/CHANGELOG.md
  2. +3 −3 packages/codemirror-language-client/package.json
  3. +17 −2 packages/codemirror-language-client/playground/src/playground.ts
  4. +2 −1 packages/codemirror-language-client/src/CodeMirrorLanguageClient.ts
  5. +4 −0 packages/codemirror-language-client/src/LanguageClient.ts
  6. +6 −0 packages/liquid-html-parser/CHANGELOG.md
  7. +1 −1 packages/liquid-html-parser/package.json
  8. +2 −2 packages/liquid-html-parser/src/stage-2-ast.ts
  9. +8 −0 packages/prettier-plugin-liquid/CHANGELOG.md
  10. +2 −2 packages/prettier-plugin-liquid/package.json
  11. +15 −0 packages/theme-check-browser/CHANGELOG.md
  12. +2 −2 packages/theme-check-browser/package.json
  13. +19 −0 packages/theme-check-common/CHANGELOG.md
  14. +2 −2 packages/theme-check-common/package.json
  15. +37 −9 packages/theme-check-common/src/JSONValidator.ts
  16. +76 −0 packages/theme-check-common/src/checks/block-id-usage/index.spec.ts
  17. +72 −0 packages/theme-check-common/src/checks/block-id-usage/index.ts
  18. +19 −0 packages/theme-check-common/src/checks/capture-on-content-for-block/index.spec.ts
  19. +15 −38 packages/theme-check-common/src/checks/capture-on-content-for-block/index.ts
  20. +7 −0 packages/theme-check-common/src/checks/index.ts
  21. +88 −0 packages/theme-check-common/src/checks/valid-block-target/block-utils.ts
  22. +484 −0 packages/theme-check-common/src/checks/valid-block-target/index.spec.ts
  23. +94 −0 packages/theme-check-common/src/checks/valid-block-target/index.ts
  24. +1 −1 packages/theme-check-common/src/checks/valid-json/index.ts
  25. +331 −0 packages/theme-check-common/src/checks/valid-local-blocks/index.spec.ts
  26. +89 −0 packages/theme-check-common/src/checks/valid-local-blocks/index.ts
  27. +106 −0 packages/theme-check-common/src/checks/valid-local-blocks/valid-block-utils.ts
  28. +86 −2 packages/theme-check-common/src/checks/valid-schema-name/index.spec.ts
  29. +58 −51 packages/theme-check-common/src/checks/valid-schema-name/index.ts
  30. +1 −1 packages/theme-check-common/src/checks/valid-schema/index.ts
  31. +2 −0 packages/theme-check-common/src/context-utils.spec.ts
  32. +1 −0 packages/theme-check-common/src/context-utils.ts
  33. +3 −0 packages/theme-check-common/src/find-root.ts
  34. +7 −10 packages/theme-check-common/src/index.ts
  35. +29 −1 packages/theme-check-common/src/json.ts
  36. +22 −18 packages/theme-check-common/src/path.ts
  37. +2 −5 packages/theme-check-common/src/test/MockFileSystem.ts
  38. +37 −9 packages/theme-check-common/src/test/test-helper.ts
  39. +150 −0 packages/theme-check-common/src/to-schema.ts
  40. +38 −3 packages/theme-check-common/src/types.ts
  41. +3 −0 packages/theme-check-common/src/types/schemas/index.ts
  42. +107 −0 packages/theme-check-common/src/types/schemas/section.ts
  43. +320 −0 packages/theme-check-common/src/types/schemas/setting.ts
  44. +68 −0 packages/theme-check-common/src/types/schemas/theme-block.ts
  45. +65 −0 packages/theme-check-common/src/types/theme-schemas.ts
  46. +1 −0 packages/theme-check-common/src/utils/index.ts
  47. +1 −4 packages/theme-check-common/src/utils/memo.ts
  48. +3 −0 packages/theme-check-common/src/utils/object.ts
  49. +16 −0 packages/theme-check-docs-updater/CHANGELOG.md
  50. +2 −2 packages/theme-check-docs-updater/package.json
  51. +1 −46 packages/theme-check-docs-updater/src/utils.ts
  52. +24 −0 packages/theme-check-node/CHANGELOG.md
  53. +9 −0 packages/theme-check-node/configs/all.yml
  54. +9 −0 packages/theme-check-node/configs/recommended.yml
  55. +3 −3 packages/theme-check-node/package.json
  56. +13 −5 packages/theme-check-node/src/config/load-config-description.ts
  57. +20 −2 packages/theme-check-node/src/config/load-config.spec.ts
  58. +56 −0 packages/theme-check-node/src/index.ts
  59. 0 packages/theme-check-node/src/path.ts
  60. +10 −0 packages/theme-language-server-browser/CHANGELOG.md
  61. +2 −2 packages/theme-language-server-browser/package.json
  62. +29 −0 packages/theme-language-server-common/CHANGELOG.md
  63. +3 −3 packages/theme-language-server-common/package.json
  64. +4 −0 packages/theme-language-server-common/src/ClientCapabilities.ts
  65. +5 −1 packages/theme-language-server-common/src/TypeSystem.spec.ts
  66. +1 −1 packages/theme-language-server-common/src/TypeSystem.ts
  67. +1 −2 packages/theme-language-server-common/src/completions/params/LiquidCompletionParams.spec.ts
  68. +1 −0 packages/theme-language-server-common/src/completions/providers/ObjectCompletionProvider.spec.ts
  69. +30 −3 packages/theme-language-server-common/src/diagnostics/runChecks.ts
  70. +226 −31 packages/theme-language-server-common/src/documents/DocumentManager.spec.ts
  71. +112 −41 packages/theme-language-server-common/src/documents/DocumentManager.ts
  72. +2 −6 packages/theme-language-server-common/src/documents/index.ts
  73. +41 −0 packages/theme-language-server-common/src/documents/types.ts
  74. +1 −0 packages/theme-language-server-common/src/hover/providers/LiquidObjectHoverProvider.spec.ts
  75. +38 −0 packages/theme-language-server-common/src/json/JSONLanguageService.spec.ts
  76. +12 −4 packages/theme-language-server-common/src/json/JSONLanguageService.ts
  77. +83 −0 packages/theme-language-server-common/src/progress.ts
  78. +1 −2 packages/theme-language-server-common/src/renamed/BaseRenameHandler.ts
  79. +12 −10 packages/theme-language-server-common/src/renamed/RenameHandler.ts
  80. +6 −4 packages/theme-language-server-common/src/renamed/handlers/AssetRenameHandler.spec.ts
  81. +16 −6 packages/theme-language-server-common/src/renamed/handlers/AssetRenameHandler.ts
  82. +5 −3 packages/theme-language-server-common/src/renamed/handlers/SnippetRenameHandler.spec.ts
  83. +17 −7 packages/theme-language-server-common/src/renamed/handlers/SnippetRenameHandler.ts
  84. +14 −1 packages/theme-language-server-common/src/server/Configuration.ts
  85. +20 −14 packages/theme-language-server-common/src/server/startServer.spec.ts
  86. +76 −26 packages/theme-language-server-common/src/server/startServer.ts
  87. +6 −5 packages/theme-language-server-common/src/test/MockConnection.ts
  88. +17 −0 packages/theme-language-server-node/CHANGELOG.md
  89. +4 −4 packages/theme-language-server-node/package.json
  90. +30 −0 packages/vscode-extension/CHANGELOG.md
  91. +7 −7 packages/vscode-extension/package.json
6 changes: 6 additions & 0 deletions packages/codemirror-language-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @shopify/codemirror-language-client

## 0.7.1

### Patch Changes

- 0b7534b: Add way to pass LSP initialization options to the server with the initialize request

## 0.7.0

### Minor Changes
6 changes: 3 additions & 3 deletions packages/codemirror-language-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shopify/codemirror-language-client",
"version": "0.7.0",
"version": "0.7.1",
"description": "A Language Client for CodeMirror",
"author": "CP Clermont <cp.clermont@shopify.com>",
"homepage": "https://github.com/Shopify/theme-tools/tree/main/packages/codemirror-language-client#readme",
@@ -51,8 +51,8 @@
"@codemirror/theme-one-dark": "^6.1.2",
"@codemirror/view": "^6.9.2",
"@replit/codemirror-vim": "^6.2.1",
"@shopify/theme-check-docs-updater": "^3.0.0",
"@shopify/theme-language-server-browser": "^2.0.0",
"@shopify/theme-check-docs-updater": "^3.2.0",
"@shopify/theme-language-server-browser": "^2.2.0",
"@shopify/lang-jsonc": "^1.0.0",
"@types/markdown-it": "^13.0.4",
"codemirror": "^6.0.1",
19 changes: 17 additions & 2 deletions packages/codemirror-language-client/playground/src/playground.ts
Original file line number Diff line number Diff line change
@@ -88,7 +88,11 @@ async function main() {

const client = new CodeMirrorLanguageClient(
worker,
{},
{
initializationOptions: {
'themeCheck.preloadOnBoot': false,
},
},
{
autocompleteOptions: {
activateOnTyping: true,
@@ -125,16 +129,24 @@ async function main() {
return JSON.stringify(exampleTranslations, null, 2);
case 'browser:/locales/en.default.schema.json':
return JSON.stringify(exampleSchemaTranslations, null, 2);
case 'browser:/snippets/article-card.liquid':
case 'browser:/snippets/product-card.liquid':
case 'browser:/snippets/product.liquid':
return '';
default:
throw new Error(`File does not exist ${uri}`);
}
});

client.client.onRequest('fs/stat' as any, ([uri]: string) => {
switch (uri) {
case 'browser:/sections/section.liquid':
case 'browser:/.theme-check.yml':
case 'browser:/locales/en.default.json':
case 'browser:/locales/en.schema.default.json':
case 'browser:/sections/section.liquid':
case 'browser:/snippets/article-card.liquid':
case 'browser:/snippets/product-card.liquid':
case 'browser:/snippets/product.liquid':
return { fileType: 1, size: 1 };
default:
throw new Error(`File does not exist: ${uri}`);
@@ -151,6 +163,9 @@ async function main() {
['browser:/.theme-check.yml', 1],
];
}
case 'browser:/sections': {
return [['browser:/sections/section.liquid', 1]];
}
case 'browser:/snippets': {
return [
['browser:/snippets/article-card.liquid', 1],
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ export class CodeMirrorLanguageClient {

constructor(
private readonly worker: Worker,
{ log = defaultLogger }: ClientDependencies = {},
{ log = defaultLogger, initializationOptions }: ClientDependencies = {},
{
infoRenderer,
autocompleteOptions,
@@ -126,6 +126,7 @@ export class CodeMirrorLanguageClient {
) {
this.client = new LanguageClient(worker, {
clientCapabilities,
initializationOptions,
log,
});
this.worker = worker;
4 changes: 4 additions & 0 deletions packages/codemirror-language-client/src/LanguageClient.ts
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ export interface PromiseCompletion {

export interface Dependencies {
clientCapabilities: ClientCapabilities;
initializationOptions?: any;
log(...args: any[]): void;
}

@@ -48,6 +49,7 @@ export interface AbstractLanguageClient {

export class LanguageClient extends EventTarget implements AbstractLanguageClient {
public readonly clientCapabilities: ClientCapabilities;
public readonly initializationOptions: any;
public serverCapabilities: ServerCapabilities | null;
public serverInfo: any;

@@ -64,6 +66,7 @@ export class LanguageClient extends EventTarget implements AbstractLanguageClien
this.dispose = () => {};
this.disposables = [];
this.clientCapabilities = dependencies.clientCapabilities;
this.initializationOptions = dependencies.initializationOptions;
this.log = dependencies.log;
this.serverCapabilities = null;
this.serverInfo = null;
@@ -91,6 +94,7 @@ export class LanguageClient extends EventTarget implements AbstractLanguageClien
*/
const response = await this.sendRequest(InitializeRequest.type, {
capabilities: this.clientCapabilities,
initializationOptions: this.initializationOptions,
processId: 0,
rootUri: 'browser:///',
});
6 changes: 6 additions & 0 deletions packages/liquid-html-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @shopify/liquid-html-parser

## 2.1.1

### Patch Changes

- c4813ff: Fix LiquidComparison types

## 2.1.0

### Minor Changes
2 changes: 1 addition & 1 deletion packages/liquid-html-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shopify/liquid-html-parser",
"version": "2.1.0",
"version": "2.1.1",
"description": "Liquid HTML parser by Shopify",
"author": "CP Clermont <cp.clermont@shopify.com>",
"homepage": "https://github.com/Shopify/theme-tools/tree/main/packages/liquid-html-parser#readme",
4 changes: 2 additions & 2 deletions packages/liquid-html-parser/src/stage-2-ast.ts
Original file line number Diff line number Diff line change
@@ -345,8 +345,8 @@ export interface LiquidLogicalExpression extends ASTNode<NodeTypes.LogicalExpres
/** Represents `left (<|<=|=|>=|>|contains) right` conditional expressions */
export interface LiquidComparison extends ASTNode<NodeTypes.Comparison> {
comparator: Comparators;
left: LiquidConditionalExpression;
right: LiquidConditionalExpression;
left: LiquidExpression;
right: LiquidExpression;
}

/** https://shopify.dev/docs/api/liquid/tags#paginate */
8 changes: 8 additions & 0 deletions packages/prettier-plugin-liquid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @shopify/prettier-plugin-liquid

## 1.6.1

### Patch Changes

- Patch bump because it depends on @shopify/liquid-html-parser
- Updated dependencies [c4813ff]
- @shopify/liquid-html-parser@2.1.1

## 1.6.0

### Minor Changes
4 changes: 2 additions & 2 deletions packages/prettier-plugin-liquid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shopify/prettier-plugin-liquid",
"version": "1.6.0",
"version": "1.6.1",
"description": "Prettier Liquid/HTML plugin by Shopify",
"author": "CP Clermont <cp.clermont@shopify.com>",
"homepage": "https://github.com/Shopify/theme-tools/tree/main/packages/prettier-plugin-liquid#readme",
@@ -59,7 +59,7 @@
"tsconfig-paths": "^3.14.1"
},
"dependencies": {
"@shopify/liquid-html-parser": "^2.1.0",
"@shopify/liquid-html-parser": "^2.1.1",
"html-styles": "^1.0.0"
}
}
15 changes: 15 additions & 0 deletions packages/theme-check-browser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# @shopify/theme-check-browser

## 3.2.0

### Patch Changes

- Updated dependencies [3f7680e]
- Updated dependencies [add2445]
- Updated dependencies [8a0bf78]
- Updated dependencies [7a6dfe8]
- Updated dependencies [7317830]
- Updated dependencies [c4813ff]
- Updated dependencies [b558bfe]
- Updated dependencies [9a07208]
- Updated dependencies [f09c923]
- @shopify/theme-check-common@3.2.0

## 3.1.0

### Minor Changes
4 changes: 2 additions & 2 deletions packages/theme-check-browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shopify/theme-check-browser",
"version": "3.1.0",
"version": "3.2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
@@ -26,6 +26,6 @@
"type-check": "tsc --noEmit"
},
"dependencies": {
"@shopify/theme-check-common": "3.1.0"
"@shopify/theme-check-common": "3.2.0"
}
}
19 changes: 19 additions & 0 deletions packages/theme-check-common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# @shopify/theme-check-common

## 3.2.0

### Minor Changes

- 3f7680e: Add the `ValidBlockTarget` Check
- 8a0bf78: Add the `ValidLocalBlocks` Check
- c4813ff: Add the `BlockIdUsage` check
- 7317830: Add translation checking to `ValidSchemaName` check
- add2445: [Internal] Add better building blocks for dealing with `{% schema %}` content

### Patch Changes

- 7a6dfe8: Fix weird root URI loading bug
- b558bfe: Fixup `CaptureOnContentForBlock` check
- 9a07208: [Bug fix] Metafield definitions should use `namespace.key` for auto-completion
- f09c923: Moving internal methods around
- Updated dependencies [c4813ff]
- @shopify/liquid-html-parser@2.1.1

## 3.1.0

### Minor Changes
4 changes: 2 additions & 2 deletions packages/theme-check-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shopify/theme-check-common",
"version": "3.1.0",
"version": "3.2.0",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -26,7 +26,7 @@
"type-check": "tsc --noEmit"
},
"dependencies": {
"@shopify/liquid-html-parser": "2.1.0",
"@shopify/liquid-html-parser": "2.1.1",
"cross-fetch": "^4.0.0",
"json-to-ast": "^2.1.0",
"jsonc-parser": "^3.2.0",
46 changes: 37 additions & 9 deletions packages/theme-check-common/src/JSONValidator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { LanguageService, TextDocument, getLanguageService } from 'vscode-json-languageservice';
import { SchemaDefinition, SourceCodeType, ValidateJSON } from './types';
import { Config, Dependencies, IsValidSchema, SchemaDefinition, ValidateJSON } from './types';
import { indexBy } from './utils';

export class JSONValidator {
private service: LanguageService;
private schemas: Record<string, SchemaDefinition>;

static async create(
jsonValidationSet: Dependencies['jsonValidationSet'],
config: Config,
): Promise<JSONValidator | undefined> {
if (!jsonValidationSet) return;
return new JSONValidator(await jsonValidationSet.schemas(config.context));
}

constructor(schemas: SchemaDefinition[]) {
this.schemas = indexBy((x) => x.uri, schemas);
this.service = getLanguageService({
@@ -31,24 +39,44 @@ export class JSONValidator {
* It's up to the caller to determine where in the file those should be.
* (presumably by doing some offset logic)
*/
public validate: ValidateJSON<SourceCodeType> = async (sourceCode, jsonString) => {
const jsonTextDocument = TextDocument.create('file:' + sourceCode.uri, 'json', 0, jsonString);
const jsonDocument = this.service.parseJSONDocument(jsonTextDocument);
const diagnostics = await this.service.doValidation(jsonTextDocument, jsonDocument, {
schemaValidation: 'error',
trailingCommas: 'ignore',
comments: 'ignore',
});
public validate: ValidateJSON = async (uri: string, jsonString: string) => {
const jsonTextDocument = TextDocument.create(uri, 'json', 0, jsonString);
const diagnostics = await this.getOffsetDiagnostics(jsonTextDocument);
return diagnostics.map((diagnostic) => ({
message: diagnostic.message,
startIndex: jsonTextDocument.offsetAt(diagnostic.range.start),
endIndex: jsonTextDocument.offsetAt(diagnostic.range.end),
}));
};

public isValid: IsValidSchema = async (uri: string, jsonString: string) => {
return isValid(this.service, uri, jsonString);
};

private async getOffsetDiagnostics(jsonTextDocument: TextDocument) {
const jsonDocument = this.service.parseJSONDocument(jsonTextDocument);
return this.service.doValidation(jsonTextDocument, jsonDocument, {
schemaValidation: 'error',
trailingCommas: 'ignore',
comments: 'ignore',
});
}

private async getSchemaForURI(uri: string): Promise<string> {
const schema = this.schemas[uri]?.schema;
if (!schema) return `No schema for '${uri}' found`;
return schema;
}
}

/** We'll reuse this in the language server */
export async function isValid(service: LanguageService, uri: string, jsonString: string) {
const jsonTextDocument = TextDocument.create(uri, 'json', 0, jsonString);
const jsonDocument = service.parseJSONDocument(jsonTextDocument);
const diagnostics = await service.doValidation(jsonTextDocument, jsonDocument, {
schemaValidation: 'error',
trailingCommas: 'ignore',
comments: 'ignore',
});
return diagnostics.every((diagnostic) => diagnostic.severity !== 1);
}
Loading