LSP Server Integration
FakeDataDSL includes a full Language Server Protocol (LSP) server for IDE integration.
Features
- Go to Definition - Jump to schema definitions from
Ref(User.id)references - Real-time Diagnostics - See errors as you type with line/column numbers
- Auto-completion - Suggestions for types, behaviors, and schemas
- Hover Documentation - See type and behavior documentation on hover
Quick Start
1. Start the LSP Server
fake_data_dsl lsp
The server will run on stdin/stdout, communicating via JSON-RPC.
2. Configure Your IDE
VS Code / Cursor
Create .vscode/settings.json:
{
"fakeDataDSL.lsp.enabled": true,
"fakeDataDSL.lsp.command": "fake_data_dsl",
"fakeDataDSL.lsp.args": ["lsp"]
}
Neovim
Add to your Neovim config:
require('lspconfig').fake_data_dsl.setup({
cmd = { 'fake_data_dsl', 'lsp' },
filetypes = { 'fakedatadsl', 'dsl' },
root_dir = require('lspconfig.util').root_pattern('.git', 'schemas'),
})
Supported LSP Features
textDocument/definition
Jump to schema definitions:
Order:
user_id: Ref(User.id) # Ctrl+Click to jump to User schema
textDocument/hover
Hover over types and behaviors to see documentation:
User:
id: uuid # Hover to see UUID type docs
@latency 100ms # Hover to see latency behavior docs
textDocument/completion
Auto-complete suggestions:
- Types:
uuid,name,email, etc. - Behaviors:
@latency,@failure,@partial_data, etc. - Schemas:
User,Order,Product, etc.
textDocument/diagnostic
Real-time error reporting:
- Parse errors with line/column numbers
- Path validation errors for
copy()references - Cycle detection for circular schema references
- Field order validation errors
Architecture
The LSP server reuses existing FakeDataDSL components:
- Parser - For syntax validation and AST generation
- Validator - For semantic validation (paths, cycles)
- Registry - For schema lookup and cross-references
No code duplication - the LSP server is a thin wrapper around existing functionality.
Troubleshooting
Server Not Starting
Check that fake_data_dsl is in your PATH:
which fake_data_dsl
No Diagnostics Appearing
Ensure your .dsl files are recognized:
- Check file extension (
.dslor.fdsl) - Verify language mode is set to "FakeDataDSL"
- Check LSP server logs for errors
Completion Not Working
The LSP server needs schemas loaded to provide completion:
- Open a
.dslfile with schema definitions - Use
loadcommand in REPL to load schemas - Completion will work for loaded schemas
API Reference
Server Class
server = FakeDataDSL::LSP::Server.new(input: $stdin, output: $stdout)
server.run
Supported Methods
initialize- Initialize LSP servertextDocument/didOpen- Document openedtextDocument/didChange- Document changedtextDocument/didClose- Document closedtextDocument/definition- Go to definitiontextDocument/hover- Hover informationtextDocument/completion- Completion suggestionstextDocument/diagnostic- Validation diagnosticsshutdown- Shutdown serverexit- Exit server
Examples
Basic Setup
# Terminal 1: Start LSP server
fake_data_dsl lsp
# Terminal 2: Connect IDE to server
# (IDE handles connection automatically)
Custom Configuration
# Custom LSP server with logging
require 'fake_data_dsl/lsp/server'
input = File.open('lsp_input.log', 'w')
output = File.open('lsp_output.log', 'w')
server = FakeDataDSL::LSP::Server.new(input: input, output: output)
server.run
Performance
The LSP server is lightweight:
- Memory: ~10MB baseline
- CPU: Minimal (only validates on change)
- Latency: <10ms for most operations
Limitations
- Currently single-file workspace (multi-file support planned)
- No incremental parsing (full parse on each change)
- No semantic tokens (syntax highlighting only)
Future Enhancements
- Multi-file workspace support
- Incremental parsing
- Semantic tokens for better highlighting
- Code actions (quick fixes)
- Rename refactoring