From e03a96e539d354345cd6328ddc5c7638398d3e14 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Wed, 24 Jun 2026 19:15:17 +0900 Subject: fix(tool-edit-file): wrap getService in try/catch to prevent activation crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The per-edit diagnostics change (8f6114b) called host.getService(lspServiceHandle) during activate(). But getService THROWS when a service has no provider — so if the LSP extension activates AFTER tool-edit-file (or isn't loaded at all), the activate() function crashes and the edit_file tool is NEVER REGISTERED. This is why the edit_file tool was missing from the agent toolset. Fix: wrap getService in try/catch — if the LSP service isn't available yet, lspService becomes undefined and edits proceed without diagnostics (the graceful degradation the comment always promised but the code didn't deliver). --- packages/tool-edit-file/src/extension.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/tool-edit-file/src/extension.ts b/packages/tool-edit-file/src/extension.ts index bbd8256..9be53da 100644 --- a/packages/tool-edit-file/src/extension.ts +++ b/packages/tool-edit-file/src/extension.ts @@ -1,5 +1,5 @@ import type { Extension } from "@dispatch/kernel"; -import { lspServiceHandle } from "@dispatch/lsp"; +import { type LspService, lspServiceHandle } from "@dispatch/lsp"; import { createEditFileTool, type DiagnosticsHook } from "./edit-file.js"; export const extension: Extension = { @@ -14,10 +14,16 @@ export const extension: Extension = { contributes: { tools: ["edit_file"] }, }, activate(host) { - // Optional LSP integration: if the lsp extension is loaded, wire its - // getDiagnostics service as the post-edit diagnostics hook. If absent, - // edits proceed without diagnostics (graceful degradation). - const lspService = host.getService(lspServiceHandle); + // Optional LSP integration: if the lsp extension is loaded AND has + // activated before us, wire its getDiagnostics service as the post-edit + // diagnostics hook. If absent (not loaded, or activates after us), edits + // proceed without diagnostics (graceful degradation). + let lspService: LspService | undefined; + try { + lspService = host.getService(lspServiceHandle); + } catch { + lspService = undefined; + } const diagnostics: DiagnosticsHook | undefined = lspService ? async (opts) => lspService.getDiagnostics({ -- cgit v1.2.3