From 0ddf47a7ab9d0f616e7296fa9a0b0eb786e4ee59 Mon Sep 17 00:00:00 2001 From: Seivan Heidari Date: Sun, 27 Oct 2019 17:57:11 +0100 Subject: Introducing a Scopes Mapper to map from RA scopes to TextMate scopes with fallbacks. Current scopes defined: ``` ['keyword.unsafe', ['storage.modifier', 'keyword.other', 'keyword.control']], ['function', ['entity.name.function']], ['parameter', ['variable.parameter']], ['type', ['entity.name.type']], ['builtin', ['variable.language', 'support.type', 'support.type']], ['text', ['string', 'string.quoted', 'string.regexp']], ['attribute', ['keyword']], ['literal', ['string', 'string.quoted', 'string.regexp']], ['macro', ['support.other']], ['variable.mut', ['variable']], ['field', ['variable.object.property']], ['module', ['entity.name.section']] ``` Need to complement with further fallbacks as some themes fail. --- editors/code/src/scopes_mapper.ts | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 editors/code/src/scopes_mapper.ts (limited to 'editors/code/src/scopes_mapper.ts') diff --git a/editors/code/src/scopes_mapper.ts b/editors/code/src/scopes_mapper.ts new file mode 100644 index 000000000..995adae2d --- /dev/null +++ b/editors/code/src/scopes_mapper.ts @@ -0,0 +1,42 @@ +import * as vscode from 'vscode' +import { TextMateRuleSettings } from './scopes' + + + + +let mappings = new Map() + + +const defaultMapping = new Map([ + ['keyword.unsafe', ['storage.modifier', 'keyword.other', 'keyword.control']], + ['function', ['entity.name.function']], + ['parameter', ['variable.parameter']], + ['type', ['entity.name.type']], + ['builtin', ['variable.language', 'support.type', 'support.type']], + ['text', ['string', 'string.quoted', 'string.regexp']], + ['attribute', ['keyword']], + ['literal', ['string', 'string.quoted', 'string.regexp']], + ['macro', ['support.other']], + ['variable.mut', ['variable']], + ['field', ['variable.object.property']], + ['module', ['entity.name.section']] +] +) +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).find(rule => rule !== null) +} + + +export function load() { + const configuration = vscode.workspace + .getConfiguration('rust-analyzer') + .get('scopeMappings') as Map | undefined || new Map() + + mappings = new Map([...Array.from(defaultMapping.entries()), ...Array.from(configuration.entries())]); + + +} \ No newline at end of file -- cgit v1.2.3