underline mutable bindings

This commit is contained in:
Aleksey Kladov 2019-07-19 14:43:36 +03:00
parent f209843e31
commit e418889996
2 changed files with 37 additions and 30 deletions

View file

@ -436,9 +436,9 @@
"id": "ralsp.variable.mut", "id": "ralsp.variable.mut",
"description": "Color for mutable variables", "description": "Color for mutable variables",
"defaults": { "defaults": {
"dark": "#4e65c9", "dark": "#4EC9B0",
"light": "#263199", "light": "#267F99",
"highContrast": "#4e65c9" "highContrast": "#4EC9B0"
} }
}, },
{ {

View file

@ -28,12 +28,14 @@ export class Highlighter {
string, string,
vscode.TextEditorDecorationType vscode.TextEditorDecorationType
> { > {
const colorContrib = ( const decoration = (
tag: string tag: string,
textDecoration?: string
): [string, vscode.TextEditorDecorationType] => { ): [string, vscode.TextEditorDecorationType] => {
const color = new vscode.ThemeColor('ralsp.' + tag); const color = new vscode.ThemeColor('ralsp.' + tag);
const decor = vscode.window.createTextEditorDecorationType({ const decor = vscode.window.createTextEditorDecorationType({
color color,
textDecoration
}); });
return [tag, decor]; return [tag, decor];
}; };
@ -41,24 +43,24 @@ export class Highlighter {
const decorations: Iterable< const decorations: Iterable<
[string, vscode.TextEditorDecorationType] [string, vscode.TextEditorDecorationType]
> = [ > = [
colorContrib('comment'), decoration('comment'),
colorContrib('string'), decoration('string'),
colorContrib('keyword'), decoration('keyword'),
colorContrib('keyword.control'), decoration('keyword.control'),
colorContrib('keyword.unsafe'), decoration('keyword.unsafe'),
colorContrib('function'), decoration('function'),
colorContrib('parameter'), decoration('parameter'),
colorContrib('constant'), decoration('constant'),
colorContrib('type'), decoration('type'),
colorContrib('builtin'), decoration('builtin'),
colorContrib('text'), decoration('text'),
colorContrib('attribute'), decoration('attribute'),
colorContrib('literal'), decoration('literal'),
colorContrib('macro'), decoration('macro'),
colorContrib('variable'), decoration('variable'),
colorContrib('variable.mut'), decoration('variable.mut', 'underline'),
colorContrib('field'), decoration('field'),
colorContrib('module') decoration('module')
]; ];
return new Map<string, vscode.TextEditorDecorationType>(decorations); return new Map<string, vscode.TextEditorDecorationType>(decorations);
@ -92,7 +94,10 @@ export class Highlighter {
} }
const byTag: Map<string, vscode.Range[]> = new Map(); const byTag: Map<string, vscode.Range[]> = new Map();
const colorfulIdents: Map<string, vscode.Range[]> = new Map(); const colorfulIdents: Map<
string,
[vscode.Range[], boolean]
> = new Map();
const rainbowTime = Server.config.rainbowHighlightingOn; const rainbowTime = Server.config.rainbowHighlightingOn;
for (const tag of this.decorations.keys()) { for (const tag of this.decorations.keys()) {
@ -106,10 +111,11 @@ export class Highlighter {
if (rainbowTime && d.bindingHash) { if (rainbowTime && d.bindingHash) {
if (!colorfulIdents.has(d.bindingHash)) { if (!colorfulIdents.has(d.bindingHash)) {
colorfulIdents.set(d.bindingHash, []); const mut = d.tag.endsWith('.mut');
colorfulIdents.set(d.bindingHash, [[], mut]);
} }
colorfulIdents colorfulIdents
.get(d.bindingHash)! .get(d.bindingHash)![0]
.push( .push(
Server.client.protocol2CodeConverter.asRange(d.range) Server.client.protocol2CodeConverter.asRange(d.range)
); );
@ -130,10 +136,11 @@ export class Highlighter {
editor.setDecorations(dec, ranges); editor.setDecorations(dec, ranges);
} }
for (const [hash, ranges] of colorfulIdents.entries()) { for (const [hash, [ranges, mut]] of colorfulIdents.entries()) {
const textDecoration = mut ? 'underline' : undefined;
const dec = vscode.window.createTextEditorDecorationType({ const dec = vscode.window.createTextEditorDecorationType({
light: { color: fancify(hash, 'light') }, light: { color: fancify(hash, 'light'), textDecoration },
dark: { color: fancify(hash, 'dark') } dark: { color: fancify(hash, 'dark'), textDecoration }
}); });
editor.setDecorations(dec, ranges); editor.setDecorations(dec, ranges);
} }