From 062d01bd2f5c3ab6de7747dc5028e66b81dac6f5 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Tue, 2 Jun 2026 17:52:14 +0900 Subject: feat(lsp): add config-driven LSP support (Roblox Luau via luau-lsp) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Language Server Protocol integration modeled on opencode's, wired for this codebase's plain-TypeScript tool/agent architecture. Core (@dispatch/core): - lsp/client.ts: LSP/JSON-RPC client over stdio (vscode-jsonrpc) with the initialize handshake, didOpen/didChange sync, push + pull diagnostics (textDocument/diagnostic, workspace/diagnostic), and a generic request() passthrough for hover/definition/references/documentSymbol. - lsp/server.ts: resolves dispatch.toml [lsp] entries into spawn specs. Config-driven only — no builtin registry, no auto-download. - lsp/manager.ts: process-wide LspManager owning client lifecycles, keyed by root+serverID, lazy spawn + reuse + graceful shutdown. - lsp/language.ts: extension->languageId map incl. .luau -> "luau". - lsp/diagnostic.ts: error-only block formatting (1-based). - tools/lsp.ts: on-demand 'lsp' tool (1-based coords -> 0-based wire). - write-file.ts: optional onAfterWrite hook for diagnostics-on-write. - config schema: validate [lsp] block; DispatchConfig.lsp + LspServerConfig. API (@dispatch/api): - AgentManager owns one LspManager; per-working-directory server cache cleared on config reload; diagnostics appended to write_file results; 'lsp' tool gated by new perm_lsp setting; shutdownAll on destroy(). Config: - dispatch.toml: documented, commented [lsp.luau-lsp] Roblox example. Tests: fake-lsp-server fixture + client/manager/server/diagnostic/schema/ tool/write-hook suites, plus an opt-in real-binary luau-lsp smoke test (auto-skipped when luau-lsp is absent). 652 pass; biome + 3 typechecks green. --- dispatch.toml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'dispatch.toml') diff --git a/dispatch.toml b/dispatch.toml index 43e164a..9f09ef7 100644 --- a/dispatch.toml +++ b/dispatch.toml @@ -49,3 +49,45 @@ read = "allow" [permissions.external_directory] "~/*" = "ask" "/tmp/*" = "allow" + +# ─── Language Servers (LSP) ────────────────────────────────────── +# Optional. Declare LSP servers to give agents diagnostics (and, with the +# `lsp` tool, hover/definition/references) for the files they edit. This block +# is PROJECT-SCOPED: it is read from the `dispatch.toml` in a tab's effective +# working directory (re-consulted when you change the CWD). Config-driven only — +# there is no builtin server registry and no auto-download, so the executable +# in `command[0]` must already be on PATH. +# +# After `write_file` edits a file whose extension matches a server below, +# dispatch opens it through the server and appends any error diagnostics to the +# tool result ("LSP errors detected in this file, please fix: ..."). Grant the +# `perm_lsp` permission to also expose the on-demand `lsp` tool. +# +# The example below is the Roblox Luau setup using luau-lsp +# (https://github.com/JohnnyMorganz/luau-lsp). Uncomment and adapt for your +# project. luau-lsp's `sourcemap.autogenerate` makes luau-lsp run +# `rojo sourcemap --watch` itself, so `rojo` must be on PATH (or set +# `[lsp.luau-lsp.env]` PATH / luau-lsp's sourcemap.rojoPath accordingly). +# +# [lsp.luau-lsp] +# command = ["luau-lsp", "lsp", "--definitions=globalTypes.d.luau", "--docs=api-docs.json"] +# extensions = [".luau"] +# +# [lsp.luau-lsp.initialization.luau-lsp.platform] +# type = "roblox" +# +# [lsp.luau-lsp.initialization.luau-lsp.sourcemap] +# enabled = true +# autogenerate = true +# rojoProjectFile = "default.project.json" +# +# [lsp.luau-lsp.initialization.luau-lsp.types] +# roblox = true +# definitionFiles = ["globalTypes.d.luau"] +# documentationFiles = ["api-docs.json"] +# +# [lsp.luau-lsp.initialization.luau-lsp.diagnostics] +# strictDatamodelTypes = false +# +# [lsp.luau-lsp.initialization.luau-lsp.completion.imports] +# useConst = true -- cgit v1.2.3