diff options
| -rw-r--r-- | packages/tool-edit-file/src/extension.ts | 16 |
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({ |
