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

@@ -3,6 +3,7 @@ import * as path from "node:path";
import { pathToFileURL, fileURLToPath } from "node:url";
import { servers } from "../server.ts";
import type { ServerConfig } from "./types.ts";
import { UnsupportedExtensionError } from "./types.ts";
// Resolve File URI To Local Path
export function uriToPath(uri: string): string {
@@ -20,7 +21,7 @@ export function pickServer(filePath: string): ServerConfig {
const ext = path.extname(filePath).replace(/^\./, "");
const hit = servers.find((s) => s.match.includes(ext));
if (!hit) {
throw new Error(`No LSP server registered for extension ".${ext}"`);
throw new UnsupportedExtensionError(`.${ext}`);
}
return hit;
}