()
| 33 | } |
| 34 | |
| 35 | export async function getTheme() { |
| 36 | let currentTheme = undefined |
| 37 | const colorTheme = vscode.workspace.getConfiguration("workbench").get<string>("colorTheme") || "Default Dark Modern" |
| 38 | |
| 39 | try { |
| 40 | for (let i = vscode.extensions.all.length - 1; i >= 0; i--) { |
| 41 | if (currentTheme) { |
| 42 | break |
| 43 | } |
| 44 | const extension = vscode.extensions.all[i] |
| 45 | if (extension.packageJSON?.contributes?.themes?.length > 0) { |
| 46 | for (const theme of extension.packageJSON.contributes.themes) { |
| 47 | if (theme.label === colorTheme) { |
| 48 | const themePath = path.join(extension.extensionPath, theme.path) |
| 49 | currentTheme = await fs.readFile(themePath, "utf-8") |
| 50 | break |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | if (currentTheme === undefined && defaultThemes[colorTheme]) { |
| 57 | const filename = `${defaultThemes[colorTheme]}.json` |
| 58 | currentTheme = await fs.readFile( |
| 59 | path.join(getExtensionUri().fsPath, "integrations", "theme", "default-themes", filename), |
| 60 | "utf-8", |
| 61 | ) |
| 62 | } |
| 63 | |
| 64 | // Strip comments from theme |
| 65 | let parsed = parseThemeString(currentTheme) |
| 66 | |
| 67 | if (parsed.include) { |
| 68 | const includeThemeString = await fs.readFile( |
| 69 | path.join(getExtensionUri().fsPath, "integrations", "theme", "default-themes", parsed.include), |
| 70 | "utf-8", |
| 71 | ) |
| 72 | const includeTheme = parseThemeString(includeThemeString) |
| 73 | parsed = mergeJson(parsed, includeTheme) |
| 74 | } |
| 75 | |
| 76 | const converted = convertTheme(parsed) |
| 77 | |
| 78 | converted.base = ( |
| 79 | ["vs", "hc-black"].includes(converted.base) |
| 80 | ? converted.base |
| 81 | : colorTheme.includes("Light") |
| 82 | ? "vs" |
| 83 | : "vs-dark" |
| 84 | ) as any |
| 85 | |
| 86 | return converted |
| 87 | } catch (e) { |
| 88 | console.log("Error loading color theme: ", e) |
| 89 | } |
| 90 | return undefined |
| 91 | } |
| 92 |
no test coverage detected