This guide shows you how to get autocomplete, validation, and documentation tooltips in your IDE when editing environment configuration files.
cargo run --bin torrust-tracker-deployer -- create schema > envs/environment-schema.jsonThis creates a JSON Schema file that describes the structure and validation rules for environment configurations.
The repository includes .vscode/settings.json with JSON schema mappings. VS Code will automatically provide:
- Autocomplete: Press
Ctrl+Spaceto see available fields - Validation: Red underlines for invalid values or missing required fields
- Documentation: Hover over fields to see descriptions and examples
- Enum values: Dropdown suggestions for fields with limited options
Open any environment file in the envs/ directory:
code envs/example.jsonTry these actions:
- Start typing a field name - you'll see autocomplete suggestions
- Hover over a field - you'll see documentation from the schema
- Remove a required field - you'll see a validation error
- Type an invalid value - you'll get instant feedback
The schema automatically applies to:
envs/*.json- User-provided environment configuration files
Important: The schema does NOT apply to data/*/environment.json files. Those are internal application state files with a different structure containing additional runtime information beyond the user-provided configuration.
If you want to use the schema in a file outside the envs/ directory, add this at the top of your JSON file:
{
"$schema": "../envs/environment-schema.json",
"environment": {
...
}
}- Open Settings → Languages & Frameworks → Schemas and DTDs → JSON Schema Mappings
- Click + to add a new mapping
- Set Schema file or URL:
envs/environment-schema.json - Add file pattern:
envs/*.json
Add to your LSP configuration:
require('lspconfig').jsonls.setup({
settings = {
json = {
schemas = {
{
fileMatch = { "envs/*.json" },
url = "file:///absolute/path/to/envs/environment-schema.json"
}
}
}
}
})Regenerate the schema whenever you:
- Add new configuration fields
- Change validation rules
- Update enum values
- Modify field types
# Quick regeneration
cargo run --bin torrust-tracker-deployer -- create schema > envs/environment-schema.json✅ Fewer errors: Catch configuration mistakes before running commands ✅ Faster editing: Autocomplete reduces typing and lookups ✅ Self-documenting: Descriptions and examples right in your editor ✅ Type safety: Validation ensures correct types for all fields ✅ Discoverability: See all available options without reading docs
- Reload the window:
Ctrl+Shift+P→ "Developer: Reload Window" - Check
.vscode/settings.jsonexists with correct schema mapping - Verify the schema file exists at
envs/environment-schema.json
- Make sure you're editing a
.jsonfile - Check the file is in the
envs/directory and matches the patternenvs/*.json - Try
Ctrl+Spaceto manually trigger autocomplete
The schema might be outdated. Regenerate it:
cargo run --bin torrust-tracker-deployer -- create schema > envs/environment-schema.json