
WGSL Linter
Language support for WGSL files and templates embedded in JS/TS: a VS Code extension, the wgsl-lint command-line tool and a dependency-free analyzer library. Validation matches Chrome and reports all the errors at once.

Features
- Diagnostics including const-evaluation, uniformity analysis, memory layout and entry-point IO.
- Hover with types, values, memory layout and spec descriptions of the builtins.
- Completion of names in scope, members, swizzles, builtins, attributes and enumerants, with signature help.
- Inlay hints with the inferred types.
- Go to definition, references, rename, symbols, highlights and folding.
- Formatting that keeps the source's line breaks.
- Semantic highlighting.
All but semantic highlighting also work in JS/TS template literals (without substitutions) tagged wgsl or preceded by a /* wgsl */ comment:
const shader = wgsl`
@compute @workgroup_size(64) fn main() {}
`;
Templates are formatted with the "Format WGSL template" code action.
For an engine composing shared structs and functions into its shaders, list the .wgsl files with them in the wgsl.prelude setting, as globs relative to the workspace folder; their code is spliced after the directives of each shader.
All the .wgsl files of the workspace are validated, open or not, and the templates in the open JS/TS files. The wgsl.validate setting maps globs relative to the workspace folder to the validation levels: full, partial to skip the names declared elsewhere, as in the parts of larger shaders, or off. The JS/TS files matched by a glob other than off are validated even when closed:
"wgsl.validate": { "src/**/*.ts": "full", "shaders/chunks/**": "partial", "vendor/**": "off" }
A // wgsl: partial comment at the start of a shader sets its level as well.
Command Line
wgsl-lint [--tag <name>]... [--prelude <file>] <file or directory>...
Reports the diagnostics of the .wgsl files and, with --tag, of the tagged templates in JS/TS files; exits with 1 on errors.
Library
import { Document, hover, lint } from "wgsl-linter";
const diagnostics = lint(source);
const info = hover(new Document(source), offset);
Positions are UTF-16 offsets.
Embedding in VS Code Extensions
import { register } from "wgsl-linter/vscode";
export function activate(context: vscode.ExtensionContext) {
register(context, { tags: ["wgsl", "shader"], prelude: engineCode });
}
tags: tags of the template literals holding WGSL; wgsl by default.
prelude: WGSL code the engine composes into all the shaders, spliced after their directives.
validate: the validation levels by glob, as in the wgsl.validate setting.
extensions, features: the enable-extensions and language features the target supports; Chrome's by default.
For highlighting, contribute the wgsl language with the configuration and grammars in syntaxes, as this repository's package.json does.
To format all the templates in a document at once, for example from a command, call formatTemplates(editor, edit, tags) within a text editor command.
Development
bun run lint, bun run test, bun run build; bun run vsce packages the extension.
bun run publish publishes the package to npm and the extension to the VS Code Marketplace.
bun run cts [query...] runs the WebGPU conformance tests against the analyzer.
bun scripts/builtins.ts and bun scripts/docs.ts regenerate the builtin tables from Tint and the hover descriptions from the spec.