VS Code TextMate Grammar Updater
The `vscode-grammar-updater` package is a specialized utility designed by Microsoft to manage and synchronize TextMate grammars within Visual Studio Code language extensions. Its primary function is to update grammar definitions from their source repositories, ensuring that syntax highlighting and other language features in VS Code extensions remain current. The current stable version is 1.1.0, published approximately four years ago, indicating a maintenance-focused development cycle tied closely to VS Code's internal needs rather than an independent, rapid release schedule. This tool is a key differentiator for VS Code extension developers, providing a built-in mechanism for integrating external TextMate grammar updates directly into the extension ecosystem, which might otherwise require manual, error-prone synchronization processes.
Common errors
-
'vscode-grammar-updater' command not found
cause The package is installed locally as a `devDependency` and not globally, or `npm`'s `bin` path is not in the system's PATH.fixIf used in an `npm` script (e.g., `"update": "vscode-grammar-updater ..."`), ensure the `npm install` command has been run. If trying to execute directly from the terminal, use `npx vscode-grammar-updater ...` or install globally via `npm install -g vscode-grammar-updater`. -
Failed to fetch grammar from 'https://github.com/...' (or similar network error)
cause Network connectivity issues, proxy problems, or rate limiting from the remote Git host.fixCheck your internet connection, verify proxy settings if applicable (e.g., `HTTP_PROXY`, `HTTPS_PROXY` environment variables), and ensure you're not hitting API rate limits on the source repository's hosting platform (e.g., GitHub).
Warnings
- gotcha The package's primary mode of operation appears to be CLI-driven, often integrated into `npm` scripts, rather than direct programmatic import. Comprehensive API documentation for programmatic use is limited.
- gotcha The package was last published over four years ago (May 18, 2022). While it's maintained by Microsoft for internal VS Code processes, external consumers should be aware of the infrequent updates and potential for outdated internal dependencies.
- gotcha This utility requires network access to fetch grammars from their source repositories (e.g., GitHub). Ensure the execution environment has appropriate network connectivity and permissions.
- gotcha The exact command-line arguments and their behavior might not be fully documented for external users. Inspection of the source code or usage in other VS Code repositories might be necessary to understand all available options.
Install
-
npm install vscode-grammar-updater -
yarn add vscode-grammar-updater -
pnpm add vscode-grammar-updater
Imports
- updateGrammars
const { updateGrammars } = require('vscode-grammar-updater');import { updateGrammars } from 'vscode-grammar-updater'; - GrammarUpdateOptions
import type { GrammarUpdateOptions } from 'vscode-grammar-updater';
Quickstart
{
"name": "my-vscode-extension",
"version": "0.0.1",
"description": "My VS Code language extension with a custom grammar.",
"scripts": {
"update-grammar": "vscode-grammar-updater --sourceRepoUrl https://github.com/my-org/my-lang-grammar --targetFilePath ./syntaxes/mylang.tmLanguage.json --cacheDir ./.grammar-cache"
},
"devDependencies": {
"vscode-grammar-updater": "^1.1.0"
}
}
// To run this, first save the above as `package.json` in your extension root,
// then install dependencies:
// npm install
// Then execute the update script:
// npm run update-grammar
// This script attempts to fetch and update the grammar from 'my-org/my-lang-grammar'
// and place it in './syntaxes/mylang.tmLanguage.json', using '.grammar-cache'
// for temporary files. Specific arguments might vary based on the grammar source.