Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
fc15e62
liquid-tm-grammar: replace the syntaxes submodule with a package
charlespwd Dec 1, 2026
478833d
liquid-tm-grammar: add a script that copies the grammar to its repo
charlespwd Dec 1, 2026
2a37122
liquid-tm-grammar: rewrite CONTRIBUTING.md for theme-tools
charlespwd Dec 1, 2026
ad44114
liquid-tm-grammar: build the grammar before F5 launches the extension
charlespwd Dec 1, 2026
8400691
vscode-extension: ignore the old syntaxes folder left in older clones
charlespwd Dec 1, 2026
d0b44ee
liquid-tm-grammar: pin vscode-textmate and vscode-oniguruma
charlespwd Dec 1, 2026
9f1154e
Add the grammar copy to the release steps
charlespwd Dec 1, 2026
307ed21
liquid-tm-grammar: send contributors to the theme-tools issues
charlespwd Dec 1, 2026
6ed6ac2
liquid-tm-grammar: copy only the built grammar to its repo
charlespwd Dec 1, 2026
c82552c
liquid-tm-grammar: point the package's links at theme-tools
charlespwd Dec 1, 2026
99b9a19
liquid-tm-grammar: port the build and tests to TypeScript and Vitest
charlespwd Dec 1, 2026
e409e20
liquid-tm-grammar: keep the grammar repo's .github when copying
charlespwd Dec 1, 2026
d32d1dc
liquid-tm-grammar: drop the README logo
charlespwd Dec 1, 2026
d927308
liquid-tm-grammar: compile the build with tsc and run it with node
charlespwd Dec 1, 2026
a32eb05
liquid-tm-grammar: merge `<<` keys in the YAML, as js-yaml did
charlespwd Dec 1, 2026
873360f
liquid-tm-grammar: never copy an older grammar over a newer one
charlespwd Dec 1, 2026
28bc769
Merge remote-tracking branch 'origin/main' into cpc-29/liquid-tm-gram…
charlespwd Dec 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
name: Code quality
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: true

- name: Setup pnpm
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
Expand Down Expand Up @@ -79,8 +77,6 @@ jobs:
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: true

- name: Setup pnpm
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
Expand Down Expand Up @@ -120,8 +116,6 @@ jobs:

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: true

- name: Setup pnpm
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: true
fetch-depth: 0
persist-credentials: false

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/vscode-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: true
persist-credentials: false

- name: Setup pnpm
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

8 changes: 7 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
"problemMatcher": "$ts-checker-webpack",
"dependsOn": [
"theme check build",
"language-config"
"language-config",
"liquid grammar"
],
},
{
"label": "liquid grammar",
"type": "shell",
"command": "pnpm --filter @shopify/liquid-tm-grammar build"
},
{
"label": "language-config",
"type": "shell",
Expand Down
10 changes: 9 additions & 1 deletion docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@

1. Merge the `Theme-Tools Release — YYYY-MM-DD` PR

2. Done!
2. If the release changes the version of `@shopify/liquid-tm-grammar`, copy the grammar to [Shopify/liquid-tm-grammar](https://github.com/Shopify/liquid-tm-grammar). GitHub Linguist highlights Liquid with that copy. From an up-to-date `main`:

```bash
packages/liquid-tm-grammar/scripts/copy-to-liquid-tm-grammar.sh
```

It opens a pull request on Shopify/liquid-tm-grammar. Merge it.

3. Done!

## Upgrading projects that depend on this

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"packages/lang-*",
"packages/codemirror-language-client",
"packages/liquid-html-parser",
"packages/liquid-tm-grammar",
"packages/prettier-plugin-liquid",
"packages/theme-check-*",
"packages/theme-graph",
Expand Down
122 changes: 122 additions & 0 deletions packages/liquid-tm-grammar/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
This document explains how to change the Liquid syntax highlighting grammar and see the effect of your changes.

* [Where the grammar lives](#where-the-grammar-lives)
* [Overview](#overview)
* [Testing in Visual Studio Code](#testing-in-visual-studio-code)
* [Setup](#setup)
* [Visual development](#visual-development)
* [Unit Testing](#unit-testing)
* [Helpful Resources](#helpful-resources)

## Where the grammar lives

The source of the grammar is [`packages/liquid-tm-grammar`](https://github.com/Shopify/theme-tools/tree/main/packages/liquid-tm-grammar) in [Shopify/theme-tools](https://github.com/Shopify/theme-tools). The Shopify Liquid VS Code extension in that repository bundles it.

[Shopify/liquid-tm-grammar](https://github.com/Shopify/liquid-tm-grammar) keeps the built grammar that GitHub Linguist uses, and is updated after Theme Tools releases a new version of it. Shopify/theme-tools is a read-only mirror of Shopify's monorepo, so report a bug or ask for a change in its [issues](https://github.com/Shopify/theme-tools/issues). The steps below build and test the grammar in a clone of Shopify/theme-tools.

## Overview

Much like [microsoft/TypeScript-TmLanguage](https://github.com/microsoft/TypeScript-TmLanguage), the `.tmLanguage` files are maintained in [YAML](https://yaml.org/) to make them easier to consume and edit by humans.

The `grammars/*.tmLanguage.json` files are _generated_ by the build from the YAML files and are _not_ maintained manually. Commit them with the YAML change that produced them.

| Path | What it holds |
| --- | --- |
| `base-syntax.yml`, `liquid.yml`, `liquid-injection.yml`, `liquid/*.yml` | The grammar's source |
| `src/build.ts` | The build, which turns the YAML into `grammars/*.tmLanguage.json` |
| `grammars/` | The built grammars. The VS Code extension bundles them, and GitHub Linguist reads them from Shopify/liquid-tm-grammar. |
| `tests/` | The test cases, their baselines, and the grammars of the languages that Liquid embeds |

## Testing in Visual Studio Code

### Setup

Visual Studio Code only lets you debug _extensions_, so you test the grammar with the VS Code extension in Shopify/theme-tools.

1. Clone [Shopify/theme-tools](https://github.com/Shopify/theme-tools):

```sh
git clone https://github.com/Shopify/theme-tools.git
```

2. Install the dependencies and build the packages, at the root of the clone:

```sh
cd theme-tools
pnpm install
pnpm build
```

### Visual development

1. Open the `theme-tools` folder in VS Code.

2. Press `F5` (or Run > Start Debugging), with the `Debug Node Extension` launch configuration.

Its build turns the grammar's YAML into `packages/liquid-tm-grammar/grammars/*.tmLanguage.json`, then copies those files into the extension's `dist/grammars`.

3. In the `[Extension Development Host]` window, open the `packages/liquid-tm-grammar/tests/cases` folder. Open any `*.liquid` file.

4. In the other window, change any of the grammar's YAML files.

5. Restart the debug session (`⇧⌘F5`, or Run > Restart Debugging), so that the build runs again.

You should see the result of your changes in the `[Extension Development Host]` window.

6. Repeat steps 4 and 5 until satisfied.

It is highly recommended you setup [VS Code's Scope inspector](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#scope-inspector). This will greatly help you debug your changes.

### Unit Testing

The tests follow the baseline workflow of [microsoft/TypeScript-TmLanguage](https://github.com/microsoft/TypeScript-TmLanguage). Each file in `tests/cases` has a baseline in `tests/baselines` that lists every token of the file and its scopes. The tests tokenize each case with the built grammar and compare the result with its baseline. They also check that `grammars/*.tmLanguage.json` matches the YAML.

Run these commands at the root of `theme-tools`.

1. Make changes to any of the YAML files.

2. Build the JSON files and run the tests:

```sh
pnpm --filter @shopify/liquid-tm-grammar build
pnpm vitest packages/liquid-tm-grammar
```

Vitest prints the difference between each changed result and its baseline.

3. Repeat steps 1 and 2 until satisfied.

4. Accept the new results as the baselines, and commit them with the JSON files:

```sh
pnpm vitest run packages/liquid-tm-grammar -u
git add packages/liquid-tm-grammar/tests/baselines packages/liquid-tm-grammar/grammars
```

5. Add a changeset for `@shopify/liquid-tm-grammar` and `theme-check-vscode` that describes the highlighting change, so that the next release ships it:

```sh
pnpm changeset add
```

To add a test, add a `*.liquid` file to `packages/liquid-tm-grammar/tests/cases` and run the tests. Vitest writes the new case's baseline. Check it before you commit it. In CI, a case without a baseline fails.

## Helpful Resources

- [Official documentation on TextMate language grammars](https://macromates.com/manual/en/language_grammars#naming_conventions)

For when you want to learn more about what the fields are and how they work. You should take an afternoon reading this entire page and taking notes. This is going to go a long way.

- [List of convention for scope names](https://www.sublimetext.com/docs/scope_naming.html)

Don't know what `name` to give to a token so that it gets highlighted properly by default themes? This reference should guide you.

- [Visual Studio Code Syntax Highlighting Guide](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide)

* [Scope Inspector Documentation](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#scope-inspector)

This section is particularly helpful when you want to debug interactively and see the result of your changes.

- [Official documentation on TextMate scope selectors](https://macromates.com/manual/en/language_grammars#naming_conventions)

For when you want to understand styling. It's a bit less important.
8 changes: 8 additions & 0 deletions packages/liquid-tm-grammar/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

Copyright 2022-present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 changes: 25 additions & 0 deletions packages/liquid-tm-grammar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Shopify Liquid TextMate Grammar

This package contains the official syntax highlighting rules for the [Shopify flavor of Liquid](https://shopify.dev/themes).

[Features](#features) | [Development](#development) | [Credits](#credits)

## Features

- 🎨 TextMate grammar (.tmLanguage) for Liquid that works in the following contexts:
- ✅ [Visual Studio Code](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#textmate-grammars)
- ✅ [Atom Editor](https://flight-manual.atom.io/hacking-atom/sections/creating-a-legacy-textmate-grammar/)
- ✅ [Sublime Text](https://www.sublimetext.com/docs/scope_naming.html)
- ✅ [GitHub.com](https://github.com/GitHub/linguist)
- 💧 Multi-lingual support:
- ✅ Liquid in HTML
- ✅ Liquid in JavaScript
- ✅ Liquid in CSS

## Development

See [CONTRIBUTING.md](./CONTRIBUTING.md).

## Credits

- The initial version of the syntax comes from [siteleaf/liquid-syntax-mode](https://github.com/siteleaf/liquid-syntax-mode)
59 changes: 59 additions & 0 deletions packages/liquid-tm-grammar/ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
THIRD-PARTY SOFTWARE NOTICES AND INFORMATION

The latest Liquid Grammar incorporates third party material from the projects listed below. The original copyright notice and the license under which Shopify received such third party material are set forth below. Shopify reserves all other rights not expressly granted, whether by implication, estoppel or otherwise.

1. TypeScript-TmLanguage (https://github.com/microsoft/TypeScript-TmLanguage)
2. vscode (https://github.com/microsoft/vscode)

%% TypeScript-TmLanguage NOTICES, INFORMATION, AND LICENSE BEGIN HERE
=========================================
Copyright (c) Microsoft Corporation
All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF TypeScript-TmLanguage NOTICES, INFORMATION, AND LICENSE

%% vscode NOTICES, INFORMATION, AND LICENSE BEGIN HERE
=========================================
MIT License

Copyright (c) 2015 - present Microsoft Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF vscode NOTICES, INFORMATION, AND LICENSE
Loading