mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Make rainbows optional
This commit is contained in:
parent
4ac338b608
commit
1e6ba19015
5 changed files with 29 additions and 6 deletions
|
@ -35,7 +35,8 @@ impl<'a> SyntaxText<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_smol_string(&self) -> SmolStr {
|
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()
|
self.to_string().into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -470,3 +470,12 @@ There also snippet completions:
|
||||||
|
|
||||||
- `tfn` -> `#[test] fn f(){}`
|
- `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.
|
||||||
|
|
|
@ -164,6 +164,11 @@
|
||||||
"default": false,
|
"default": false,
|
||||||
"description": "Highlight Rust code (overrides built-in syntax highlighting)"
|
"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": {
|
"rust-analyzer.showWorkspaceLoadedNotification": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
|
|
|
@ -15,6 +15,7 @@ export interface CargoWatchOptions {
|
||||||
|
|
||||||
export class Config {
|
export class Config {
|
||||||
public highlightingOn = true;
|
public highlightingOn = true;
|
||||||
|
public rainbowHighlightingOn = false;
|
||||||
public enableEnhancedTyping = true;
|
public enableEnhancedTyping = true;
|
||||||
public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
|
public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
|
||||||
public showWorkspaceLoadedNotification = true;
|
public showWorkspaceLoadedNotification = true;
|
||||||
|
@ -39,6 +40,12 @@ export class Config {
|
||||||
this.highlightingOn = config.get('highlightingOn') as boolean;
|
this.highlightingOn = config.get('highlightingOn') as boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.has('rainbowHighlightingOn')) {
|
||||||
|
this.rainbowHighlightingOn = config.get(
|
||||||
|
'rainbowHighlightingOn'
|
||||||
|
) as boolean;
|
||||||
|
}
|
||||||
|
|
||||||
if (config.has('showWorkspaceLoadedNotification')) {
|
if (config.has('showWorkspaceLoadedNotification')) {
|
||||||
this.showWorkspaceLoadedNotification = config.get(
|
this.showWorkspaceLoadedNotification = config.get(
|
||||||
'showWorkspaceLoadedNotification'
|
'showWorkspaceLoadedNotification'
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { Server } from './server';
|
||||||
export interface Decoration {
|
export interface Decoration {
|
||||||
range: lc.Range;
|
range: lc.Range;
|
||||||
tag: string;
|
tag: string;
|
||||||
id?: string;
|
bindingHash?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76
|
// 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 byTag: Map<string, vscode.Range[]> = new Map();
|
||||||
const colorfulIdents: 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()) {
|
for (const tag of this.decorations.keys()) {
|
||||||
byTag.set(tag, []);
|
byTag.set(tag, []);
|
||||||
|
@ -102,12 +103,12 @@ export class Highlighter {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d.id) {
|
if (rainbowTime && d.bindingHash) {
|
||||||
if (!colorfulIdents.has(d.id)) {
|
if (!colorfulIdents.has(d.bindingHash)) {
|
||||||
colorfulIdents.set(d.id, []);
|
colorfulIdents.set(d.bindingHash, []);
|
||||||
}
|
}
|
||||||
colorfulIdents
|
colorfulIdents
|
||||||
.get(d.id)!
|
.get(d.bindingHash)!
|
||||||
.push(
|
.push(
|
||||||
Server.client.protocol2CodeConverter.asRange(d.range)
|
Server.client.protocol2CodeConverter.asRange(d.range)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue