Lynx Language Support for Visual Studio Code
A comprehensive Visual Studio Code extension that provides syntax highlighting and language support for the Lynx declarative modeling language.
Features
- Complete Syntax Highlighting: Full support for all Lynx language constructs
- Language Server Protocol (LSP): Real-time type checking and error diagnostics
- Intelligent Error Positioning: Errors shown at their exact source location
- Multi-Comment Support: Both single-line (
// ) and multi-line (/* */ ) comments
- Language Configuration: Auto-closing brackets, comment toggling, and smart indentation
- Color Theme: Custom "Lynx Dark" theme optimized for Lynx code
- File Association: Automatic recognition of
.lynx files
Language Server Features
Real-time Type Checking
- Parse Error Detection: Syntax errors highlighted as you type
- Type Error Detection: Comprehensive type checking with detailed error messages
- Intelligent Error Positioning: Errors shown at their exact source location, not just line 1
- Multiple Error Support: All errors in a file are reported simultaneously
Supported Error Types
- Undefined Types: Detection of unknown type references
- Undefined Enum Variants: Invalid enum variant usage (e.g.,
Material.Aluminum )
- Field Errors: Missing required fields and unknown field usage
- Type Mismatches: String vs int errors and other type conflicts
- Logic Expression Errors: Invalid logic constructs and operators
Configuration
The extension includes configurable settings for the language server:
lynx.server.path : Path to the Lynx language server executable
lynx.server.args : Additional arguments for the language server
lynx.diagnostics.enable : Toggle real-time diagnostics
Language Features Supported
Type System
- Primitive type aliases: Simple declarations like
type Size: int
- Complex logic types: Boolean, integer ranges, and logic operators
- Logic operators:
All , Any , Not , Exactly<n> , AtLeast<n> , AtMost<n>
- Optional fields: Support for
? syntax (e.g., nails: Any[Nail]? )
- Default field values: Lambda expressions and literals as defaults
Instance Declarations (New Syntax!)
- Modern syntax:
TypeName instanceName { field: value, ... }
- Object literals: Inline type construction
- Field assignments: Clean property assignment syntax
Advanced Expressions
- Binary operators: Full support for comparison (
>= , <= , == , != ) and arithmetic (+ , - , * , / )
- Lambda expressions:
(param: Type) -> expression and (_) -> expression
- Field access chains:
object.field.subfield.property
- Match expressions: Pattern matching with logic expressions and wildcards
- Logic expressions: Composable logic constructs with parameters
- Built-in function calls: Nested function calls with complex arguments
Enhanced Solve Calls
- Assignment syntax:
variable = solve(target, objectives, constraints)
- Objective specifications:
{ item1: weight1, item2: weight2 }
- Constraint blocks: Logic expressions as constraints
Built-in Functions
Comprehensive highlighting for Lynx built-in functions:
solve , find , sum , first
match , propagate
Installation
From VSIX (Recommended)
- Download the latest
.vsix file from releases
- Open VS Code
- Go to Extensions view (
Ctrl+Shift+X )
- Click the "..." menu and select "Install from VSIX..."
- Select the downloaded
.vsix file
Language Server Setup
For full LSP features (type checking, error diagnostics):
Install Rust (if not already installed):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Build the Lynx Language Server:
git clone https://github.com/lynx-lang/lynxql
cd lynxql
cargo build --release
Configure the extension:
- Open VS Code settings (
Ctrl+, )
- Search for "lynx.server.path"
- Set the path to your compiled
lynx-lsp executable
- Example:
/path/to/lynxql/target/release/lynx-lsp
Development Setup
# Install vsce (VS Code Extension Manager)
npm install -g vsce
# Package the extension
cd vscode-lynx-extension
vsce package
# Install the generated .vsix file
code --install-extension lynx-language-4.0.5.vsix
Usage
- Create or open a file with the
.lynx extension
- VS Code will automatically apply Lynx syntax highlighting
- Optionally, select the "Lynx Dark" color theme for optimal highlighting:
- Open Command Palette (
Ctrl+Shift+P )
- Type "Preferences: Color Theme"
- Select "Lynx Dark"
Example Code
// Multi-line comment support
/*
Complex type declarations with logic types
and default lambda expressions
*/
// Simple type alias
type Size: int
// Complex type with optional fields and defaults
type Toolbox: All {
hammers: AtLeast<1>[Hammer] = (_) -> find((h: Hammer) -> h.size >= 8),
nails: Any[Nail]?, // Optional field
boxType: BoxType
}
type Carpenter: All {
name: string,
age: int,
workable: bool = (c: Carpenter) -> c.age >= 18,
toolbox: Toolbox,
salary: float = (c: Carpenter) -> 20000.0 - sum(c.toolbox.hammers.cost)
}
// New instance declaration syntax
Hammer hammer1 {
material: "steel",
size: 10,
cost: 25.0
}
Carpenter john {
name: "John Doe",
age: 30,
workable: true,
toolbox: Toolbox {
hammers: AtLeast<1> { hammer1 },
nails: Any { find((n: Nail) -> n.length >= 10) },
boxType: BoxType { width: 30, height: 20, depth: 15 }
}
}
// Enhanced solve calls with assignment syntax
solution = solve(john, { hammer1: 1.0, nail1: 0.5 }, { Not { hammer2 } })
// Field access chains
total_cost = john.toolbox.hammers.cost + john.toolbox.nails.cost
Language Configuration
The extension provides:
- Multi-comment support: Toggle line comments (
// ) and block comments (/* */ )
- Auto-closing pairs: Brackets, parentheses, quotes, and angle brackets
- Smart indentation: Context-aware indentation for nested structures
- Enhanced on-enter rules: Automatic comment continuation and proper indentation
Migration from v2.x
Instance Declaration Changes
Before (v2.x):
let hammer: Hammer = Hammer(material="steel", size=10)
After (v3.x):
Hammer hammer {
material: "steel",
size: 10
}
New Features Available
- Primitive type aliases:
type Size: int
- Optional fields:
nails: Any[Nail]?
- Field access chains:
carpenter.toolbox.hammers.cost
- Binary operators in expressions:
age >= 18 , cost + tax
- Multi-line comments:
/* ... */
Color Theme
The "Lynx Dark" theme provides optimized highlighting:
- Keywords: Red tones (
type , solve , match )
- Logic operators: Orange (
All , Any , AtLeast<1> )
- Types: Green for user types, blue for primitives
- Functions: Purple for built-in functions
- Operators: Red for arrows (
-> ), blue for comparisons (>= )
- Field access: Distinct coloring for chained access
- Comments: Gray italic for both single and multi-line
Contributing
- Fork the repository
- Make your changes to grammar or language configuration
- Test with sample Lynx files using the new syntax
- Update changelog and documentation
- Submit a pull request
Issues
Report issues and feature requests on the GitHub repository.
License
MIT License - see LICENSE file for details.
Recent Changes
3.0.0 - Major Language Update
- BREAKING: New instance declaration syntax
- Multi-line comment support (
/* */ )
- Binary operators and field access chains
- Enhanced lambda expressions with complex operations
- Improved solve call syntax with assignment
- Complete grammar rewrite for better parsing
- Updated example files with new syntax
See CHANGELOG.md for full version history.
| |