mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-31 17:12:53 +00:00
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:
parent
1aea7c83ac
commit
5957b851e4
@ -32,8 +32,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"seedrandom": "^3.0.1",
|
"seedrandom": "^3.0.1",
|
||||||
"vscode-languageclient": "^5.3.0-next.4",
|
"vscode-languageclient": "^5.3.0-next.4"
|
||||||
"jsonc-parser": "^2.1.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/glob": "^7.1.1",
|
"@types/glob": "^7.1.1",
|
||||||
@ -494,4 +493,4 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as jsonc from 'jsonc-parser'
|
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as vscode from 'vscode'
|
import * as vscode from 'vscode'
|
||||||
|
|
||||||
@ -44,26 +43,21 @@ export function load() {
|
|||||||
|
|
||||||
// Find current theme on disk
|
// Find current theme on disk
|
||||||
function loadThemeNamed(themeName: string) {
|
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');
|
const customization: any = vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations');
|
||||||
if (customization && customization.textMateRules) {
|
if (customization && customization.textMateRules) {
|
||||||
loadColors(customization.textMateRules)
|
loadColors(customization.textMateRules)
|
||||||
@ -71,9 +65,11 @@ function loadThemeNamed(themeName: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadThemeFile(themePath: string) {
|
function loadThemeFile(themePath: string) {
|
||||||
|
|
||||||
if (checkFileExists(themePath)) {
|
if (checkFileExists(themePath)) {
|
||||||
const themeContentText: string = readFileText(themePath)
|
const themeContentText: string = readFileText(themePath)
|
||||||
const themeContent: any = jsonc.parse(themeContentText)
|
|
||||||
|
const themeContent: any = JSON.parse(themeContentText)
|
||||||
|
|
||||||
if (themeContent && themeContent.tokenColors) {
|
if (themeContent && themeContent.tokenColors) {
|
||||||
loadColors(themeContent.tokenColors)
|
loadColors(themeContent.tokenColors)
|
||||||
|
Loading…
Reference in New Issue
Block a user