From 1e6ba1901550fb1610a1a464c48ec358cd3c339c Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Mon, 27 May 2019 11:26:15 +0200 Subject: Make rainbows optional --- editors/code/package.json | 5 +++++ editors/code/src/config.ts | 7 +++++++ editors/code/src/highlighting.ts | 11 ++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) (limited to 'editors') diff --git a/editors/code/package.json b/editors/code/package.json index d8ba914f5..05c808394 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -164,6 +164,11 @@ "default": false, "description": "Highlight Rust code (overrides built-in syntax highlighting)" }, + "rust-analyzer.rainbowHighlightingOn": { + "type": "boolean", + "default": false, + "description": "When highlighting Rust code, use a unique color per identifier" + }, "rust-analyzer.showWorkspaceLoadedNotification": { "type": "boolean", "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 { export class Config { public highlightingOn = true; + public rainbowHighlightingOn = false; public enableEnhancedTyping = true; public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; public showWorkspaceLoadedNotification = true; @@ -39,6 +40,12 @@ export class Config { this.highlightingOn = config.get('highlightingOn') as boolean; } + if (config.has('rainbowHighlightingOn')) { + this.rainbowHighlightingOn = config.get( + 'rainbowHighlightingOn' + ) as boolean; + } + if (config.has('showWorkspaceLoadedNotification')) { this.showWorkspaceLoadedNotification = config.get( 'showWorkspaceLoadedNotification' diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 4597db08f..52a0bd4bb 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -7,7 +7,7 @@ import { Server } from './server'; export interface Decoration { range: lc.Range; tag: string; - id?: string; + bindingHash?: string; } // Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76 @@ -92,6 +92,7 @@ export class Highlighter { const byTag: Map = new Map(); const colorfulIdents: Map = new Map(); + const rainbowTime = Server.config.rainbowHighlightingOn; for (const tag of this.decorations.keys()) { byTag.set(tag, []); @@ -102,12 +103,12 @@ export class Highlighter { continue; } - if (d.id) { - if (!colorfulIdents.has(d.id)) { - colorfulIdents.set(d.id, []); + if (rainbowTime && d.bindingHash) { + if (!colorfulIdents.has(d.bindingHash)) { + colorfulIdents.set(d.bindingHash, []); } colorfulIdents - .get(d.id)! + .get(d.bindingHash)! .push( Server.client.protocol2CodeConverter.asRange(d.range) ); -- cgit v1.2.3