MSpec DSL Support for VSCode
A comprehensive VSCode extension providing rich language support for PLC4X MSpec (Message Specification) protocol definitions.
Features
Core Language Support
- ✅ Syntax Highlighting - Full syntax highlighting for all MSpec constructs
- ✅ Auto-Completion - Context-aware completion for keywords, types, fields, and constants
- ✅ Error Detection - Real-time syntax and semantic validation with detailed error messages
- ✅ Hover Information - Detailed documentation and type information on hover
- ✅ Go to Definition - Navigate to type and field definitions with
Ctrl+Click
- ✅ Document Formatting - Automatic code formatting with configurable indentation
- ✅ Code Snippets - Pre-defined snippets for common MSpec patterns
Packet Decoder
- ✅ Binary Packet Decoding - Decode binary packets using MSpec type definitions
- ✅ Tree View Display - Hierarchical tree view of decoded packet structure
- ✅ Field Overlay - Visual overlay of field values on the MSpec file
- ✅ Byte Order Support - Automatic handling of BIG_ENDIAN and LITTLE_ENDIAN byte orders
- ✅ Expression Evaluation - Automatic evaluation of const and implicit field expressions
Supported MSpec Constructs
- Type definitions (
type, discriminatedType, enum, dataIo)
- Field types (simple, array, const, reserved, optional, implicit, etc.)
- Data types (bit, byte, int, uint, float, string, etc.)
- Expressions and operators with full expression evaluation
- Type switching and discriminated unions
- Attributes and parameters
- Batch sets with custom byte orders
Installation
From VSCode Marketplace
- Open VSCode
- Go to Extensions (
Ctrl+Shift+X / Cmd+Shift+X)
- Search for "MSpec DSL Support"
- Click Install
From VSIX Package
- Download the latest
.vsix file from releases
- Open Command Palette (
Ctrl+Shift+P / Cmd+Shift+P)
- Run
Extensions: Install from VSIX...
- Select the downloaded
.vsix file
Quick Start
Creating MSpec Files
- Create a new file with
.mspec extension
- Start typing MSpec definitions
- Use
Ctrl+Space for auto-completion suggestions
- Use snippets for quick scaffolding
Example MSpec File
[type SimpleMessage byteOrder='BIG_ENDIAN'
[const uint 8 messageType 0x01]
[simple uint 16 messageId]
[implicit uint 16 payloadLength 'payload.lengthInBytes']
[array byte payload count 'payloadLength']
]
[enum uint 8 MessageType
['0x01' REQUEST]
['0x02' RESPONSE]
]
[discriminatedType ProtocolMessage
[discriminator uint 8 messageType]
[typeSwitch messageType
['0x01' RequestMessage
[simple string 32 command]
]
['0x02' ResponseMessage
[simple uint 8 status]
]
]
]
Using the Packet Decoder
- Open an MSpec file
- Run
MSpec: Open Packet Decoder from the Command Palette
- Select a binary file or paste hex data
- Choose the root type to decode
- View the decoded packet structure in the tree view
Configuration
Configure the extension through VSCode settings:
{
"mspec.validation.enabled": true,
"mspec.validation.strictMode": false,
"mspec.completion.enabled": true,
"mspec.completion.snippets": true,
"mspec.formatting.enabled": true,
"mspec.formatting.indentSize": 4,
"mspec.trace.server": "off"
}
Configuration Options
validation.enabled - Enable/disable real-time validation
validation.strictMode - Enable strict validation mode for additional checks
completion.enabled - Enable/disable auto-completion
completion.snippets - Enable/disable code snippets
formatting.enabled - Enable/disable document formatting
formatting.indentSize - Number of spaces for indentation (default: 4)
trace.server - Trace communication with language server (off, messages, verbose)
Commands
Available Commands
MSpec: Restart Language Server - Restart the language server
MSpec: Show Output - Show language server output channel
MSpec: Go to Definition - Navigate to type/field definition
MSpec: Format Document - Format the current document
MSpec: Open Packet Decoder - Open the packet decoder panel
Keyboard Shortcuts
Ctrl+Space - Trigger auto-completion
Ctrl+Shift+F - Format document
Ctrl+Click - Go to definition
F12 - Go to definition (alternative)
Troubleshooting
Language Server Not Starting
- Verify Node.js 18+ is installed
- Check the MSpec output channel for error messages
- Try restarting VSCode
No Syntax Highlighting
- Ensure file has
.mspec extension
- Restart VSCode after installation
Auto-Completion Not Working
- Check if completion is enabled in settings
- Verify language server is running
- Try restarting the language server with
MSpec: Restart Language Server
Packet Decoder Issues
- Ensure the MSpec file is valid and has no syntax errors
- Verify the binary data format matches the selected type
- Check byte order settings in the MSpec type definition
Support
For issues, feature requests, or questions:
License
Licensed under the Apache License 2.0 - see LICENSE file for details.