( settings: RuntimeSettings, context: LspRuntimeContext, )
| 22 | } |
| 23 | |
| 24 | function getWorkspaceRuntimeOverride( |
| 25 | settings: RuntimeSettings, |
| 26 | context: LspRuntimeContext, |
| 27 | ): string | null { |
| 28 | const workspaces = settings.workspaces; |
| 29 | if (!workspaces || typeof workspaces !== "object") return null; |
| 30 | |
| 31 | const candidates = [ |
| 32 | context.rootUri, |
| 33 | context.file?.uri, |
| 34 | context.uri, |
| 35 | context.documentUri, |
| 36 | ] |
| 37 | .map((uri) => String(uri || "")) |
| 38 | .filter(Boolean); |
| 39 | |
| 40 | let bestMatch = ""; |
| 41 | let bestRuntime: string | null = null; |
| 42 | for (const [prefix, runtimeId] of Object.entries(workspaces)) { |
| 43 | const normalizedPrefix = String(prefix || ""); |
| 44 | if (!normalizedPrefix) continue; |
| 45 | if ( |
| 46 | normalizedPrefix.length > bestMatch.length && |
| 47 | candidates.some((uri) => uri.startsWith(normalizedPrefix)) |
| 48 | ) { |
| 49 | bestMatch = normalizedPrefix; |
| 50 | bestRuntime = toRuntimeId(runtimeId); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return bestRuntime; |
| 55 | } |
| 56 | |
| 57 | export function getConfiguredRuntimeId( |
| 58 | server: LspServerDefinition, |
no test coverage detected