aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/scopes.ts
diff options
context:
space:
mode:
authorSeivan Heidari <[email protected]>2019-10-26 15:29:49 +0100
committerSeivan Heidari <[email protected]>2019-10-26 15:29:49 +0100
commit5957b851e4451050151722598fa1ff9d41ccf0ff (patch)
tree23b58b05d93d7471a61aca790f736533edf454c1 /editors/code/src/scopes.ts
parent1aea7c83ac8259b9c7e10aedd7ed480e80464b85 (diff)
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
Diffstat (limited to 'editors/code/src/scopes.ts')
-rw-r--r--editors/code/src/scopes.ts38
1 files changed, 17 insertions, 21 deletions
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 @@
1import * as fs from 'fs' 1import * as fs from 'fs'
2import * as jsonc from 'jsonc-parser'
3import * as path from 'path' 2import * as path from 'path'
4import * as vscode from 'vscode' 3import * as vscode from 'vscode'
5 4
@@ -44,26 +43,21 @@ export function load() {
44 43
45// Find current theme on disk 44// Find current theme on disk
46function loadThemeNamed(themeName: string) { 45function loadThemeNamed(themeName: string) {
47 for (const extension of vscode.extensions.all) {
48 const extensionPath: string = extension.extensionPath
49 const extensionPackageJsonPath: string = path.join(extensionPath, 'package.json')
50 if (!checkFileExists(extensionPackageJsonPath)) {
51 continue
52 }
53 const packageJsonText: string = readFileText(extensionPackageJsonPath)
54 const packageJson: any = jsonc.parse(packageJsonText)
55 if (packageJson.contributes && packageJson.contributes.themes) {
56 for (const theme of packageJson.contributes.themes) {
57 const id = theme.id || theme.label
58 if (id === themeName) {
59 const themeRelativePath: string = theme.path
60 const themeFullPath: string = path.join(extensionPath, themeRelativePath)
61 loadThemeFile(themeFullPath)
62 }
63 }
64 }
65 46
66 } 47 const themePaths = vscode.extensions.all
48 .filter(extension => extension.extensionKind === vscode.ExtensionKind.UI)
49 .filter(extension => extension.packageJSON.contributes)
50 .filter(extension => extension.packageJSON.contributes.themes)
51 .reduce((list, extension) => {
52 const paths = extension.packageJSON.contributes.themes
53 .filter((element: any) => (element.id || element.label) === themeName)
54 .map((element: any) => path.join(extension.extensionPath, element.path))
55 return list.concat(paths)
56 }, Array<string>());
57
58
59 themePaths.forEach(loadThemeFile);
60
67 const customization: any = vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations'); 61 const customization: any = vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations');
68 if (customization && customization.textMateRules) { 62 if (customization && customization.textMateRules) {
69 loadColors(customization.textMateRules) 63 loadColors(customization.textMateRules)
@@ -71,9 +65,11 @@ function loadThemeNamed(themeName: string) {
71} 65}
72 66
73function loadThemeFile(themePath: string) { 67function loadThemeFile(themePath: string) {
68
74 if (checkFileExists(themePath)) { 69 if (checkFileExists(themePath)) {
75 const themeContentText: string = readFileText(themePath) 70 const themeContentText: string = readFileText(themePath)
76 const themeContent: any = jsonc.parse(themeContentText) 71
72 const themeContent: any = JSON.parse(themeContentText)
77 73
78 if (themeContent && themeContent.tokenColors) { 74 if (themeContent && themeContent.tokenColors) {
79 loadColors(themeContent.tokenColors) 75 loadColors(themeContent.tokenColors)