Skip to content

LSP: Language-Server Intelligence & Edit Gate ​

Kompile's lsp tool exposes real language servers directly to agents — no grep approximations when type resolution, overload disambiguation, or compile/lint diagnostics are needed. One lsp tool handles navigation, refactoring, diagnostics, server lifecycle, and a fail-closed edit-verification gate (action=check).


Operations at a glance ​

ActionRequired InputsWhat It Does
definitionTarget (file_path + line + column or symbol)Jumps to the exact symbol definition
referencesTargetFinds every semantic reference across the project
call_hierarchyExplicit file_path + line + columnIncoming (default) or outgoing call edges (max_depth=1, max_results=20 up to 100)
hoverTargetReturns resolved type signature and documentation at a position
symbolsfile_path (or symbol)Document outline with symbol kinds and line ranges
workspace_symbolsquery + (file_path or language)Project-wide symbol search from the active language server
renameTarget + new_nameComputes a WorkspaceEdit — dry_run=true by default (renders per-file diff preview)
diagnosticsfile_path (or symbol)Returns compile/lint diagnostics; explicitly reports if the server never answered instead of pretending the file is clean
checkfile_paths=[...]Fail-closed edit-verification gate across all touched files (and every required backend)
serversserver_action=list|status|start|stop|restartInspect installed/running servers or control their lifecycle

Addressing a target ​

For definition, references, hover, and rename, you can address a symbol in either of two ways:

  • Explicit position: file_path + line + column — 1-based (Kompile converts to LSP's 0-based UTF-16 coordinates internally).
  • By symbol name: symbol (+ optional project_id) — resolved automatically through the Local Code Index (local_code_index action=index first if the repo isn't indexed yet).

NOTE

call_hierarchy requires advertised language-server support and explicit declaration coordinates (file_path + line + column), not symbol lookup. If prepareCallHierarchy finds ambiguous overloads, Kompile returns the choices rather than guessing.


The fail-closed edit gate (lsp action=check) ​

lsp action=check is Kompile's semantic verification gate for touched files. Instead of returning a vague diagnostics dump, it produces a structured verdict per file per checking context, followed by an OVERALL verdict.

Verdict semantics ​

StatusMeaning
PASSChecked cleanly with zero errors
FAILReal compile/type errors reported by the language server (up to 25 errors reported per verdict)
NOT_CHECKEDCould not verify — reason is explicitly reported (TIMEOUT, CHANGED_DURING_CHECK, NO_SERVER, SERVER_ERROR, BUSY). Never treated as a pass and never disguised as a compile error.
NOT_APPLICABLEThat backend/compile database does not compile anything for this file

OVERALL PASS rules:

  • Every file in file_paths must have at least one PASS and zero FAIL or NOT_CHECKED verdicts.
  • A file that no backend/server checked fails the overall gate.

Checking contexts ​

ContextWhen Used
EXACTC/C++/CUDA source file with its own row in compile_commands.json
INCLUDERC/C++/CUDA header (.h, .hh, .hpp, .hxx, .cuh, .inl, .ipp, .tpp) checked through translation units that directly include it (max_dependents, 0 = all)
INFERREDHeader no TU includes, or a new source not yet in compile_commands.json (interpolated compile command — marked provisional, not CMake inclusion proof)
PROJECTAll non-C-family languages checked by their project language server (jdtls, pyright, rust-analyzer, tsserver, etc.)

Multi-backend C / C++ / CUDA (clangd) ​

For C, C++, and CUDA repos with multiple build configurations (e.g., CPU, CUDA, ARM), Kompile pools one clangd variant per compile database (root|language#variant):

  1. Auto-discovery: Reads <project>/.kompile/lsp-check.json (which maps named compileDatabases such as cpu and cuda to their compile_commands.json paths plus defaultBackends), or falls back automatically to compile_commands.json at the repo root or build/. You can ask the agent "Configure .kompile/lsp-check.json for our build-cpu and build-cuda compile databases as default backends" instead of writing it by hand.
  2. Per-call overrides:
    • backend=["cpu", "cuda"]: Makes those databases and a verdict on each mandatory.
    • compile_db=["NAME=PATH"]: Adds an ad-hoc compile database for the check.
  3. CUDA (nvcc) handling: Kompile automatically rewrites nvcc compile rows into clang CUDA frontend flags so clangd can type-check .cu / .cuh files. (Keep in mind: this checks clang's CUDA frontend, not nvcc device codegen.)

Staged overlay checking (check before writing to the tree) ​

Pass overlay=<dir> (and optional overlay_root=<dir>, defaulting to the project root) to send <dir>/<rel> as unsaved in-memory buffers for <overlay_root>/<rel>. This lets agents or review pipelines run full LSP verification on staged/candidate edits without modifying the working tree.

Tuning parameters & scope ​

  • timeout_ms: Per-check timeout (default 180000 ms / 3 min)
  • settle_ms: Diagnostics settle window after document sync (default 1500 ms)
  • jobs: Parallelism across files/backends
  • What check does not prove: Syntax and semantic type-checking only — it is not a substitute for build-graph inclusion, linking, or runtime test execution.

Safe refactoring (lsp action=rename) ​

rename is dry-run by default (dry_run=true):

  1. First call lsp action=rename with your target and new_name → Kompile asks the language server for the WorkspaceEdit and returns a per-file diff preview plus a summary.
  2. Review the preview, then re-run with dry_run=false (which also requires edit permission) to apply the edits atomically across files.

How Kompile manages language servers (LspServerManager) ​

  • Lazy startup & pooling: Servers start on first use and are pooled process-wide by root|language (or root|language#variant for compile-database variants).
  • Idle reaping: A background reaper stops idle servers after 10 minutes (or 30 minutes for Java / jdtls, whose initial project indexing is heavier).
  • Bounded crash restarts: Crashed servers auto-restart within a budget of 2 restarts per 10-minute window so a broken server never enters an infinite crash loop.
  • Logs: Server stderr is drained to ~/.kompile/logs/lsp/ for diagnostics.
  • Shutdown cleanup: All managed servers are torn down cleanly on session exit or restart.

Supported languages & custom overrides ​

Kompile ships built-in definitions for 45+ languages — the first installed binary in each fallback chain wins (run lsp action=servers server_action=list to see what is installed on your machine, or see Languages & Required Tools for exact install commands, root markers, and per-language build prerequisites):

  • JVM: Java (jdtls), Kotlin (kotlin-lsp | kotlin-language-server), Scala (metals), Groovy, Clojure
  • Systems / Native: C/C++/CUDA/ObjC (clangd | ccls), Rust (rust-analyzer), Go (gopls), Zig (zls), Swift (sourcekit-lsp), Fortran (fortls), C# (csharp-ls | OmniSharp), F# (fsautocomplete)
  • Scripting / Data: Python (pyright | basedpyright | pylsp | jedi-language-server), Ruby (ruby-lsp | solargraph), PHP (intelephense | phpactor), Lua, Perl, R, Julia, Bash, PowerShell
  • Functional: Haskell (hls), OCaml (ocamllsp), Elixir, Erlang (elp | erlang_ls), Gleam, Elm, Dart
  • Web & Config: TypeScript/JavaScript (typescript-language-server | vtsls), Vue, Svelte, Astro, HTML, CSS/SCSS/Less, GraphQL, JSON, YAML, TOML (taplo), XML (lemminx), Markdown (marksman), LaTeX (texlab), SQL, Dockerfile, Terraform, Nix (nil | nixd), CMake, Protobuf

Need a custom language-server binary or want to disable one? Ask the agent in chat (for example, "Switch Python LSP to basedpyright-langserver --stdio and disable the Markdown language server in ~/.kompile/lsp-servers.json"). Under the hood, per-user overrides live in ~/.kompile/lsp-servers.json (servers.<lang> supports enabled, command, alternatives, and filenames for extension-less files such as Dockerfile or CMakeLists.txt).

Next steps ​

Released under the Apache-2.0 License.