Skip to content

Setup LSP

import { Steps, Aside, Tabs, TabItem } from ‘@astrojs/starlight/components’;

kag-lsp is a Language Server Protocol implementation for KAG scripts (.ks files). It provides:

  • Syntax highlighting and error diagnostics
  • Hover documentation for every built-in tag and attribute
  • Go-to-definition for labels, macros, and files
  • Auto-completion for tag names and attribute keys
  • Find-all-references for labels and macros

kag-lsp lives in the kag-lsp crate of this repository.

  1. Clone the repository

    Terminal window
    git clone https://github.com/haruki-nikaidou/kani-engine.git
    cd kani-engine
  2. Build in release mode

    Terminal window
    cargo build -p kag-lsp --release

    The binary is placed at target/release/kag-lsp.

  3. Put it on your PATH

    Terminal window
    # Linux / macOS
    cp target/release/kag-lsp ~/.local/bin/
    # Or add the release dir to PATH in your shell profile
    export PATH="$PATH:/path/to/kani-engine/target/release"
  1. Install the KAG Script extension (or any generic LSP client such as vscode-glspc).

  2. Add this to your settings.json:

    {
    "languageServerExample.serverPath": "/path/to/kag-lsp"
    }

    Or, with a generic client:

    {
    "genericLSP.servers": [
    {
    "name": "KAG",
    "language": "kag",
    "extensions": [".ks"],
    "command": ["kag-lsp"]
    }
    ]
    }

Add to your Neovim config:

local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')
if not configs.kag_lsp then
configs.kag_lsp = {
default_config = {
cmd = { 'kag-lsp' },
filetypes = { 'kag' },
root_dir = lspconfig.util.root_pattern('Cargo.toml', '.git'),
settings = {},
},
}
end
lspconfig.kag_lsp.setup {}

Then add a filetype detection rule:

autocmd BufRead,BufNewFile *.ks set filetype=kag

Add to ~/.config/helix/languages.toml:

[[language]]
name = "kag"
scope = "source.kag"
file-types = ["ks"]
language-servers = ["kag-lsp"]
[language-server.kag-lsp]
command = "kag-lsp"

Any editor that supports the LSP protocol can use kag-lsp. Configure your editor to:

  • Launch kag-lsp as a server process (communicates over stdio)
  • Associate the .ks file extension with the kag language ID

Hovering over a tag name displays its description, required and optional attributes, and a short example — sourced directly from the tag_defs module.

Ctrl+click (or your editor’s equivalent) on a target=*label value jumps to the label’s definition, even across files.

The LSP validates attribute completeness in real time:

SeverityCondition
ErrorA required attribute (e.g. storage= on [bg]) is missing
WarningA recommended attribute is absent and the tag will have no effect

Pressing the completion key inside [ or after a space inside a tag gives you:

  • All known tag names
  • All valid attribute keys for the current tag
  • Boolean value suggestions (true / false)