refactor: replace string-matching error checks with custom error classes

This commit is contained in:
2026-04-30 08:27:13 -04:00
parent 81ed5c88b8
commit 7abe4efa02
4 changed files with 59 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ import type {
} from "vscode-languageserver-protocol";
import * as path from "node:path";
import type { ServerConfig } from "./types.ts";
import { ServerNotFoundError } from "./types.ts";
import { findRoot, pathToUri, uriToPath } from "./root.ts";
// Is On PATH - Returns true if `cmd` resolves to an executable via the
@@ -73,10 +74,7 @@ export class LspClient {
// letting spawn ENOENT surface as a generic error. It's the user's
// responsibility to have the server installed & on PATH.
if (!isOnPath(this.server.command)) {
throw new Error(
`LSP server binary "${this.server.command}" not found on PATH. ` +
`Install it and ensure it's on your PATH (required by server "${this.server.id}").`,
);
throw new ServerNotFoundError(this.server.command);
}
this.proc = spawn(this.server.command, this.server.args, {
stdio: ["pipe", "pipe", "pipe"],