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_mapper.ts | 58 +++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 21 deletions(-) (limited to 'editors/code/src/scopes_mapper.ts') diff --git a/editors/code/src/scopes_mapper.ts b/editors/code/src/scopes_mapper.ts index dfb8bf217..85c791ff5 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(); - const defaultMapping = new Map([ - ['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([ ['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 +} -- cgit v1.2.3