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
This commit is contained in:
Seivan Heidari 2019-10-26 16:29:49 +02:00
parent 1aea7c83ac
commit 5957b851e4
2 changed files with 19 additions and 24 deletions

View File

@ -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 @@
}
]
}
}
}

View File

@ -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<string>());
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)