summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-24 19:15:17 +0900
committerAdam Malczewski <[email protected]>2026-06-24 19:15:17 +0900
commite03a96e539d354345cd6328ddc5c7638398d3e14 (patch)
treebff49806ed664d0b87f13199558f0e9f1794e14f /packages
parent94363d4e5b4fe7f026e06b65fb847342224428d8 (diff)
downloaddispatch-e03a96e539d354345cd6328ddc5c7638398d3e14.tar.gz
dispatch-e03a96e539d354345cd6328ddc5c7638398d3e14.zip
fix(tool-edit-file): wrap getService in try/catch to prevent activation crash
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).
Diffstat (limited to 'packages')
-rw-r--r--packages/tool-edit-file/src/extension.ts16
1 files 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({