CDM Language Support for VS Code
Official Visual Studio Code extension for the CDM (Contextual Data Model) language.
Features
- ✅ Syntax highlighting - Basic syntax highlighting for CDM files
- ✅ Real-time validation - Errors and warnings appear as you type
- ✅ Error diagnostics - Inline error messages with severity indicators
- 🚧 Code completion - Autocomplete for types, keywords, and more (coming soon)
- 🚧 Go to definition - Jump to type and model definitions (coming soon)
- 🚧 Hover information - See type information on hover (coming soon)
- 🚧 Document formatting - Format files on save (coming soon)
Requirements
The extension requires the cdm-lsp language server to be installed and available in your PATH.
Installing the Language Server
# From the CDM repository root
cargo install --path crates/cdm-lsp
Or, if you're developing the extension:
# Build the LSP server
cargo build -p cdm-lsp --release
# Add to PATH or configure the path in VS Code settings
Installation
From VSIX (Local Development)
Build the extension:
cd editors/vscode-cdm
npm install
npm run compile
npm run package
Install the generated .vsix file:
code --install-extension cdm-0.1.0.vsix
From VS Code Marketplace (Coming Soon)
Search for "CDM Language Support" in the VS Code extensions marketplace.
Extension Settings
This extension contributes the following settings:
cdm.server.path: Path to the cdm-lsp server binary (default: "cdm-lsp")
cdm.format.indentSize: Number of spaces for indentation when formatting (default: 2)
cdm.validation.checkIds: Check for missing entity IDs and show warnings (default: true)
cdm.trace.server: Trace LSP communication for debugging (default: "off")
Commands
CDM: Restart Language Server - Restart the CDM language server
Usage
- Open or create a
.cdm file
- Start editing - the language server will provide real-time validation
- Errors and warnings will appear inline with red/yellow squiggles
- Hover over errors to see detailed messages
Example
Create a file schema.cdm:
// Type alias with validation
Email: string {
@validation { format: "email", max_length: 320 }
} [#1](https://github.com/cdm-lang/cdm/issues/1)
// Model with fields
User {
id: string [#1](https://github.com/cdm-lang/cdm/issues/1)
email: Email [#2](https://github.com/cdm-lang/cdm/issues/2)
name: string [#3](https://github.com/cdm-lang/cdm/issues/3)
status: "active" | "pending" = "pending" [#4](https://github.com/cdm-lang/cdm/issues/4)
@sql { table: "users" }
} [#10](https://github.com/cdm-lang/cdm/issues/10)
The extension will:
- Highlight syntax
- Validate the schema in real-time
- Show errors if you reference undefined types
- Warn about missing entity IDs (if
checkIds is enabled)
Troubleshooting
Language server not starting
Verify cdm-lsp is in your PATH:
which cdm-lsp
Check the output channel:
- View → Output
- Select "CDM Language Server" from the dropdown
Enable verbose logging:
- Set
cdm.trace.server to "verbose" in settings
- Check the "CDM Language Server Trace" output channel
Errors not showing up
- Ensure the file has a
.cdm extension
- Check if the language mode is set to "CDM" (bottom right of VS Code)
- Try restarting the language server with the command palette (Ctrl+Shift+P): "CDM: Restart Language Server"
Development
Running the Extension in Development Mode
Open the extension directory in VS Code:
cd editors/vscode-cdm
code .
Install dependencies:
npm install
Press F5 to open an Extension Development Host window
Open a .cdm file to test the extension
Building for Production
npm run compile
npm run package
This creates a .vsix file that can be installed in VS Code.
Known Issues
- Code completion not yet implemented
- Go-to-definition not yet implemented
- Hover information not yet implemented
- Multi-file validation (via
@extends) shows errors for inherited types
See the GitHub issues for a full list.
Release Notes
0.1.0 (Initial Release)
- Basic syntax highlighting
- Real-time validation with diagnostics
- Error and warning reporting
- Language server integration
Contributing
Contributions are welcome! Please see the CDM repository for contribution guidelines.
License
MIT