about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorSeivan Heidari <seivan.heidari@icloud.com>2019-11-09 17:23:30 +0100
committerSeivan Heidari <seivan.heidari@icloud.com>2019-11-09 17:23:30 +0100
commit83a33fbbeae9cbec8bec855e9338b7ccd08bd3a0 (patch)
tree7378bc3b85599264027eaab28ff017ed933fb984 /editors/code/src
parent529b227d42951feabf64c8c964b00e726dd92d46 (diff)
downloadrust-83a33fbbeae9cbec8bec855e9338b7ccd08bd3a0.tar.gz
rust-83a33fbbeae9cbec8bec855e9338b7ccd08bd3a0.zip
Vscode wasn't running the linter automatically so ran `npm run fix` - wonder if it's related to `tslint` being deprecated.
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/config.ts5
-rw-r--r--editors/code/src/extension.ts10
-rw-r--r--editors/code/src/highlighting.ts81
-rw-r--r--editors/code/src/scopes.ts60
-rw-r--r--editors/code/src/scopes_mapper.ts58
5 files changed, 109 insertions, 105 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 234a390acff..4cedbea4661 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -46,14 +46,14 @@ export class Config {
 
     public userConfigChanged() {
         const config = vscode.workspace.getConfiguration('rust-analyzer');
-        
+
         Server.highlighter.removeHighlights();
 
         if (config.has('highlightingOn')) {
             this.highlightingOn = config.get('highlightingOn') as boolean;
             if (this.highlightingOn) {
                 scopes.load();
-                scopesMapper.load();    
+                scopesMapper.load();
             }
         }
 
@@ -63,7 +63,6 @@ export class Config {
             ) as boolean;
         }
 
-
         if (config.has('enableEnhancedTyping')) {
             this.enableEnhancedTyping = config.get(
                 'enableEnhancedTyping'
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index 07a5c59e81e..c06928d122b 100644
--- a/editors/code/src/extension.ts
+++ b/editors/code/src/extension.ts
@@ -91,11 +91,11 @@ export function activate(context: vscode.ExtensionContext) {
     const allNotifications: Iterable<
         [string, lc.GenericNotificationHandler]
     > = [
-            [
-                'rust-analyzer/publishDecorations',
-                notifications.publishDecorations.handle
-            ]
-        ];
+        [
+            'rust-analyzer/publishDecorations',
+            notifications.publishDecorations.handle
+        ]
+    ];
     const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
 
     // The events below are plain old javascript events, triggered and handled by vscode
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index ee39ca64c87..14199dbeae6 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -25,35 +25,15 @@ function fancify(seed: string, shade: 'light' | 'dark') {
     return `hsl(${h},${s}%,${l}%)`;
 }
 
-
-function createDecorationFromTextmate(themeStyle: scopes.TextMateRuleSettings): vscode.TextEditorDecorationType {
-    const options: vscode.DecorationRenderOptions = {};
-    options.rangeBehavior = vscode.DecorationRangeBehavior.OpenOpen;
-    if (themeStyle.foreground) {
-        options.color = themeStyle.foreground;
-    }
-    if (themeStyle.background) {
-        options.backgroundColor = themeStyle.background;
-    }
-    if (themeStyle.fontStyle) {
-        const parts: string[] = themeStyle.fontStyle.split(' ');
-        parts.forEach((part) => {
-            switch (part) {
-                case 'italic':
-                    options.fontStyle = 'italic';
-                    break;
-                case 'bold':
-                    options.fontWeight = 'bold';
-                    break;
-                case 'underline':
-                    options.textDecoration = 'underline';
-                    break;
-                default:
-                    break;
-            }
-        })
-    }
-    return vscode.window.createTextEditorDecorationType(options);
+function createDecorationFromTextmate(
+    themeStyle: scopes.TextMateRuleSettings
+): vscode.TextEditorDecorationType {
+    const decorationOptions: vscode.DecorationRenderOptions = {};
+    decorationOptions.rangeBehavior = vscode.DecorationRangeBehavior.OpenOpen;
+    decorationOptions.color = themeStyle.foreground;
+    decorationOptions.backgroundColor = themeStyle.background;
+    decorationOptions.fontStyle = themeStyle.fontStyle;
+    return vscode.window.createTextEditorDecorationType(decorationOptions);
 }
 
 export class Highlighter {
@@ -65,14 +45,12 @@ export class Highlighter {
             tag: string,
             textDecoration?: string
         ): [string, vscode.TextEditorDecorationType] => {
-
             const rule = scopesMapper.toRule(tag, scopes.find);
 
             if (rule) {
                 const decor = createDecorationFromTextmate(rule);
                 return [tag, decor];
-            }
-            else {
+            } else {
                 const fallBackTag = 'ralsp.' + tag;
                 // console.log(' ');
                 // console.log('Missing theme for: <"' + tag + '"> for following mapped scopes:');
@@ -91,25 +69,25 @@ export class Highlighter {
         const decorations: Iterable<
             [string, vscode.TextEditorDecorationType]
         > = [
-                decoration('comment'),
-                decoration('string'),
-                decoration('keyword'),
-                decoration('keyword.control'),
-                decoration('keyword.unsafe'),
-                decoration('function'),
-                decoration('parameter'),
-                decoration('constant'),
-                decoration('type'),
-                decoration('builtin'),
-                decoration('text'),
-                decoration('attribute'),
-                decoration('literal'),
-                decoration('macro'),
-                decoration('variable'),
-                decoration('variable.mut', 'underline'),
-                decoration('field'),
-                decoration('module')
-            ];
+            decoration('comment'),
+            decoration('string'),
+            decoration('keyword'),
+            decoration('keyword.control'),
+            decoration('keyword.unsafe'),
+            decoration('function'),
+            decoration('parameter'),
+            decoration('constant'),
+            decoration('type'),
+            decoration('builtin'),
+            decoration('text'),
+            decoration('attribute'),
+            decoration('literal'),
+            decoration('macro'),
+            decoration('variable'),
+            decoration('variable.mut', 'underline'),
+            decoration('field'),
+            decoration('module')
+        ];
 
         return new Map<string, vscode.TextEditorDecorationType>(decorations);
     }
@@ -138,7 +116,6 @@ export class Highlighter {
         // Note: decoration objects need to be kept around so we can dispose them
         // if the user disables syntax highlighting
 
-
         if (this.decorations == null) {
             this.decorations = Highlighter.initDecorations();
         }
diff --git a/editors/code/src/scopes.ts b/editors/code/src/scopes.ts
index a6138fad05c..98099872cc7 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<any>): 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<string>());
 
-
     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
+}
diff --git a/editors/code/src/scopes_mapper.ts b/editors/code/src/scopes_mapper.ts
index dfb8bf217e2..85c791ff509 100644
--- a/editors/code/src/scopes_mapper.ts
+++ b/editors/code/src/scopes_mapper.ts
@@ -1,17 +1,25 @@
 import * as vscode from 'vscode';
 import { TextMateRuleSettings } from './scopes';
 
-
-
 let mappings = new Map<string, string[]>();
 
-
 const defaultMapping = new Map<string, string[]>([
-    ['comment', ['comment', 'comment.block', 'comment.line', 'comment.block.documentation']],
+    [
+        'comment',
+        [
+            'comment',
+            'comment.block',
+            'comment.line',
+            'comment.block.documentation'
+        ]
+    ],
     ['string', ['string']],
     ['keyword', ['keyword']],
     ['keyword.control', ['keyword.control', 'keyword', 'keyword.other']],
-    ['keyword.unsafe', ['storage.modifier', 'keyword.other', 'keyword.control', 'keyword']],
+    [
+        'keyword.unsafe',
+        ['storage.modifier', 'keyword.other', 'keyword.control', 'keyword']
+    ],
     ['function', ['entity.name.function']],
     ['parameter', ['variable.parameter']],
     ['constant', ['constant', 'variable']],
@@ -23,21 +31,32 @@ const defaultMapping = new Map<string, string[]>([
     ['macro', ['support.other']],
     ['variable', ['variable']],
     ['variable.mut', ['variable', 'storage.modifier']],
-    ['field', ['variable.object.property', 'meta.field.declaration', 'meta.definition.property', 'variable.other',]],
+    [
+        'field',
+        [
+            'variable.object.property',
+            'meta.field.declaration',
+            'meta.definition.property',
+            'variable.other'
+        ]
+    ],
     ['module', ['entity.name.section', 'entity.other']]
-]
-);
+]);
 
-// Temporary exported for debugging for now. 
+// Temporary exported for debugging for now.
 export function find(scope: string): string[] {
     return mappings.get(scope) || [];
 }
 
-export function toRule(scope: string, intoRule: (scope: string) => TextMateRuleSettings | undefined): TextMateRuleSettings | undefined {
-    return find(scope).map(intoRule).filter(rule => rule !== undefined)[0];
+export function toRule(
+    scope: string,
+    intoRule: (scope: string) => TextMateRuleSettings | undefined
+): TextMateRuleSettings | undefined {
+    return find(scope)
+        .map(intoRule)
+        .filter(rule => rule !== undefined)[0];
 }
 
-
 function isString(value: any): value is string {
     return typeof value === 'string';
 }
@@ -46,18 +65,15 @@ function isArrayOfString(value: any): value is string[] {
     return Array.isArray(value) && value.every(item => isString(item));
 }
 
-
 export function load() {
-    const rawConfig: { [key: string]: any } = vscode.workspace
-        .getConfiguration('rust-analyzer')
-        .get('scopeMappings')
-        || {};
+    const rawConfig: { [key: string]: any } =
+        vscode.workspace
+            .getConfiguration('rust-analyzer')
+            .get('scopeMappings') || {};
 
-    mappings = Object
-        .entries(rawConfig)
+    mappings = Object.entries(rawConfig)
         .filter(([_, value]) => isString(value) || isArrayOfString(value))
         .reduce((list, [key, value]: [string, string | string[]]) => {
             return list.set(key, isString(value) ? [value] : value);
         }, defaultMapping);
-
-}
\ No newline at end of file
+}