about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorSeivan Heidari <seivan.heidari@icloud.com>2019-10-27 17:57:11 +0100
committerSeivan Heidari <seivan.heidari@icloud.com>2019-10-27 17:57:11 +0100
commit0ddf47a7ab9d0f616e7296fa9a0b0eb786e4ee59 (patch)
tree80234db0e3af0d5f0b428a18f1b66f8fa2ba3bea /editors/code/src
parent5957b851e4451050151722598fa1ff9d41ccf0ff (diff)
downloadrust-0ddf47a7ab9d0f616e7296fa9a0b0eb786e4ee59.tar.gz
rust-0ddf47a7ab9d0f616e7296fa9a0b0eb786e4ee59.zip
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.
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/config.ts2
-rw-r--r--editors/code/src/highlighting.ts11
-rw-r--r--editors/code/src/scopes.ts18
-rw-r--r--editors/code/src/scopes_mapper.ts42
4 files changed, 60 insertions, 13 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 9f8c810b63d..a3fe3909872 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -1,5 +1,6 @@
 import * as vscode from 'vscode';
 import * as scopes from './scopes';
+import * as scopesMapper from './scopes_mapper';
 import { Server } from './server';
 
 const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
@@ -49,6 +50,7 @@ export class Config {
         
         Server.highlighter.removeHighlights();
         scopes.load()
+        scopesMapper.load()
         if (config.has('highlightingOn')) {
 
             this.highlightingOn = config.get('highlightingOn') as boolean;
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 4b961170b97..bc19fae2ff2 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -2,7 +2,7 @@ import seedrandom = require('seedrandom');
 import * as vscode from 'vscode';
 import * as lc from 'vscode-languageclient';
 import * as scopes from './scopes'
-
+import * as scopesMapper from './scopes_mapper';
 
 import { Server } from './server';
 
@@ -65,10 +65,13 @@ export class Highlighter {
             tag: string,
             textDecoration?: string
         ): [string, vscode.TextEditorDecorationType] => {
-            const scope = scopes.find(tag)
 
-            if (scope) {
-                const decor = createDecorationFromTextmate(scope);
+            const foundRule = scopesMapper.toRule(tag, scopes.find) || scopes.find(tag)
+
+
+
+            if (foundRule) {
+                const decor = createDecorationFromTextmate(foundRule);
                 return [tag, decor];
             }
             else {
diff --git a/editors/code/src/scopes.ts b/editors/code/src/scopes.ts
index c9c01ba1d10..470ee716ff2 100644
--- a/editors/code/src/scopes.ts
+++ b/editors/code/src/scopes.ts
@@ -16,16 +16,16 @@ export interface TextMateRuleSettings {
 }
 
 // Current theme colors
-const colors = new Map<string, TextMateRuleSettings>()
+const rules = new Map<string, TextMateRuleSettings>()
 
 export function find(scope: string): TextMateRuleSettings | undefined {
-    return colors.get(scope)
+    return rules.get(scope)
 }
 
 // Load all textmate scopes in the currently active theme
 export function load() {
     // Remove any previous theme
-    colors.clear()
+    rules.clear()
     // Find out current color theme
     const themeName = vscode.workspace.getConfiguration('workbench').get('colorTheme')
 
@@ -95,21 +95,21 @@ function loadColors(textMateRules: TextMateRule[]): void {
     for (const rule of textMateRules) {
 
         if (typeof rule.scope === 'string') {
-            const existingRule = colors.get(rule.scope);
+            const existingRule = rules.get(rule.scope);
             if (existingRule) {
-                colors.set(rule.scope, mergeRuleSettings(existingRule, rule.settings))
+                rules.set(rule.scope, mergeRuleSettings(existingRule, rule.settings))
             }
             else {
-                colors.set(rule.scope, rule.settings)
+                rules.set(rule.scope, rule.settings)
             }
         } else if (rule.scope instanceof Array) {
             for (const scope of rule.scope) {
-                const existingRule = colors.get(scope);
+                const existingRule = rules.get(scope);
                 if (existingRule) {
-                    colors.set(scope, mergeRuleSettings(existingRule, rule.settings))
+                    rules.set(scope, mergeRuleSettings(existingRule, rule.settings))
                 }
                 else {
-                    colors.set(scope, rule.settings)
+                    rules.set(scope, rule.settings)
                 }
             }
         }
diff --git a/editors/code/src/scopes_mapper.ts b/editors/code/src/scopes_mapper.ts
new file mode 100644
index 00000000000..995adae2dd8
--- /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<string, string[]>()
+
+
+const defaultMapping = new Map<string, string[]>([
+    ['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<string, string[]> | undefined || new Map()
+
+    mappings = new Map([...Array.from(defaultMapping.entries()), ...Array.from(configuration.entries())]);
+
+
+}
\ No newline at end of file