Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

underline mutable bindings #1550

Merged
merged 1 commit into from Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions editors/code/package.json
Expand Up @@ -436,9 +436,9 @@
"id": "ralsp.variable.mut",
"description": "Color for mutable variables",
"defaults": {
"dark": "#4e65c9",
"light": "#263199",
"highContrast": "#4e65c9"
"dark": "#4EC9B0",
"light": "#267F99",
"highContrast": "#4EC9B0"
}
},
{
Expand Down
61 changes: 34 additions & 27 deletions editors/code/src/highlighting.ts
Expand Up @@ -28,37 +28,39 @@ export class Highlighter {
string,
vscode.TextEditorDecorationType
> {
const colorContrib = (
tag: string
const decoration = (
tag: string,
textDecoration?: string
): [string, vscode.TextEditorDecorationType] => {
const color = new vscode.ThemeColor('ralsp.' + tag);
const decor = vscode.window.createTextEditorDecorationType({
color
color,
textDecoration
});
return [tag, decor];
};

const decorations: Iterable<
[string, vscode.TextEditorDecorationType]
> = [
colorContrib('comment'),
colorContrib('string'),
colorContrib('keyword'),
colorContrib('keyword.control'),
colorContrib('keyword.unsafe'),
colorContrib('function'),
colorContrib('parameter'),
colorContrib('constant'),
colorContrib('type'),
colorContrib('builtin'),
colorContrib('text'),
colorContrib('attribute'),
colorContrib('literal'),
colorContrib('macro'),
colorContrib('variable'),
colorContrib('variable.mut'),
colorContrib('field'),
colorContrib('module')
decoration('comment'),
decoration('string'),
decoration('keyword'),
decoration('keyword.control'),
decoration('keyword.unsafe'),
decoration('function'),
decoration('parameter'),
decoration('constant'),
decoration('type'),
decoration('builtin'),
decoration('text'),
decoration('attribute'),
decoration('literal'),
decoration('macro'),
decoration('variable'),
decoration('variable.mut', 'underline'),
decoration('field'),
decoration('module')
];

return new Map<string, vscode.TextEditorDecorationType>(decorations);
Expand Down Expand Up @@ -92,7 +94,10 @@ export class Highlighter {
}

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;

for (const tag of this.decorations.keys()) {
Expand All @@ -106,10 +111,11 @@ export class Highlighter {

if (rainbowTime && d.bindingHash) {
if (!colorfulIdents.has(d.bindingHash)) {
colorfulIdents.set(d.bindingHash, []);
const mut = d.tag.endsWith('.mut');
colorfulIdents.set(d.bindingHash, [[], mut]);
}
colorfulIdents
.get(d.bindingHash)!
.get(d.bindingHash)![0]
.push(
Server.client.protocol2CodeConverter.asRange(d.range)
);
Expand All @@ -130,10 +136,11 @@ export class Highlighter {
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({
light: { color: fancify(hash, 'light') },
dark: { color: fancify(hash, 'dark') }
light: { color: fancify(hash, 'light'), textDecoration },
dark: { color: fancify(hash, 'dark'), textDecoration }
});
editor.setDecorations(dec, ranges);
}
Expand Down