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.
Install the language server
Section titled “Install the language server”# Go installgo install github.com/gsid-nl/kdef/cmd/kdef-lsp@latest
# Or build from sourcegit clone https://github.com/gsid-nl/kdef.gitcd kdef && make build # produces ./kdef-lspMake sure kdef-lsp is on your PATH.
VS Code
Section titled “VS Code”Install the kdef extension (the .vsix is attached to every release).
code --install-extension kdef-0.X.Y.vsixThe 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.
- Install
kdef-lsp(see above). - Settings → Languages & Frameworks → Language Servers
- Click + to add a new server
- Name:
kdef - Command:
kdef-lsp(full path if not onPATH) - Under File type mappings, add
*.kdef - OK, open any
.kdeffile
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
Section titled “Neovim”Any LSP-capable Neovim setup works. With nvim-lspconfig:
-- ~/.config/nvim/lua/plugins/kdef.lualocal 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 kdefvim.filetype.add({ extension = { kdef = 'kdef' } })Pre-commit hook
Section titled “Pre-commit hook”Install the git hook that runs kdef validate before every commit:
kdef install-hook # fresh install in the current repokdef 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.