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:

cook lsp

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:

{
  "cooklang.languageServer.path": "cook",
  "cooklang.languageServer.args": ["lsp"]
}

Neovim

Using nvim-lspconfig:

local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')

if not configs.cooklang then
  configs.cooklang = {
    default_config = {
      cmd = { 'cook', 'lsp' },
      filetypes = { 'cooklang' },
      root_dir = lspconfig.util.root_pattern('.git', 'config'),
      settings = {},
    },
  }
end

lspconfig.cooklang.setup{}

Vim with CoC

Add to your coc-settings.json:

{
  "languageserver": {
    "cooklang": {
      "command": "cook",
      "args": ["lsp"],
      "filetypes": ["cooklang"],
      "rootPatterns": [".git", "config"]
    }
  }
}

Emacs

Using lsp-mode:

(with-eval-after-load 'lsp-mode
  (add-to-list 'lsp-language-id-configuration
    '(cooklang-mode . "cooklang"))

  (lsp-register-client
    (make-lsp-client
      :new-connection (lsp-stdio-connection '("cook" "lsp"))
      :activation-fn (lsp-activate-on "cooklang")
      :server-id 'cooklang-lsp)))

Using eglot:

(add-to-list 'eglot-server-programs
  '(cooklang-mode . ("cook" "lsp")))

Helix

Add to your languages.toml:

[[language]]
name = "cooklang"
scope = "source.cooklang"
file-types = ["cook"]
language-servers = ["cooklang-lsp"]

[language-server.cooklang-lsp]
command = "cook"
args = ["lsp"]

Sublime Text

Using LSP package:

Add to LSP settings:

{
  "clients": {
    "cooklang": {
      "enabled": true,
      "command": ["cook", "lsp"],
      "selector": "source.cooklang"
    }
  }
}

Zed

Add to your settings.json:

{
  "lsp": {
    "cooklang": {
      "binary": {
        "path": "cook",
        "arguments": ["lsp"]
      }
    }
  }
}

Features

Diagnostics

The LSP server reports syntax errors and warnings in real-time:

Line 5: Invalid ingredient syntax - missing quantity
Line 8: Timer format should be ~{time%unit}
Line 12: Referenced recipe not found: ./Missing Recipe.cook

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:

which cook
cook --version

Connection Issues

Check server logs by running manually:

cook lsp 2>/tmp/cooklang-lsp.log

Editor Not Detecting Server

Ensure your editor:

  1. Recognizes .cook files as Cooklang
  2. Has LSP client support enabled
  3. Is configured with the correct command path

Debugging

Enable verbose logging:

RUST_LOG=debug cook lsp 2>/tmp/cooklang-lsp-debug.log

Protocol Details

The server implements LSP specification features:

FeatureSupport
textDocument/didOpenYes
textDocument/didChangeYes
textDocument/didCloseYes
textDocument/completionYes
textDocument/hoverYes
textDocument/definitionYes
textDocument/documentSymbolYes
textDocument/semanticTokensYes
textDocument/publishDiagnosticsYes

Transport

  • Protocol: JSON-RPC 2.0
  • Transport: stdin/stdout
  • Encoding: UTF-8

See Also