Make rainbows optional

This commit is contained in:
Pascal Hertleif 2019-05-27 11:26:15 +02:00
parent 4ac338b608
commit 1e6ba19015
5 changed files with 29 additions and 6 deletions

View file

@ -35,7 +35,8 @@ impl<'a> SyntaxText<'a> {
}
pub fn to_smol_string(&self) -> SmolStr {
// TODO: `impl iter::FromIterator<&str> for SmolStr`
// FIXME: use `self.chunks().collect()` here too once
// https://github.com/matklad/smol_str/pull/12 is merged and published
self.to_string().into()
}

View file

@ -470,3 +470,12 @@ There also snippet completions:
- `tfn` -> `#[test] fn f(){}`
### Code highlighting
Experimental feature to let rust-analyzer highlight Rust code instead of using the
default highlighter.
#### Rainbow highlighting
Experimental feature that, given code highlighting using rust-analyzer is
active, will pick unique colors for identifiers.

View file

@ -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,

View file

@ -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'

View file

@ -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<string, vscode.Range[]> = new Map();
const colorfulIdents: Map<string, vscode.Range[]> = 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)
);