RelSpec Template Editor for VS Code
Visual editor and tooling for RelSpec PostgreSQL migration templates.
Features
1. Template Preview
- Command:
RelSpec: Preview Template - Shortcut: Click the preview icon in the editor title bar
- Preview your templates with sample data
- Side-by-side view of template, data, and rendered SQL
2. Syntax Validation
- Command:
RelSpec: Validate Template - Automatic validation on save (configurable)
- Highlights syntax errors inline
- Checks for unclosed template tags
3. IntelliSense
- Auto-completion for template functions
- Function signatures and documentation on hover
- Keyword completions (
if,range,template, etc.)
4. Template Scaffolding
- Command:
RelSpec: New Template - Quick scaffolding for common template types:
- DDL operations
- Constraints
- Indexes
- Audit trails
- Reusable fragments
5. Function Library
- Command:
RelSpec: List Available Functions - Browse all available template functions
- See examples and documentation
- Quick reference for template development
Installation
From Source
- Clone the RelSpec repository
- Navigate to the extension directory:
cd vscode-extension - Install dependencies:
npm install - Compile the extension:
npm run compile - Open in VS Code:
code . - Press
F5to launch the extension in a new window
From VSIX (when published)
code --install-extension relspec-template-editor-0.1.0.vsix
Usage
Opening Templates
- Open your RelSpec project in VS Code
- Navigate to
pkg/writers/pgsql/templates/ - Open any
.tmplfile - The extension will automatically activate
Previewing Templates
- Open a template file
- Click the preview icon in the editor title bar OR
- Run command:
RelSpec: Preview Template(Ctrl+Shift+P) - The preview pane will show:
- Your template source
- Sample data (configurable)
- Rendered SQL output
Configuring Sample Data
Set custom sample data for preview in settings:
{
"relspec.previewSampleData": {
"SchemaName": "public",
"TableName": "users",
"ColumnName": "email",
"Columns": [
{"Name": "id", "Type": "integer", "NotNull": true},
{"Name": "email", "Type": "text"}
]
}
}
Creating New Templates
- Run command:
RelSpec: New Template - Select template type
- Enter template name
- The extension creates a scaffolded template
- Edit and customize
Using IntelliSense
Type {{ to trigger auto-completion:
{{upper // Shows function signature and documentation
{{. // Shows available fields from data structure
Hover over function names to see:
- Function signature
- Description
- Usage examples
Configuration
Available settings:
| Setting | Type | Default | Description |
|---|---|---|---|
relspec.templatePath |
string | pkg/writers/pgsql/templates |
Path to template directory |
relspec.autoValidate |
boolean | true |
Validate templates on save |
relspec.showDataStructures |
boolean | true |
Show data structure hints in preview |
relspec.previewSampleData |
object | {} |
Sample JSON data for preview |
Keyboard Shortcuts
| Command | Shortcut | Description |
|---|---|---|
| Preview Template | N/A | Click preview icon in title bar |
| Validate Template | N/A | Use command palette |
| New Template | N/A | Use command palette |
Template Functions Reference
The extension provides IntelliSense for all RelSpec template functions:
String Manipulation
upper- Convert to uppercaselower- Convert to lowercasetitle- Title casesnake_case- Convert to snake_casecamelCase- Convert to camelCase
SQL Formatting
indent- Indent textquote- Quote for SQLescape- Escape special characterssafe_identifier- Make safe SQL identifier
Type Conversion
goTypeToSQL- Go type → SQL typesqlTypeToGo- SQL type → Go typeisNumeric- Check if numeric typeisText- Check if text type
Collection Helpers
first- First elementlast- Last elementfilter- Filter elementsmapFunc- Map functionjoin_with- Join with separatorjoin- Join strings
See full documentation: Template Functions
Code Snippets
The extension includes snippets for common patterns:
| Prefix | Description |
|---|---|
tmpl-define |
Define a new template |
tmpl-template |
Use a template |
tmpl-block |
Define a block |
tmpl-if |
If statement |
tmpl-range |
Range loop |
tmpl-with |
With statement |
Development
Building
npm run compile
Watching
npm run watch
Linting
npm run lint
Testing
npm test
Troubleshooting
Extension Not Activating
Problem: Extension doesn't activate when opening .tmpl files
Solution:
- Check that file has
.tmplextension - Reload VS Code window (Ctrl+Shift+P → "Reload Window")
- Check extension is enabled in Extensions panel
Preview Not Working
Problem: Preview shows error or doesn't update
Solution:
- Ensure RelSpec binary is in PATH
- Check template syntax is valid
- Verify sample data is valid JSON
IntelliSense Not Working
Problem: Auto-completion doesn't trigger
Solution:
- Type
{{to trigger - Check language mode is set to "Go Template"
- Reload window
Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
Same as RelSpec project license.
Links
Changelog
0.1.0 (Initial Release)
- Template preview with sample data
- Syntax validation
- IntelliSense for functions
- Template scaffolding
- Function library browser