]> git.lizzy.rs Git - rust.git/commitdiff
Rename file
authorAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 31 Dec 2019 08:41:16 +0000 (09:41 +0100)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 31 Dec 2019 13:06:40 +0000 (14:06 +0100)
editors/code/src/highlighting.ts
editors/code/src/load_theme_colors.ts [new file with mode: 0644]
editors/code/src/scopes.ts [deleted file]
editors/code/src/scopes_mapper.ts

index 5e9cbe0de7612f1015cb8bd076e648e8eebddb49..e97eb086a7c2368291d97a0db91ef66d896936a2 100644 (file)
@@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient';
 import * as seedrandom_ from 'seedrandom';
 const seedrandom = seedrandom_; // https://github.com/jvandemo/generator-angular2-library/issues/221#issuecomment-355945207
 
-import { loadThemeColors, TextMateRuleSettings } from './scopes';
+import { loadThemeColors, TextMateRuleSettings } from './load_theme_colors';
 import * as scopesMapper from './scopes_mapper';
 
 import { Ctx } from './ctx';
diff --git a/editors/code/src/load_theme_colors.ts b/editors/code/src/load_theme_colors.ts
new file mode 100644 (file)
index 0000000..73fabbf
--- /dev/null
@@ -0,0 +1,108 @@
+import * as fs from 'fs';
+import * as jsonc from 'jsonc-parser';
+import * as path from 'path';
+import * as vscode from 'vscode';
+
+export interface TextMateRuleSettings {
+    foreground?: string;
+    background?: string;
+    fontStyle?: string;
+}
+
+// Load all textmate scopes in the currently active theme
+export function loadThemeColors(): Map<string, TextMateRuleSettings> {
+    // Find out current color theme
+    const themeName = vscode.workspace
+        .getConfiguration('workbench')
+        .get('colorTheme');
+
+    if (typeof themeName !== 'string') {
+        // console.warn('workbench.colorTheme is', themeName)
+        return new Map();
+    }
+    return loadThemeNamed(themeName);
+}
+
+function loadThemeNamed(themeName: string): Map<string, TextMateRuleSettings> {
+    function isTheme(extension: vscode.Extension<any>): boolean {
+        return (
+            extension.extensionKind === vscode.ExtensionKind.UI &&
+            extension.packageJSON.contributes &&
+            extension.packageJSON.contributes.themes
+        );
+    }
+
+    let themePaths = vscode.extensions.all
+        .filter(isTheme)
+        .flatMap(ext => {
+            return ext.packageJSON.contributes.themes
+                .filter((it: any) => (it.id || it.label) === themeName)
+                .map((it: any) => path.join(ext.extensionPath, it.path));
+        })
+
+    const res = new Map();
+    for (const themePath of themePaths) {
+        mergeInto(res, loadThemeFile(themePath))
+    }
+
+    const customizations: any = vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations');
+    mergeInto(res, loadColors(customizations?.textMateRules ?? []))
+
+    return res;
+}
+
+function loadThemeFile(themePath: string): Map<string, TextMateRuleSettings> {
+    let text;
+    try {
+        text = fs.readFileSync(themePath, 'utf8')
+    } catch {
+        return new Map();
+    }
+    const obj = jsonc.parse(text);
+    const tokenColors = obj?.tokenColors ?? [];
+    const res = loadColors(tokenColors);
+
+    for (const include in obj?.include ?? []) {
+        const includePath = path.join(path.dirname(themePath), include);
+        const tmp = loadThemeFile(includePath);
+        mergeInto(res, tmp);
+    }
+
+    return res;
+}
+
+interface TextMateRule {
+    scope: string | string[];
+    settings: TextMateRuleSettings;
+}
+
+function loadColors(textMateRules: TextMateRule[]): Map<string, TextMateRuleSettings> {
+    const res = new Map();
+    for (const rule of textMateRules) {
+        const scopes = typeof rule.scope === 'string'
+            ? [rule.scope]
+            : rule.scope;
+        for (const scope of scopes) {
+            res.set(scope, rule.settings)
+        }
+    }
+    return res
+}
+
+function mergeRuleSettings(
+    defaultSetting: TextMateRuleSettings | undefined,
+    override: TextMateRuleSettings,
+): TextMateRuleSettings {
+    return {
+        foreground: defaultSetting?.foreground ?? override.foreground,
+        background: defaultSetting?.background ?? override.background,
+        fontStyle: defaultSetting?.fontStyle ?? override.fontStyle,
+    }
+}
+
+function mergeInto(dst: Map<string, TextMateRuleSettings>, addition: Map<string, TextMateRuleSettings>) {
+    addition.forEach((value, key) => {
+        const merged = mergeRuleSettings(dst.get(key), value)
+        dst.set(key, merged)
+    })
+}
diff --git a/editors/code/src/scopes.ts b/editors/code/src/scopes.ts
deleted file mode 100644 (file)
index 73fabbf..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-import * as fs from 'fs';
-import * as jsonc from 'jsonc-parser';
-import * as path from 'path';
-import * as vscode from 'vscode';
-
-export interface TextMateRuleSettings {
-    foreground?: string;
-    background?: string;
-    fontStyle?: string;
-}
-
-// Load all textmate scopes in the currently active theme
-export function loadThemeColors(): Map<string, TextMateRuleSettings> {
-    // Find out current color theme
-    const themeName = vscode.workspace
-        .getConfiguration('workbench')
-        .get('colorTheme');
-
-    if (typeof themeName !== 'string') {
-        // console.warn('workbench.colorTheme is', themeName)
-        return new Map();
-    }
-    return loadThemeNamed(themeName);
-}
-
-function loadThemeNamed(themeName: string): Map<string, TextMateRuleSettings> {
-    function isTheme(extension: vscode.Extension<any>): boolean {
-        return (
-            extension.extensionKind === vscode.ExtensionKind.UI &&
-            extension.packageJSON.contributes &&
-            extension.packageJSON.contributes.themes
-        );
-    }
-
-    let themePaths = vscode.extensions.all
-        .filter(isTheme)
-        .flatMap(ext => {
-            return ext.packageJSON.contributes.themes
-                .filter((it: any) => (it.id || it.label) === themeName)
-                .map((it: any) => path.join(ext.extensionPath, it.path));
-        })
-
-    const res = new Map();
-    for (const themePath of themePaths) {
-        mergeInto(res, loadThemeFile(themePath))
-    }
-
-    const customizations: any = vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations');
-    mergeInto(res, loadColors(customizations?.textMateRules ?? []))
-
-    return res;
-}
-
-function loadThemeFile(themePath: string): Map<string, TextMateRuleSettings> {
-    let text;
-    try {
-        text = fs.readFileSync(themePath, 'utf8')
-    } catch {
-        return new Map();
-    }
-    const obj = jsonc.parse(text);
-    const tokenColors = obj?.tokenColors ?? [];
-    const res = loadColors(tokenColors);
-
-    for (const include in obj?.include ?? []) {
-        const includePath = path.join(path.dirname(themePath), include);
-        const tmp = loadThemeFile(includePath);
-        mergeInto(res, tmp);
-    }
-
-    return res;
-}
-
-interface TextMateRule {
-    scope: string | string[];
-    settings: TextMateRuleSettings;
-}
-
-function loadColors(textMateRules: TextMateRule[]): Map<string, TextMateRuleSettings> {
-    const res = new Map();
-    for (const rule of textMateRules) {
-        const scopes = typeof rule.scope === 'string'
-            ? [rule.scope]
-            : rule.scope;
-        for (const scope of scopes) {
-            res.set(scope, rule.settings)
-        }
-    }
-    return res
-}
-
-function mergeRuleSettings(
-    defaultSetting: TextMateRuleSettings | undefined,
-    override: TextMateRuleSettings,
-): TextMateRuleSettings {
-    return {
-        foreground: defaultSetting?.foreground ?? override.foreground,
-        background: defaultSetting?.background ?? override.background,
-        fontStyle: defaultSetting?.fontStyle ?? override.fontStyle,
-    }
-}
-
-function mergeInto(dst: Map<string, TextMateRuleSettings>, addition: Map<string, TextMateRuleSettings>) {
-    addition.forEach((value, key) => {
-        const merged = mergeRuleSettings(dst.get(key), value)
-        dst.set(key, merged)
-    })
-}
index e738fa2396d6c9f7fe22a3dbaca3147fcc1d9e0d..1295ab4768147e68b6f7f70e104184b900ba864c 100644 (file)
@@ -1,5 +1,5 @@
 import * as vscode from 'vscode';
-import { TextMateRuleSettings } from './scopes';
+import { TextMateRuleSettings } from './load_theme_colors';
 
 let mappings = new Map<string, string[]>();