aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/highlighting.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/highlighting.ts')
-rw-r--r--editors/code/src/highlighting.ts56
1 files changed, 31 insertions, 25 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index d4e961b5b..f9d2e9d90 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -5,31 +5,32 @@ const seedrandom = seedrandom_; // https://github.com/jvandemo/generator-angular
5 5
6import { ColorTheme, TextMateRuleSettings } from './color_theme'; 6import { ColorTheme, TextMateRuleSettings } from './color_theme';
7 7
8import { Ctx } from './ctx'; 8import { Ctx, sendRequestWithRetry } from './ctx';
9 9
10export function activateHighlighting(ctx: Ctx) { 10export function activateHighlighting(ctx: Ctx) {
11 const highlighter = new Highlighter(ctx); 11 const highlighter = new Highlighter(ctx);
12 12 ctx.onDidRestart(client => {
13 ctx.onNotification( 13 client.onNotification(
14 'rust-analyzer/publishDecorations', 14 'rust-analyzer/publishDecorations',
15 (params: PublishDecorationsParams) => { 15 (params: PublishDecorationsParams) => {
16 if (!ctx.config.highlightingOn) return; 16 if (!ctx.config.highlightingOn) return;
17 17
18 const targetEditor = vscode.window.visibleTextEditors.find( 18 const targetEditor = vscode.window.visibleTextEditors.find(
19 editor => { 19 editor => {
20 const unescapedUri = unescape( 20 const unescapedUri = unescape(
21 editor.document.uri.toString(), 21 editor.document.uri.toString(),
22 ); 22 );
23 // Unescaped URI looks like: 23 // Unescaped URI looks like:
24 // file:///c:/Workspace/ra-test/src/main.rs 24 // file:///c:/Workspace/ra-test/src/main.rs
25 return unescapedUri === params.uri; 25 return unescapedUri === params.uri;
26 }, 26 },
27 ); 27 );
28 if (!targetEditor) return; 28 if (!targetEditor) return;
29 29
30 highlighter.setHighlights(targetEditor, params.decorations); 30 highlighter.setHighlights(targetEditor, params.decorations);
31 }, 31 },
32 ); 32 );
33 })
33 34
34 vscode.workspace.onDidChangeConfiguration( 35 vscode.workspace.onDidChangeConfiguration(
35 _ => highlighter.removeHighlights(), 36 _ => highlighter.removeHighlights(),
@@ -40,11 +41,14 @@ export function activateHighlighting(ctx: Ctx) {
40 async (editor: vscode.TextEditor | undefined) => { 41 async (editor: vscode.TextEditor | undefined) => {
41 if (!editor || editor.document.languageId !== 'rust') return; 42 if (!editor || editor.document.languageId !== 'rust') return;
42 if (!ctx.config.highlightingOn) return; 43 if (!ctx.config.highlightingOn) return;
44 let client = ctx.client;
45 if (!client) return;
43 46
44 const params: lc.TextDocumentIdentifier = { 47 const params: lc.TextDocumentIdentifier = {
45 uri: editor.document.uri.toString(), 48 uri: editor.document.uri.toString(),
46 }; 49 };
47 const decorations = await ctx.sendRequestWithRetry<Decoration[]>( 50 const decorations = await sendRequestWithRetry<Decoration[]>(
51 client,
48 'rust-analyzer/decorationsRequest', 52 'rust-analyzer/decorationsRequest',
49 params, 53 params,
50 ); 54 );
@@ -103,6 +107,8 @@ class Highlighter {
103 } 107 }
104 108
105 public setHighlights(editor: vscode.TextEditor, highlights: Decoration[]) { 109 public setHighlights(editor: vscode.TextEditor, highlights: Decoration[]) {
110 let client = this.ctx.client;
111 if (!client) return;
106 // Initialize decorations if necessary 112 // Initialize decorations if necessary
107 // 113 //
108 // Note: decoration objects need to be kept around so we can dispose them 114 // Note: decoration objects need to be kept around so we can dispose them
@@ -135,13 +141,13 @@ class Highlighter {
135 colorfulIdents 141 colorfulIdents
136 .get(d.bindingHash)![0] 142 .get(d.bindingHash)![0]
137 .push( 143 .push(
138 this.ctx.client.protocol2CodeConverter.asRange(d.range), 144 client.protocol2CodeConverter.asRange(d.range),
139 ); 145 );
140 } else { 146 } else {
141 byTag 147 byTag
142 .get(d.tag)! 148 .get(d.tag)!
143 .push( 149 .push(
144 this.ctx.client.protocol2CodeConverter.asRange(d.range), 150 client.protocol2CodeConverter.asRange(d.range),
145 ); 151 );
146 } 152 }
147 } 153 }