portfolio / work / yrest-vscode.mdoc
yRest for VS Code
Write db.yml with an editor that understands it.
A VS Code extension for yRest files — syntax highlighting, hover documentation, context-aware autocompletion and diagnostics for db.yml and *.yrest.yml, also inside yrest tagged templates in TypeScript and JavaScript.
At a glance
- Problem
- Mistakes in db.yml conventions, like a missing collection or a key without its _, only showed up when the server ran.
- My part
- Built and published it alone: grammars, providers, validation rules, tests and the release pipeline.
- What I delivered
- Published on the VS Code Marketplace, from version tags.
- Highlighting, hover docs, autocompletion and diagnostics, also inside yrest tagged templates.
- Unit tests cover the validation rules.

Problem
yRest's db.yml format grew its own conventions: relations (_rel), custom routes (_routes), a compact relation DSL and template variables. Without editor support, a typo in a collection name or a key without its _ prefix only showed up when the server ran.
Solution
- Highlighting for reserved keys, relation types and aliases, cardinalities, the relation DSL, template variables and path parameters.
- Hover documentation for every reserved key, with a short description and a YAML example.
- Autocompletion in ten contexts, such as collection names for relation targets or HTTP methods for
_method. - Diagnostics on every keystroke: YAML errors with exact position, relations pointing to collections that don't exist, invalid relation types or cardinalities, and
_routeskeys written without their_prefix. - The same help inside tests: hover and diagnostics also work in
yrest`...`tagged templates in TypeScript and JavaScript.
Technical decisions
Diagnostics scoped to their section
- Problem
- Errors were reported on the first occurrence of a word anywhere in the file, causing false positives.
- Decision
- Scope each diagnostic to its section, searching from the _rel: or _routes: offset.
- Alternatives
- Highlight the whole line, or skip positions.
- Trade-off
- The validator has to track section offsets.
- Evidence
- Fixed in v0.2.2; a field named status inside _schema is no longer flagged.
Quality
Unit tests cover the validation rules and the shared constants. CI compiles, lints and packages the extension on every push; tags publish to the VS Code Marketplace.
Gallery
Stack
| Layer | Technology | Why |
|---|---|---|
| Interface | VS Code Extension API | Hover, completion and diagnostics providers. |
| Interface | TextMate grammars | Highlighting for yRest files, injected into plain YAML and into TS/JS tagged templates. |
| Runtime | TypeScript + yaml | Validation logic on top of the same YAML parser yRest uses. |
| Quality | Vitest | Unit tests for the validation rules and shared constants. |




