From 83a33fbbeae9cbec8bec855e9338b7ccd08bd3a0 Mon Sep 17 00:00:00 2001 From: Seivan Heidari Date: Sat, 9 Nov 2019 17:23:30 +0100 Subject: Vscode wasn't running the linter automatically so ran `npm run fix` - wonder if it's related to `tslint` being deprecated. --- editors/code/src/scopes.ts | 60 +++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'editors/code/src/scopes.ts') diff --git a/editors/code/src/scopes.ts b/editors/code/src/scopes.ts index a6138fad0..98099872c 100644 --- a/editors/code/src/scopes.ts +++ b/editors/code/src/scopes.ts @@ -2,8 +2,6 @@ import * as fs from 'fs'; import * as path from 'path'; import * as vscode from 'vscode'; - - export interface TextMateRule { scope: string | string[]; settings: TextMateRuleSettings; @@ -27,7 +25,9 @@ export function load() { // Remove any previous theme rules.clear(); // Find out current color theme - const themeName = vscode.workspace.getConfiguration('workbench').get('colorTheme'); + const themeName = vscode.workspace + .getConfiguration('workbench') + .get('colorTheme'); if (typeof themeName !== 'string') { // console.warn('workbench.colorTheme is', themeName) @@ -42,38 +42,43 @@ export function load() { } function filterThemeExtensions(extension: vscode.Extension): boolean { - return extension.extensionKind === vscode.ExtensionKind.UI && + return ( + extension.extensionKind === vscode.ExtensionKind.UI && extension.packageJSON.contributes && - extension.packageJSON.contributes.themes; + extension.packageJSON.contributes.themes + ); } - - // Find current theme on disk function loadThemeNamed(themeName: string) { - const themePaths = vscode.extensions.all .filter(filterThemeExtensions) .reduce((list, extension) => { return extension.packageJSON.contributes.themes - .filter((element: any) => (element.id || element.label) === themeName) - .map((element: any) => path.join(extension.extensionPath, element.path)) - .concat(list) + .filter( + (element: any) => + (element.id || element.label) === themeName + ) + .map((element: any) => + path.join(extension.extensionPath, element.path) + ) + .concat(list); }, Array()); - themePaths.forEach(loadThemeFile); - const tokenColorCustomizations: [any] = [vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations')] + const tokenColorCustomizations: [any] = [ + vscode.workspace + .getConfiguration('editor') + .get('tokenColorCustomizations') + ]; tokenColorCustomizations .filter(custom => custom && custom.textMateRules) .map(custom => custom.textMateRules) .forEach(loadColors); - } - function loadThemeFile(themePath: string) { const themeContent = [themePath] .filter(isFile) @@ -92,18 +97,26 @@ function loadThemeFile(themePath: string) { .forEach(loadThemeFile); } -function mergeRuleSettings(defaultSetting: TextMateRuleSettings | undefined, override: TextMateRuleSettings): TextMateRuleSettings { - if (defaultSetting === undefined) { return override; } +function mergeRuleSettings( + defaultSetting: TextMateRuleSettings | undefined, + override: TextMateRuleSettings +): TextMateRuleSettings { + if (defaultSetting === undefined) { + return override; + } const mergedRule = defaultSetting; mergedRule.background = override.background || defaultSetting.background; mergedRule.foreground = override.foreground || defaultSetting.foreground; mergedRule.fontStyle = override.fontStyle || defaultSetting.foreground; - return mergedRule + return mergedRule; } -function updateRules(scope: string, updatedSettings: TextMateRuleSettings): void { +function updateRules( + scope: string, + updatedSettings: TextMateRuleSettings +): void { [rules.get(scope)] .map(settings => mergeRuleSettings(settings, updatedSettings)) .forEach(settings => rules.set(scope, settings)); @@ -113,11 +126,10 @@ function loadColors(textMateRules: TextMateRule[]): void { textMateRules.forEach(rule => { if (typeof rule.scope === 'string') { updateRules(rule.scope, rule.settings); - } - else if (rule.scope instanceof Array) { + } else if (rule.scope instanceof Array) { rule.scope.forEach(scope => updateRules(scope, rule.settings)); } - }) + }); } function isFile(filePath: string): boolean { @@ -128,7 +140,7 @@ function readFileText(filePath: string): string { return fs.readFileSync(filePath, 'utf8'); } -// Might need to replace with JSONC if a theme contains comments. +// Might need to replace with JSONC if a theme contains comments. function parseJSON(content: string): any { return JSON.parse(content); -} \ No newline at end of file +} -- cgit v1.2.3