Lsp
The lsp command starts a Language Server Protocol (LSP) server for Cooklang recipe files. It enables IDE features in text editors and development environments.
Overview
The LSP server provides intelligent editing features for .cook files:
- Real-time syntax checking – Catch errors as you type
- Auto-completion – Suggestions for ingredients, cookware, and timers
- Semantic highlighting – Rich syntax coloring beyond basic highlighting
- Hover documentation – Information about ingredients and references
- Document symbols – Navigate recipe structure quickly
- Go to definition – Jump to referenced recipes
Basic Usage
Start the LSP server:
The server communicates over stdin/stdout using the standard LSP protocol. You typically don't run this command directly—your editor starts it automatically.
Editor Integration
Visual Studio Code
Install the Cooklang extension from the VS Code marketplace. The extension automatically uses cook lsp when available.
Manual Configuration:
Add to your settings.json:
Neovim
Using nvim-lspconfig:
Vim with CoC
Add to your coc-settings.json:
Emacs
Using lsp-mode:
Using eglot:
Helix
Add to your languages.toml:
Sublime Text
Using LSP package:
Add to LSP settings:
Zed
Add to your settings.json:
Features
Diagnostics
The LSP server reports syntax errors and warnings in real-time:
Completions
Auto-completion triggers in various contexts:
- Ingredients – After typing
@, suggests known ingredients - Cookware – After typing
#, suggests equipment - Timers – After typing
~, suggests time formats - References – Suggests recipe files for
@./paths - Metadata – Suggests common metadata keys in frontmatter
Hover Information
Hover over elements to see details:
- Ingredients – Quantity, unit, and any notes
- Timers – Formatted duration
- Recipe references – Preview of referenced recipe
- Metadata – Description of metadata fields
Document Symbols
Navigate recipe structure:
- Sections and steps
- Ingredients list
- Cookware list
- Timers
- Metadata fields
Semantic Tokens
Enhanced syntax highlighting for:
- Ingredients (with quantity and unit distinction)
- Cookware
- Timers
- Comments
- Metadata keys and values
- Recipe references
Troubleshooting
Server Not Starting
Verify the cook command is in your PATH:
Connection Issues
Check server logs by running manually:
Editor Not Detecting Server
Ensure your editor:
- Recognizes
.cookfiles as Cooklang - Has LSP client support enabled
- Is configured with the correct command path
Debugging
Enable verbose logging:
Protocol Details
The server implements LSP specification features:
| Feature | Support |
|---|---|
| textDocument/didOpen | Yes |
| textDocument/didChange | Yes |
| textDocument/didClose | Yes |
| textDocument/completion | Yes |
| textDocument/hover | Yes |
| textDocument/definition | Yes |
| textDocument/documentSymbol | Yes |
| textDocument/semanticTokens | Yes |
| textDocument/publishDiagnostics | Yes |
Transport
- Protocol: JSON-RPC 2.0
- Transport: stdin/stdout
- Encoding: UTF-8