Official VS Code extension for the Digital Substrate Model (DSM) language
The DSM extension provides comprehensive language support for .dsm files, including syntax highlighting, intelligent snippets, and integration with DSM tools.
This extension implements editor support for DSM. The language itself — surface grammar and the canonical JSON wire format used for tooling — is specified at github.com/digital-substrate/dsm.
Full documentation: https://docs.digitalsubstrate.io/dsm/ide.html
Part of the DevKit ecosystem.
- Keywords:
namespace,concept,club,membership,enum,struct,attachment,function_pool - Types: All primitive types (
bool,int8-64,uint8-64,float,double,string,uuid,blob_id) - Collections:
vec,mat,tuple,optional,vector,set,map,xarray,variant - UUIDs: Automatic recognition and highlighting of UUID patterns
- Comments: Line comments (
//) and docstrings ("""...""") - Enumerations: Enum value syntax (
.EnumValue)
Type prefixes and press Tab to insert common DSM constructs:
Primitive Types:
bool,string,uuid,blob_idint8,int16,int32,int64uint8,uint16,uint32,uint64float,double
Collections:
vec→vec<T, size>(numeric vectors)mat→mat<T, cols, rows>(matrices)optional→optional<T>vector→vector<T>set→set<T>map→map<K, V>tuple→tuple<T0, T1>variant→variant<T0, T1>xarray→xarray<T>key→key<T>
Structures:
namespace→ Full namespace template with UUID placeholderconcept→ Concept declarationclub→ Club declarationmembership→ Membership declarationenum→ Enumeration templatestruct→ Structure templateattachment→ Attachment declarationfunction_pool→ Function pool template with UUIDattachment_function_pool→ Attachment function pool templatedocstr→ Documentation string ("""...""")
Advanced Patterns:
isa→ Concept inheritance (concept Derived is a Base;)struct-defaults→ Structure with default field valuesenum-field→ Enum field with default value (.enumValue)attachment-block→ Complete attachment namespace with docstringkeyfield→ Key field with naming convention (key<Concept> fieldKey;)opt-key→ Optional key field (optional<key<Concept>> fieldKey;)mutable→ Mutable function in attachment function pool (state-modifying)query→ Query function in attachment function pool (read-only)
- Auto-closing: Automatic closing of brackets
{},[],(),<>and quotes - Auto-indentation: Smart indentation after
structandenumdeclarations - Folding: Support for code regions with
// #region/// #endregion
Integrated problem matcher ($dsm) for dsm_util.py output, automatically parsing errors into the VS Code Problems panel.
Create custom build tasks to validate DSM files on demand or automatically.
// Type 'concept' and press Tab
concept Person;
struct PersonData {
string name;
uint32 age;
optional<string> email;
};
// Type 'vec' and press Tab, then select type and size
vec<float, 3> position;
// Type 'map' and press Tab
map<string, PersonData> people;
// Type 'namespace' and press Tab
namespace MyApp {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} {
concept User;
concept Session;
};
Note: Replace the UUID placeholder with an actual UUID. You can generate one using:
- Online tools (e.g.,
uuidgencommand on macOS/Linux) - Python:
python3 -c "import uuid; print(uuid.uuid4())" - VS Code extension: UUID Generator
DSM supports single inheritance using the is a keyword:
// Base concept
concept Material;
// Derived concepts
concept MaterialMatte is a Material;
concept MaterialMirror is a Material;
concept MaterialMultilayer is a Material;
// Each material type can have its own properties
struct MaterialMatteProperties {
string name = "Matte Material";
float threshold;
float contrast = 1.0;
};
You can specify default values for struct fields:
struct Transform {
Vector translation;
Vector orientation;
Vector scaling = {1.0, 1.0, 1.0}; // Default value
};
struct CameraProperties {
string name = "Camera"; // String default
bool exposedInConfiguration = true; // Boolean default
float fov = 0.785398; // Float default
PointOfView pointOfView; // Required field
};
Enums can be used as types with default values:
enum CameraDepthRangePolicy {
frustumBased,
fixedDepthRange,
lookAtPointBasedInterest,
useGlobalPolicy
};
struct CameraDepthRange {
CameraDepthRangePolicy policy = .lookAtPointBasedInterest;
float zNear = 0.1;
float zFar = 100.0;
};
Attachments associate data structures with concepts:
namespace Graph {27c49329-a399-415c-baf0-db42949d2ba2} {
// Define concepts
concept Graph;
concept Vertex;
concept Edge;
// Define data structures
struct GraphTopology {
set<key<Vertex>> vertexKeys;
set<key<Edge>> edgeKeys;
};
struct VertexVisualAttributes {
int64 value;
Color color;
};
// Attach data to concepts
attachment<Graph, GraphTopology> topology;
attachment<Vertex, VertexVisualAttributes> visualAttributes;
};
Define callable functions with docstrings:
"""This pool provides access to utility functions."""
function_pool Tools {dc9740c9-9d1d-4c1e-9caa-4c8843b91e82} {
"""Return a + b."""
int64 add(int64 a, int64 b);
"""Return true if a is even."""
bool isEven(int64 a);
"""Return a random word."""
string randomWord(uint64 size);
};
attachment_function_pool is used for operations that modify persistent data in a collaborative editing context. Functions can be mutable (modify state) or queries (read-only).
"""This pool provides functions to edit the graph topology."""
attachment_function_pool ModelGraph {9bdcbb5b-76e9-426f-b8a6-a10ed2d949e6} {
// Mutable functions modify state
"""Create a new edge between two vertices."""
mutable key<Edge> newEdge(key<Graph> graphKey, key<Vertex> vaKey, key<Vertex> vbKey);
"""Create a vertex with specified attributes."""
mutable key<Vertex> newVertex(key<Graph> graphKey, int64 value, Position position);
"""Set the vertex position."""
mutable void setVertexPosition(key<Vertex> vertexKey, Position position);
"""Delete the selected elements."""
mutable void deleteSelection(key<Graph> graphKey);
};
Key differences from function_pool:
mutablekeyword: Marks functions that modify state (create, update, delete)- Commit tracking: All mutations are tracked for collaborative editing and undo/redo
- Return keys: Mutable functions can return
key<T>for newly created entities - Query functions: Non-mutable functions can query state without the
mutablekeyword
Common patterns:
// Creating entities - returns key
mutable key<Vertex> newVertex(key<Graph> graphKey, int64 value, Position position);
// Modifying entities - void return
mutable void setVertexColor(key<Vertex> vertexKey, Color color);
// Querying state - no mutable keyword
set<key<Vertex>> selectedVertices(key<Graph> graphKey);
// Batch operations - operate on sets
mutable void moveVertices(set<key<Vertex>> vertexKeys, Position offset);
Organizing attachment function pools by concern:
// Topology editing
attachment_function_pool ModelGraph {...} {
mutable key<Vertex> newVertex(...);
mutable key<Edge> newEdge(...);
mutable void deleteSelection(...);
};
// Selection management
attachment_function_pool ModelSelection {...} {
mutable void selectAll(key<Graph> graphKey);
mutable void deselectAll(key<Graph> graphKey);
set<key<Vertex>> selectedVertices(key<Graph> graphKey);
};
// Data integrity
attachment_function_pool ModelIntegrity {...} {
mutable void restoreIntegrityByCreating(key<Graph> graphKey);
mutable void restoreIntegrityByDeleting(key<Graph> graphKey);
};
Use triple-quoted strings for documentation:
"""A graph data structure."""
concept Graph;
"""The vertices and edges of the graph topology."""
struct GraphTopology {
"""The vertex keys in the graph."""
set<key<Vertex>> vertexKeys;
"""The edge keys in the graph."""
set<key<Edge>> edgeKeys;
};
Comprehensive DSM examples are available in the dsm-samples repository:
-
Graph modeling (
Ge/): Complete graph topology system demonstrating:- Concept definitions:
Graph,Vertex,Edge - Attachment system for graph topology and visual attributes
- Attachment function pools for collaborative editing:
ModelGraph: Topology editing (newVertex, newEdge, deleteSelection)ModelSelection: Selection management (selectAll, deselectAll)ModelIntegrity: Data integrity restoration
- Mutable operations with proper return types (
key<T>,void) - Query functions for state inspection
- Concept definitions:
-
3D rendering system (
Re/): Raptor rendering engine models including:- Camera system with depth of field and motion blur
- Material system with inheritance (matte, mirror, multilayer)
- Lighting, textures, and environment
- Sensors and timeline management
These examples demonstrate production-quality DSM modeling patterns and best practices.
The DSM extension includes a problem matcher ($dsm) that integrates with VS Code tasks. You can create build tasks to validate DSM files automatically.
-
Create a tasks configuration file in your project:
- Create
.vscode/tasks.jsonin your project root - Or use VS Code:
Terminal→Configure Tasks...→Create tasks.json from template
- Create
-
Add the DSM syntax check task:
{
"version": "2.0.0",
"tasks": [
{
"label": "Check DSM Syntax",
"type": "shell",
"command": "python3",
"args": [
"${workspaceFolder}/tools/dsm_util.py",
"check",
"${file}"
],
"presentation": {
"reveal": "never",
"revealProblems": "onProblem"
},
"problemMatcher": "$dsm",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}- Customize paths based on your project structure:
- Adjust
tools/dsm_util.pypath to match your setup - Use
${workspaceFolder}for workspace-relative paths - Use
${file}to check the currently open file
- Adjust
- Keyboard shortcut: Press
Cmd+Shift+B(macOS) orCtrl+Shift+B(Windows/Linux) - Command Palette:
Tasks: Run Build Task - Menu:
Terminal→Run Build Task...
- The task runs
dsm_util.py checkon your DSM file - The
$dsmproblem matcher parses the output - Errors appear in the Problems panel (
Cmd+Shift+M) - Click on errors to jump directly to the line in your file
presentation.reveal:
"never"- Don't show terminal output (cleanest)"always"- Always show terminal"onProblem"- Show only when errors occur
presentation.revealProblems:
"onProblem"- Auto-open Problems panel on errors"never"- Don't auto-open Problems panel
group.isDefault:
true- Makes this the default build task (runs withCmd+Shift+B)false- Requires manual selection from task list
Add a file watcher task to automatically validate on save:
{
"label": "Watch DSM Files",
"type": "shell",
"command": "python3",
"args": [
"${workspaceFolder}/tools/dsm_util.py",
"check",
"${file}"
],
"problemMatcher": "$dsm",
"runOptions": {
"runOn": "folderOpen"
}
}Then configure VS Code to run tasks on save in settings.json:
{
"files.autoSave": "afterDelay",
"task.autoDetect": "on"
}Note: The actual path to dsm_util.py depends on your project structure. Common locations:
../tools/dsm_util.py(from subdirectory)tools/dsm_util.py(from root)python3 tools/dsm_util.py(explicit Python interpreter)
- Use Tab completion: Start typing a keyword and press Tab to expand snippets
- Navigate by symbols: Use
Ctrl+Shift+O(Windows/Linux) orCmd+Shift+O(macOS) to navigate between concepts, structs, and enums - Fold regions: Use
// #region Descriptionand// #endregionto organize large DSM files - Validate with build task: Set up a VS Code task (see above) and press
Cmd+Shift+Bto check syntax instantly - Jump to errors: Use
Cmd+Shift+Mto open the Problems panel and click errors to jump to their location - Format with tools: Use
python3 tools/dsm_util.py check <file.dsm>to validate syntax from command line
- VS Code version 1.87.0 or higher
- DSM tools from the Viper project (for validation and code generation)
None at this time. Please report issues to: support@digitalsubstrate.io
See CHANGELOG.md for version history.
- DSM Language Specification: dsm — Grammar and JSON wire format, the language-level contract this extension implements editor support for
- JetBrains Plugin: dsm-jetbrains — DSM language support for IntelliJ-family IDEs
- DSM Examples: dsm-samples — Reference DSM models
- DSM Utilities:
dsm_util.py— Command-line semantic validator for.dsmfiles. The extension already validates syntax against the grammar.
This project is licensed under the MIT License — see LICENSE.
Digital Substrate | Report an issue | Contributing