A comprehensive Language Server Protocol (LSP) implementation for Enforce Script, the scripting language used by the Enfusion game engine and for modding video games such as DayZ.
# Build the project
cargo build --release
# Run tests
cargo test
# Start the LSP server
cargo run --release- Tutorial - Comprehensive guide to using and extending the LSP
- Contributing - Guidelines for contributors
- Syntax Reference - Complete Enforce Script language specification
- Implementation Details - Architecture and design decisions
- Developer Guide - Guide for AI agents and developers
-
Lexer/Tokenizer - Complete tokenization of Enforce Script source code
- Keywords, operators, literals, identifiers, comments
- Support for all Enforce Script syntax elements
-
Parser - Full AST generation for Enforce Script
- Classes (with inheritance, modded classes, templates)
- Functions and methods (with modifiers: private, protected, static, override, etc.)
- Variables and fields (with modifiers: const, ref, autoptr, etc.)
- Enums (with inheritance and custom values)
- Control structures (if, else, switch, for, foreach, while)
- Expressions (binary, unary, member access, indexing, new, etc.)
- Typedefs
-
Semantic Analyzer - Symbol table and basic semantic analysis
- Symbol resolution across scopes
- Class hierarchy tracking
- Type inference for variables
- Undefined symbol detection
-
Diagnostics - Real-time error and warning detection with accurate positions
- Syntax errors from parser with line/column information
- Semantic errors from analyzer
- Undefined variable warnings
-
Completion - IntelliSense support
- All Enforce Script keywords
- Symbols from symbol table (classes, methods, fields, variables)
- Context-aware completions
-
Hover Information - Rich symbol information on hover
- Symbol type and kind display
- Markdown-formatted code blocks
- Definition location highlighting
-
Go to Definition - Navigate to symbol definitions
- Jump from usage to definition
- Works with classes, functions, methods, variables
-
Find References - Find all symbol occurrences
- Lists all definitions of a symbol
- Document-wide symbol search
-
Signature Help - Function/method parameter hints
- Basic signature information
- Shows function names and signatures
-
Document Symbols - Outline view
- Classes with fields and methods
- Functions
- Enums with variants
- Hierarchical symbol tree
-
Folding Ranges - Code folding support
- Classes and methods
- Code blocks
- Workspace Symbols - Global symbol search (stub implemented)
- Go to Implementation - Navigate to implementations (stub implemented)
- Go to Type Definition - Navigate to type definitions (stub implemented)
- Code Actions - Quick fixes and refactorings (stub implemented)
- Rename - Symbol renaming (stub implemented)
- Inlay Hints - Inline type/parameter hints (stub implemented)
- Rust 1.70+ (https://rustup.rs/)
- Cargo (comes with Rust)
# Clone the repository
git clone <repository-url>
cd enforce-script-lsp
# Build the project
cargo build --release
# Run tests
cargo test
# Run the LSP server
cargo run --releaseThe compiled binary will be available at target/release/enforce-script-lsp (or .exe on Windows).
The LSP server communicates over stdin/stdout following the Language Server Protocol specification.
To use with VS Code, you'll need to create or update a VS Code extension that uses this LSP server. Example configuration:
{
"command": "path/to/enforce-script-lsp",
"args": []
}lexer.rs- Tokenizes Enforce Script source code into tokensparser.rs- Parses tokens into an Abstract Syntax Tree (AST)semantic.rs- Performs semantic analysis and builds symbol tableslsp.rs- LSP server implementation using tower-lspmain.rs- Entry point that starts the LSP server
Token- Represents a lexical token with type, lexeme, and positionExpression- Represents Enforce Script expressions in the ASTStatement- Represents Enforce Script statements in the ASTDeclaration- Represents top-level declarations (classes, enums, functions, typedefs)Symbol- Represents a symbol in the symbol table with scope and type informationSymbolTable- Maintains symbols across scopes for semantic analysis
The project includes comprehensive unit tests for all major components:
# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test module
cargo test lexer::tests
cargo test parser::tests
cargo test semantic::tests- ✅ Lexer: Keywords, identifiers, numbers, strings, operators, comments
- ✅ Parser: Classes, enums, functions, expressions, statements
- ✅ Semantic: Symbol resolution, undefined variable detection
- ✅ Integration: End-to-end parsing and analysis
The implementation follows the official Enforce Script syntax as documented in ENFORCE-SCRIPT-SYNTAX.md, which covers:
- Basic syntax (code blocks, variables, functions, comments)
- Operators (arithmetic, assignment, relational, logical, bitwise)
- Keywords and modifiers
- Types (primitives, objects, enums, templates, arrays)
- Control structures (if/else, switch, for, foreach, while)
- Object-oriented features (classes, inheritance, constructors/destructors)
- Managed classes and automatic reference counting
- Modding features (modded classes, modded constants)
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Complete LSP Features - Finish implementing goto definition, find references, rename, etc.
- Enhanced Type Checking - More sophisticated type inference and checking
- Better Error Recovery - Improve parser error recovery for better diagnostics
- Performance - Optimize parsing and semantic analysis for large files
- Documentation - Add more inline documentation and examples
- Tests - Expand test coverage for edge cases
# Run tests
cargo test
# Format code
cargo fmt
# Run linter
cargo clippy
# Build documentation
cargo doc --openSee LICENSE file for details.
- Bohemia Interactive for the Enforce Script language specification
- The tower-lsp library maintainers for the excellent LSP framework
- The Rust community for the robust tooling ecosystem