Skip to content

Editors & LSP

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.

Terminal window
# 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

Make sure kdef-lsp is on your PATH.

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

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

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

  • HCL-derived syntax highlighting
  • LSP-driven diagnostics (error squiggles, hover info)
  • Document formatting

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, …)

Section titled “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).

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' } })

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

Terminal window
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.