aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/highlighting.ts
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-31 17:38:55 +0000
committerGitHub <[email protected]>2019-12-31 17:38:55 +0000
commit6d23140ba03c77b28d94e042c94155899baba9da (patch)
tree3efa5daf54fe08cd1b310fa42c2ef469503fcedd /editors/code/src/highlighting.ts
parent1327aed7f6289043091aa9179282030c6f13ddbe (diff)
parent6368b40dd98b208da3758d4d1eed34cf276e3b09 (diff)
Merge #2709
2709: Work around synchrnonisation issue r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src/highlighting.ts')
-rw-r--r--editors/code/src/highlighting.ts20
1 files changed, 12 insertions, 8 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index d383d87ef..f9d2e9d90 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -5,13 +5,12 @@ 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.client.onReady().then(() => { 13 client.onNotification(
14 ctx.client.onNotification(
15 'rust-analyzer/publishDecorations', 14 'rust-analyzer/publishDecorations',
16 (params: PublishDecorationsParams) => { 15 (params: PublishDecorationsParams) => {
17 if (!ctx.config.highlightingOn) return; 16 if (!ctx.config.highlightingOn) return;
@@ -31,7 +30,7 @@ export function activateHighlighting(ctx: Ctx) {
31 highlighter.setHighlights(targetEditor, params.decorations); 30 highlighter.setHighlights(targetEditor, params.decorations);
32 }, 31 },
33 ); 32 );
34 }); 33 })
35 34
36 vscode.workspace.onDidChangeConfiguration( 35 vscode.workspace.onDidChangeConfiguration(
37 _ => highlighter.removeHighlights(), 36 _ => highlighter.removeHighlights(),
@@ -42,11 +41,14 @@ export function activateHighlighting(ctx: Ctx) {
42 async (editor: vscode.TextEditor | undefined) => { 41 async (editor: vscode.TextEditor | undefined) => {
43 if (!editor || editor.document.languageId !== 'rust') return; 42 if (!editor || editor.document.languageId !== 'rust') return;
44 if (!ctx.config.highlightingOn) return; 43 if (!ctx.config.highlightingOn) return;
44 let client = ctx.client;
45 if (!client) return;
45 46
46 const params: lc.TextDocumentIdentifier = { 47 const params: lc.TextDocumentIdentifier = {
47 uri: editor.document.uri.toString(), 48 uri: editor.document.uri.toString(),
48 }; 49 };
49 const decorations = await ctx.sendRequestWithRetry<Decoration[]>( 50 const decorations = await sendRequestWithRetry<Decoration[]>(
51 client,
50 'rust-analyzer/decorationsRequest', 52 'rust-analyzer/decorationsRequest',
51 params, 53 params,
52 ); 54 );
@@ -105,6 +107,8 @@ class Highlighter {
105 } 107 }
106 108
107 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;
108 // Initialize decorations if necessary 112 // Initialize decorations if necessary
109 // 113 //
110 // 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
@@ -137,13 +141,13 @@ class Highlighter {
137 colorfulIdents 141 colorfulIdents
138 .get(d.bindingHash)![0] 142 .get(d.bindingHash)![0]
139 .push( 143 .push(
140 this.ctx.client.protocol2CodeConverter.asRange(d.range), 144 client.protocol2CodeConverter.asRange(d.range),
141 ); 145 );
142 } else { 146 } else {
143 byTag 147 byTag
144 .get(d.tag)! 148 .get(d.tag)!
145 .push( 149 .push(
146 this.ctx.client.protocol2CodeConverter.asRange(d.range), 150 client.protocol2CodeConverter.asRange(d.range),
147 ); 151 );
148 } 152 }
149 } 153 }