( provider: LspRuntimeProvider, )
| 22 | } |
| 23 | |
| 24 | function normalizeProvider( |
| 25 | provider: LspRuntimeProvider, |
| 26 | ): LspRuntimeProvider { |
| 27 | const id = toKey(provider?.id); |
| 28 | if (!id) throw new Error("LSP runtime provider requires a non-empty id"); |
| 29 | if (!provider.label || typeof provider.label !== "string") { |
| 30 | throw new Error(`LSP runtime provider ${id} requires a label`); |
| 31 | } |
| 32 | if (typeof provider.canHandle !== "function") { |
| 33 | throw new Error(`LSP runtime provider ${id} requires canHandle()`); |
| 34 | } |
| 35 | if (typeof provider.start !== "function") { |
| 36 | throw new Error(`LSP runtime provider ${id} requires start()`); |
| 37 | } |
| 38 | for (const method of [ |
| 39 | "resolveUris", |
| 40 | "checkInstallation", |
| 41 | "install", |
| 42 | "uninstall", |
| 43 | "getInstallCommand", |
| 44 | "getUninstallCommand", |
| 45 | "stop", |
| 46 | ] as const) { |
| 47 | if ( |
| 48 | provider[method] !== undefined && |
| 49 | typeof provider[method] !== "function" |
| 50 | ) { |
| 51 | throw new Error(`LSP runtime provider ${id} has invalid ${method}()`); |
| 52 | } |
| 53 | } |
| 54 | return { ...provider, id }; |
| 55 | } |
| 56 | |
| 57 | function getPriority(provider: LspRuntimeProvider): number { |
| 58 | const priority = Number(provider.priority); |
no test coverage detected