Editors & LSP

Set up kdef-lsp for live diagnostics in VS Code, JetBrains, and Neovim.

kdef ships a language server (kdef-lsp) that provides real-time error squiggles as you type. Block type validation, reference checking (secret("name", "key") against declared secrets), variable type checking, missing namespaces: all caught in the editor.

Install the language server

# Go install
go install github.com/gsid-nl/kdef/cmd/kdef-lsp@latest

# Or build from source
git clone https://github.com/gsid-nl/kdef.git
cd kdef && make build       # produces ./kdef-lsp

Prebuilt kdef-lsp binaries are attached to every release too. Make sure kdef-lsp is on your PATH.

VS Code

Install the kdef extension (the .vsix is attached to every release).

code --install-extension kdef-0.X.Y.vsix

The extension activates automatically for .kdef files and ships with:

  • HCL-derived syntax highlighting
  • Snippets for the common blocks
  • LSP-driven diagnostics (error squiggles) and completion

If kdef-lsp isn't on your PATH, set a custom path:

// VS Code settings.json
{
  "kdef.lsp.path": "/home/me/bin/kdef-lsp"
}

JetBrains (IntelliJ, GoLand, WebStorm, PhpStorm, RubyMine, …)

JetBrains IDEs have built-in LSP support since 2023.3.

  1. Install kdef-lsp (see above).
  2. Settings → Languages & Frameworks → Language Servers
  3. Click + to add a new server
  4. Name: kdef
  5. Command: kdef-lsp (full path if not on PATH)
  6. Under File type mappings, add *.kdef
  7. OK, open any .kdef file

For syntax highlighting, install the TextMate Bundles plugin and point it at the bundled grammar (vscode-extension/syntaxes/kdef.tmLanguage.json in the kdef repo).

Neovim

Any LSP-capable Neovim setup works. With nvim-lspconfig:

-- ~/.config/nvim/lua/plugins/kdef.lua
local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')

if not configs.kdef then
  configs.kdef = {
    default_config = {
      cmd = { 'kdef-lsp' },
      filetypes = { 'kdef' },
      root_dir = lspconfig.util.root_pattern('root.kdef', 'vars.kdef', '.git'),
      settings = {},
    },
  }
end

lspconfig.kdef.setup({})

-- Associate *.kdef with filetype kdef
vim.filetype.add({ extension = { kdef = 'kdef' } })

Pre-commit hook

Install the git hook that runs kdef validate before every commit:

kdef install-hook            # fresh install in the current repo
kdef install-hook --append   # append to an existing pre-commit hook (idempotent)

The generated script detects whether kdef is on the path of the committer. If not, it logs a warning and skips validation, so cloning the repo on a machine without kdef installed doesn't break commits.