diff options
author | Seivan Heidari <[email protected]> | 2019-10-26 15:29:49 +0100 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-10-26 15:29:49 +0100 |
commit | 5957b851e4451050151722598fa1ff9d41ccf0ff (patch) | |
tree | 23b58b05d93d7471a61aca790f736533edf454c1 /editors | |
parent | 1aea7c83ac8259b9c7e10aedd7ed480e80464b85 (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')
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/scopes.ts | 38 |
2 files changed, 19 insertions, 24 deletions
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 @@ | |||
32 | }, | 32 | }, |
33 | "dependencies": { | 33 | "dependencies": { |
34 | "seedrandom": "^3.0.1", | 34 | "seedrandom": "^3.0.1", |
35 | "vscode-languageclient": "^5.3.0-next.4", | 35 | "vscode-languageclient": "^5.3.0-next.4" |
36 | "jsonc-parser": "^2.1.0" | ||
37 | }, | 36 | }, |
38 | "devDependencies": { | 37 | "devDependencies": { |
39 | "@types/glob": "^7.1.1", | 38 | "@types/glob": "^7.1.1", |
@@ -494,4 +493,4 @@ | |||
494 | } | 493 | } |
495 | ] | 494 | ] |
496 | } | 495 | } |
497 | } | 496 | } \ 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 @@ | |||
1 | import * as fs from 'fs' | 1 | import * as fs from 'fs' |
2 | import * as jsonc from 'jsonc-parser' | ||
3 | import * as path from 'path' | 2 | import * as path from 'path' |
4 | import * as vscode from 'vscode' | 3 | import * 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 |
46 | function loadThemeNamed(themeName: string) { | 45 | function 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 | ||
73 | function loadThemeFile(themePath: string) { | 67 | function 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) |