aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/package-lock.json10
-rw-r--r--editors/code/package.json7
-rw-r--r--editors/code/src/config.ts7
-rw-r--r--editors/code/src/highlighting.ts46
4 files changed, 67 insertions, 3 deletions
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json
index 29cd260a4..6b3a12f91 100644
--- a/editors/code/package-lock.json
+++ b/editors/code/package-lock.json
@@ -36,6 +36,11 @@
36 "integrity": "sha512-Ja7d4s0qyGFxjGeDq5S7Si25OFibSAHUi6i17UWnwNnpitADN7hah9q0Tl25gxuV5R1u2Bx+np6w4LHXfHyj/g==", 36 "integrity": "sha512-Ja7d4s0qyGFxjGeDq5S7Si25OFibSAHUi6i17UWnwNnpitADN7hah9q0Tl25gxuV5R1u2Bx+np6w4LHXfHyj/g==",
37 "dev": true 37 "dev": true
38 }, 38 },
39 "@types/seedrandom": {
40 "version": "2.4.28",
41 "resolved": "https://registry.npmjs.org/@types/seedrandom/-/seedrandom-2.4.28.tgz",
42 "integrity": "sha512-SMA+fUwULwK7sd/ZJicUztiPs8F1yCPwF3O23Z9uQ32ME5Ha0NmDK9+QTsYE4O2tHXChzXomSWWeIhCnoN1LqA=="
43 },
39 "agent-base": { 44 "agent-base": {
40 "version": "4.2.1", 45 "version": "4.2.1",
41 "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.1.tgz", 46 "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.1.tgz",
@@ -984,6 +989,11 @@
984 "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", 989 "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
985 "dev": true 990 "dev": true
986 }, 991 },
992 "seedrandom": {
993 "version": "3.0.1",
994 "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.1.tgz",
995 "integrity": "sha512-1/02Y/rUeU1CJBAGLebiC5Lbo5FnB22gQbIFFYTLkwvp1xdABZJH1sn4ZT1MzXmPpzv+Rf/Lu2NcsLJiK4rcDg=="
996 },
987 "semver": { 997 "semver": {
988 "version": "5.7.0", 998 "version": "5.7.0",
989 "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", 999 "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz",
diff --git a/editors/code/package.json b/editors/code/package.json
index cde5fbcb8..05c808394 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -31,11 +31,13 @@
31 "singleQuote": true 31 "singleQuote": true
32 }, 32 },
33 "dependencies": { 33 "dependencies": {
34 "seedrandom": "^3.0.1",
34 "vscode-languageclient": "^5.3.0-next.4" 35 "vscode-languageclient": "^5.3.0-next.4"
35 }, 36 },
36 "devDependencies": { 37 "devDependencies": {
37 "@types/mocha": "^5.2.6", 38 "@types/mocha": "^5.2.6",
38 "@types/node": "^10.14.5", 39 "@types/node": "^10.14.5",
40 "@types/seedrandom": "^2.4.28",
39 "prettier": "^1.17.0", 41 "prettier": "^1.17.0",
40 "shx": "^0.3.1", 42 "shx": "^0.3.1",
41 "tslint": "^5.16.0", 43 "tslint": "^5.16.0",
@@ -162,6 +164,11 @@
162 "default": false, 164 "default": false,
163 "description": "Highlight Rust code (overrides built-in syntax highlighting)" 165 "description": "Highlight Rust code (overrides built-in syntax highlighting)"
164 }, 166 },
167 "rust-analyzer.rainbowHighlightingOn": {
168 "type": "boolean",
169 "default": false,
170 "description": "When highlighting Rust code, use a unique color per identifier"
171 },
165 "rust-analyzer.showWorkspaceLoadedNotification": { 172 "rust-analyzer.showWorkspaceLoadedNotification": {
166 "type": "boolean", 173 "type": "boolean",
167 "default": true, 174 "default": true,
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 481a5e5f1..8d73a6b34 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -15,6 +15,7 @@ export interface CargoWatchOptions {
15 15
16export class Config { 16export class Config {
17 public highlightingOn = true; 17 public highlightingOn = true;
18 public rainbowHighlightingOn = false;
18 public enableEnhancedTyping = true; 19 public enableEnhancedTyping = true;
19 public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; 20 public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
20 public showWorkspaceLoadedNotification = true; 21 public showWorkspaceLoadedNotification = true;
@@ -39,6 +40,12 @@ export class Config {
39 this.highlightingOn = config.get('highlightingOn') as boolean; 40 this.highlightingOn = config.get('highlightingOn') as boolean;
40 } 41 }
41 42
43 if (config.has('rainbowHighlightingOn')) {
44 this.rainbowHighlightingOn = config.get(
45 'rainbowHighlightingOn'
46 ) as boolean;
47 }
48
42 if (config.has('showWorkspaceLoadedNotification')) { 49 if (config.has('showWorkspaceLoadedNotification')) {
43 this.showWorkspaceLoadedNotification = config.get( 50 this.showWorkspaceLoadedNotification = config.get(
44 'showWorkspaceLoadedNotification' 51 'showWorkspaceLoadedNotification'
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 8389d94b8..52a0bd4bb 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -1,3 +1,4 @@
1import seedrandom = require('seedrandom');
1import * as vscode from 'vscode'; 2import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 3import * as lc from 'vscode-languageclient';
3 4
@@ -6,6 +7,20 @@ import { Server } from './server';
6export interface Decoration { 7export interface Decoration {
7 range: lc.Range; 8 range: lc.Range;
8 tag: string; 9 tag: string;
10 bindingHash?: string;
11}
12
13// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76
14function fancify(seed: string, shade: 'light' | 'dark') {
15 const random = seedrandom(seed);
16 const randomInt = (min: number, max: number) => {
17 return Math.floor(random() * (max - min + 1)) + min;
18 };
19
20 const h = randomInt(0, 360);
21 const s = randomInt(42, 98);
22 const l = shade === 'light' ? randomInt(15, 40) : randomInt(40, 90);
23 return `hsl(${h},${s}%,${l}%)`;
9} 24}
10 25
11export class Highlighter { 26export class Highlighter {
@@ -76,6 +91,9 @@ export class Highlighter {
76 } 91 }
77 92
78 const byTag: Map<string, vscode.Range[]> = new Map(); 93 const byTag: Map<string, vscode.Range[]> = new Map();
94 const colorfulIdents: Map<string, vscode.Range[]> = new Map();
95 const rainbowTime = Server.config.rainbowHighlightingOn;
96
79 for (const tag of this.decorations.keys()) { 97 for (const tag of this.decorations.keys()) {
80 byTag.set(tag, []); 98 byTag.set(tag, []);
81 } 99 }
@@ -84,9 +102,23 @@ export class Highlighter {
84 if (!byTag.get(d.tag)) { 102 if (!byTag.get(d.tag)) {
85 continue; 103 continue;
86 } 104 }
87 byTag 105
88 .get(d.tag)! 106 if (rainbowTime && d.bindingHash) {
89 .push(Server.client.protocol2CodeConverter.asRange(d.range)); 107 if (!colorfulIdents.has(d.bindingHash)) {
108 colorfulIdents.set(d.bindingHash, []);
109 }
110 colorfulIdents
111 .get(d.bindingHash)!
112 .push(
113 Server.client.protocol2CodeConverter.asRange(d.range)
114 );
115 } else {
116 byTag
117 .get(d.tag)!
118 .push(
119 Server.client.protocol2CodeConverter.asRange(d.range)
120 );
121 }
90 } 122 }
91 123
92 for (const tag of byTag.keys()) { 124 for (const tag of byTag.keys()) {
@@ -96,5 +128,13 @@ export class Highlighter {
96 const ranges = byTag.get(tag)!; 128 const ranges = byTag.get(tag)!;
97 editor.setDecorations(dec, ranges); 129 editor.setDecorations(dec, ranges);
98 } 130 }
131
132 for (const [hash, ranges] of colorfulIdents.entries()) {
133 const dec = vscode.window.createTextEditorDecorationType({
134 light: { color: fancify(hash, 'light') },
135 dark: { color: fancify(hash, 'dark') }
136 });
137 editor.setDecorations(dec, ranges);
138 }
99 } 139 }
100} 140}