diff options
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/config.ts | 7 | ||||
-rw-r--r-- | editors/code/src/highlighting.ts | 46 |
2 files changed, 50 insertions, 3 deletions
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 | ||
16 | export class Config { | 16 | export 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 @@ | |||
1 | import seedrandom = require('seedrandom'); | ||
1 | import * as vscode from 'vscode'; | 2 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 3 | import * as lc from 'vscode-languageclient'; |
3 | 4 | ||
@@ -6,6 +7,20 @@ import { Server } from './server'; | |||
6 | export interface Decoration { | 7 | export 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 | ||
14 | function 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 | ||
11 | export class Highlighter { | 26 | export 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 | } |