From 5957b851e4451050151722598fa1ff9d41ccf0ff Mon Sep 17 00:00:00 2001 From: Seivan Heidari Date: Sat, 26 Oct 2019 16:29:49 +0200 Subject: Refactor how themes are found in packages without relying on parsing JSONC. However, there is still an issue where themes could have been defined in JSONC - but so far with testing very few of them actually do. The issue was in loading packages and now we're letting VSCode tackle that. Fix: https://github.com/rust-analyzer/rust-analyzer/pull/2061#discussion_r339015610 --- editors/code/package.json | 5 ++--- editors/code/src/scopes.ts | 38 +++++++++++++++++--------------------- 2 files changed, 19 insertions(+), 24 deletions(-) (limited to 'editors') diff --git a/editors/code/package.json b/editors/code/package.json index 46b8cd47c..b7ea9fa6f 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -32,8 +32,7 @@ }, "dependencies": { "seedrandom": "^3.0.1", - "vscode-languageclient": "^5.3.0-next.4", - "jsonc-parser": "^2.1.0" + "vscode-languageclient": "^5.3.0-next.4" }, "devDependencies": { "@types/glob": "^7.1.1", @@ -494,4 +493,4 @@ } ] } -} +} \ No newline at end of file diff --git a/editors/code/src/scopes.ts b/editors/code/src/scopes.ts index 607b8b2dd..c9c01ba1d 100644 --- a/editors/code/src/scopes.ts +++ b/editors/code/src/scopes.ts @@ -1,5 +1,4 @@ import * as fs from 'fs' -import * as jsonc from 'jsonc-parser' import * as path from 'path' import * as vscode from 'vscode' @@ -44,26 +43,21 @@ export function load() { // Find current theme on disk function loadThemeNamed(themeName: string) { - for (const extension of vscode.extensions.all) { - const extensionPath: string = extension.extensionPath - const extensionPackageJsonPath: string = path.join(extensionPath, 'package.json') - if (!checkFileExists(extensionPackageJsonPath)) { - continue - } - const packageJsonText: string = readFileText(extensionPackageJsonPath) - const packageJson: any = jsonc.parse(packageJsonText) - if (packageJson.contributes && packageJson.contributes.themes) { - for (const theme of packageJson.contributes.themes) { - const id = theme.id || theme.label - if (id === themeName) { - const themeRelativePath: string = theme.path - const themeFullPath: string = path.join(extensionPath, themeRelativePath) - loadThemeFile(themeFullPath) - } - } - } - } + const themePaths = vscode.extensions.all + .filter(extension => extension.extensionKind === vscode.ExtensionKind.UI) + .filter(extension => extension.packageJSON.contributes) + .filter(extension => extension.packageJSON.contributes.themes) + .reduce((list, extension) => { + const paths = extension.packageJSON.contributes.themes + .filter((element: any) => (element.id || element.label) === themeName) + .map((element: any) => path.join(extension.extensionPath, element.path)) + return list.concat(paths) + }, Array()); + + + themePaths.forEach(loadThemeFile); + const customization: any = vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations'); if (customization && customization.textMateRules) { loadColors(customization.textMateRules) @@ -71,9 +65,11 @@ function loadThemeNamed(themeName: string) { } function loadThemeFile(themePath: string) { + if (checkFileExists(themePath)) { const themeContentText: string = readFileText(themePath) - const themeContent: any = jsonc.parse(themeContentText) + + const themeContent: any = JSON.parse(themeContentText) if (themeContent && themeContent.tokenColors) { loadColors(themeContent.tokenColors) -- cgit v1.2.3