Language Server
Draft provides a Language Server for IDE integration with full editing features.
Installation
Section titled “Installation”draft lsp installFeatures
Section titled “Features”Code Completion
Section titled “Code Completion”Intelligent completion for:
- Variables and actions
- Record fields
- Module imports
- Type members
- Keywords
@// Type @user# to see available fields@user = User { name: "Alice", age: 30 }@user#name @// Completion shows: name, age, emailHover Information
Section titled “Hover Information”Hover over any symbol to see:
- Type information
- Documentation
- Signature
action add(@a: Int, @b: Int) -> Int return @a + @bfin action.
@// Hover over "add" shows:@// action add(a: Int, b: Int) -> Int@// Returns the sum of two integers.Go to Definition
Section titled “Go to Definition”Jump to where a symbol is defined:
F12orCtrl+Click— Go to definitionCtrl+Alt+Click— Go to type definition
Find References
Section titled “Find References”Find all references to a symbol:
Shift+F12— Find all referencesF2— Rename symbol
Diagnostics
Section titled “Diagnostics”Real-time error and warning reporting:
- Type errors
- Unused variables
- Missing fields
- Unreachable code
Code Actions
Section titled “Code Actions”Quick fixes and refactorings:
- Add missing imports
- Generate record fields
- Implement missing actions
- Fix type mismatches
Code Formatting
Section titled “Code Formatting”Format document or selection:
Shift+Alt+F— Format document- Format on save
Signature Help
Section titled “Signature Help”Parameter hints when calling actions:
@add(|) @// Shows: add(a: Int, b: Int) -> IntDocument Symbols
Section titled “Document Symbols”Navigate symbols in the file:
Ctrl+Shift+O— Go to symbol
Workspace Symbols
Section titled “Workspace Symbols”Search symbols across the project:
Ctrl+T— Go to symbol in workspace
Code Lens
Section titled “Code Lens”Inline information:
- Reference counts
- Test status
- Implementation counts
Inlay Hints
Section titled “Inlay Hints”Inline type annotations:
@x = 42 @// Shows: @x: Int = 42@name = "Alice" @// Shows: @name: String = "Alice"Semantic Tokens
Section titled “Semantic Tokens”Syntax highlighting with semantic information:
- Variables
- Types
- Actions
- Keywords
- Comments
Editor Setup
Section titled “Editor Setup”VS Code
Section titled “VS Code”Install the Draft extension:
code --install-extension draft-lang.draftOr search for “Draft” in the extension marketplace.
Features:
- Syntax highlighting
- Code completion
- Error checking
- Formatting
- Debugging
- Testing
Neovim
Section titled “Neovim”Using nvim-lspconfig:
require'lspconfig'.draft_lsp.setup{}Using coc.nvim:
{ "languageserver": { "draft": { "command": "draft", "args": ["lsp"], "filetypes": ["draft"], "rootPatterns": ["draft.toml"] } }}Using vim-lsp:
if executable('draft') augroup lsp_draft autocmd! autocmd User lsp_setup call lsp#register_server({ \ 'name': 'draft', \ 'cmd': {server_info -> ['draft', 'lsp']}, \ 'allowlist': ['draft'], \ }) augroup ENDendifUsing lisp-mode:
(use-package lsp-draft :ensure t :hook (draft-mode . lsp))Sublime Text
Section titled “Sublime Text”Install using Package Control:
Ctrl+Shift+P— Command Palette- “Package Control: Install Package”
- “Draft”
Or manually:
{ "clients": { "draft": { "command": ["draft", "lsp"], "enabled": true, "languageId": "draft", "scopes": ["source.draft"], "syntaxes": ["Packages/Draft/Draft.sublime-syntax"] } }}IntelliJ IDEA / CLion
Section titled “IntelliJ IDEA / CLion”Install the Draft plugin:
- Settings → Plugins → Marketplace
- Search “Draft”
- Install and restart
Configuration
Section titled “Configuration”draft.toml
Section titled “draft.toml”[lsp]inlay_hints = truecode_lens = truesemantic_tokens = truediagnostics = truecompletion_snippets = trueVS Code Settings
Section titled “VS Code Settings”{ "draft.lsp.path": "draft", "draft.lsp.inlayHints": true, "draft.lsp.codeLens": true, "draft.lsp.semanticTokens": true, "draft.format.enable": true, "draft.format.onSave": true}Server Options
Section titled “Server Options”draft lsp [options]Options:
--stdio— Use stdio transport (default)--tcp <port>— Use TCP transport--pipe <name>— Use named pipe--log <level>— Log level (error, warn, info, debug, trace)--log-file <path>— Log file path
Protocol Support
Section titled “Protocol Support”The Draft LSP implements the Language Server Protocol 3.17:
| Feature | Status |
|---|---|
| textDocument/completion | Full |
| textDocument/hover | Full |
| textDocument/definition | Full |
| textDocument/references | Full |
| textDocument/diagnostic | Full |
| textDocument/codeAction | Full |
| textDocument/formatting | Full |
| textDocument/signatureHelp | Full |
| textDocument/documentSymbol | Full |
| textDocument/rename | Full |
| textDocument/inlayHint | Full |
| textDocument/semanticTokens | Full |
| textDocument/codeLens | Full |
| workspace/symbol | Full |
| workspace/didChangeWatchedFiles | Full |
Troubleshooting
Section titled “Troubleshooting”LSP Not Starting
Section titled “LSP Not Starting”@// Check installationdraft lsp --version
@// Check logsdraft lsp --log debug --log-file lsp.logNo Completions
Section titled “No Completions”@// Ensure project is initializeddraft init
@// Check draft.toml existsls draft.tomlHigh CPU Usage
Section titled “High CPU Usage”@// Disable expensive features[lsp]semantic_tokens = falsecode_lens = falsePerformance
Section titled “Performance”| Metric | Value |
|---|---|
| Startup time | < 100ms |
| Completion latency | < 50ms |
| Memory usage | ~50 MB |
| Index time (10k LOC) | < 2s |
