diff options
-rw-r--r-- | crates/ra_syntax/src/syntax_text.rs | 3 | ||||
-rw-r--r-- | docs/user/features.md | 9 | ||||
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/config.ts | 7 | ||||
-rw-r--r-- | editors/code/src/highlighting.ts | 11 |
5 files changed, 29 insertions, 6 deletions
diff --git a/crates/ra_syntax/src/syntax_text.rs b/crates/ra_syntax/src/syntax_text.rs index bff1ed5a0..c9038cd5c 100644 --- a/crates/ra_syntax/src/syntax_text.rs +++ b/crates/ra_syntax/src/syntax_text.rs | |||
@@ -35,7 +35,8 @@ impl<'a> SyntaxText<'a> { | |||
35 | } | 35 | } |
36 | 36 | ||
37 | pub fn to_smol_string(&self) -> SmolStr { | 37 | pub fn to_smol_string(&self) -> SmolStr { |
38 | // TODO: `impl iter::FromIterator<&str> for SmolStr` | 38 | // FIXME: use `self.chunks().collect()` here too once |
39 | // https://github.com/matklad/smol_str/pull/12 is merged and published | ||
39 | self.to_string().into() | 40 | self.to_string().into() |
40 | } | 41 | } |
41 | 42 | ||
diff --git a/docs/user/features.md b/docs/user/features.md index 22470bc56..b6e6008c4 100644 --- a/docs/user/features.md +++ b/docs/user/features.md | |||
@@ -470,3 +470,12 @@ There also snippet completions: | |||
470 | 470 | ||
471 | - `tfn` -> `#[test] fn f(){}` | 471 | - `tfn` -> `#[test] fn f(){}` |
472 | 472 | ||
473 | ### Code highlighting | ||
474 | |||
475 | Experimental feature to let rust-analyzer highlight Rust code instead of using the | ||
476 | default highlighter. | ||
477 | |||
478 | #### Rainbow highlighting | ||
479 | |||
480 | Experimental feature that, given code highlighting using rust-analyzer is | ||
481 | active, will pick unique colors for identifiers. | ||
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 @@ | |||
164 | "default": false, | 164 | "default": false, |
165 | "description": "Highlight Rust code (overrides built-in syntax highlighting)" | 165 | "description": "Highlight Rust code (overrides built-in syntax highlighting)" |
166 | }, | 166 | }, |
167 | "rust-analyzer.rainbowHighlightingOn": { | ||
168 | "type": "boolean", | ||
169 | "default": false, | ||
170 | "description": "When highlighting Rust code, use a unique color per identifier" | ||
171 | }, | ||
167 | "rust-analyzer.showWorkspaceLoadedNotification": { | 172 | "rust-analyzer.showWorkspaceLoadedNotification": { |
168 | "type": "boolean", | 173 | "type": "boolean", |
169 | "default": true, | 174 | "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 { | |||
15 | 15 | ||
16 | export class Config { | 16 | export class Config { |
17 | public highlightingOn = true; | 17 | public highlightingOn = true; |
18 | public rainbowHighlightingOn = false; | ||
18 | public enableEnhancedTyping = true; | 19 | public enableEnhancedTyping = true; |
19 | public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; | 20 | public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; |
20 | public showWorkspaceLoadedNotification = true; | 21 | public showWorkspaceLoadedNotification = true; |
@@ -39,6 +40,12 @@ export class Config { | |||
39 | this.highlightingOn = config.get('highlightingOn') as boolean; | 40 | this.highlightingOn = config.get('highlightingOn') as boolean; |
40 | } | 41 | } |
41 | 42 | ||
43 | if (config.has('rainbowHighlightingOn')) { | ||
44 | this.rainbowHighlightingOn = config.get( | ||
45 | 'rainbowHighlightingOn' | ||
46 | ) as boolean; | ||
47 | } | ||
48 | |||
42 | if (config.has('showWorkspaceLoadedNotification')) { | 49 | if (config.has('showWorkspaceLoadedNotification')) { |
43 | this.showWorkspaceLoadedNotification = config.get( | 50 | this.showWorkspaceLoadedNotification = config.get( |
44 | 'showWorkspaceLoadedNotification' | 51 | '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'; | |||
7 | export interface Decoration { | 7 | export interface Decoration { |
8 | range: lc.Range; | 8 | range: lc.Range; |
9 | tag: string; | 9 | tag: string; |
10 | id?: string; | 10 | bindingHash?: string; |
11 | } | 11 | } |
12 | 12 | ||
13 | // Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76 | 13 | // Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76 |
@@ -92,6 +92,7 @@ export class Highlighter { | |||
92 | 92 | ||
93 | const byTag: Map<string, vscode.Range[]> = new Map(); | 93 | const byTag: Map<string, vscode.Range[]> = new Map(); |
94 | const colorfulIdents: Map<string, vscode.Range[]> = new Map(); | 94 | const colorfulIdents: Map<string, vscode.Range[]> = new Map(); |
95 | const rainbowTime = Server.config.rainbowHighlightingOn; | ||
95 | 96 | ||
96 | for (const tag of this.decorations.keys()) { | 97 | for (const tag of this.decorations.keys()) { |
97 | byTag.set(tag, []); | 98 | byTag.set(tag, []); |
@@ -102,12 +103,12 @@ export class Highlighter { | |||
102 | continue; | 103 | continue; |
103 | } | 104 | } |
104 | 105 | ||
105 | if (d.id) { | 106 | if (rainbowTime && d.bindingHash) { |
106 | if (!colorfulIdents.has(d.id)) { | 107 | if (!colorfulIdents.has(d.bindingHash)) { |
107 | colorfulIdents.set(d.id, []); | 108 | colorfulIdents.set(d.bindingHash, []); |
108 | } | 109 | } |
109 | colorfulIdents | 110 | colorfulIdents |
110 | .get(d.id)! | 111 | .get(d.bindingHash)! |
111 | .push( | 112 | .push( |
112 | Server.client.protocol2CodeConverter.asRange(d.range) | 113 | Server.client.protocol2CodeConverter.asRange(d.range) |
113 | ); | 114 | ); |