aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/inlay_hints.ts
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-17 11:17:01 +0000
committerAleksey Kladov <[email protected]>2020-02-17 12:40:47 +0000
commitdcdbbddd1630a4ed01906c2aff0e2b65ed99a591 (patch)
treee02793bf82f2956bf7c61dfbd7adfcfdf4df191b /editors/code/src/inlay_hints.ts
parentfcf15cc05afaeda6880664777ff2a3db342ea088 (diff)
Simplify TS reload logic
Fixes #3164
Diffstat (limited to 'editors/code/src/inlay_hints.ts')
-rw-r--r--editors/code/src/inlay_hints.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index 3896878cd..9e400fabe 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -27,9 +27,15 @@ export function activateInlayHints(ctx: Ctx) {
27 ctx.subscriptions 27 ctx.subscriptions
28 ); 28 );
29 29
30 ctx.pushCleanup({
31 dispose() {
32 hintsUpdater.clear()
33 }
34 })
35
30 // We pass async function though it will not be awaited when called, 36 // We pass async function though it will not be awaited when called,
31 // thus Promise rejections won't be handled, but this should never throw in fact... 37 // thus Promise rejections won't be handled, but this should never throw in fact...
32 ctx.onDidRestart(async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints)); 38 ctx.onStart(async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints));
33} 39}
34 40
35interface InlayHintsParams { 41interface InlayHintsParams {
@@ -61,16 +67,23 @@ class HintsUpdater {
61 67
62 constructor(ctx: Ctx) { 68 constructor(ctx: Ctx) {
63 this.ctx = ctx; 69 this.ctx = ctx;
64 this.enabled = ctx.config.displayInlayHints; 70 this.enabled = false;
65 } 71 }
66 72
67 async setEnabled(enabled: boolean): Promise<void> { 73 async setEnabled(enabled: boolean): Promise<void> {
74 console.log({ enabled, prev: this.enabled });
75
68 if (this.enabled == enabled) return; 76 if (this.enabled == enabled) return;
69 this.enabled = enabled; 77 this.enabled = enabled;
70 78
71 if (this.enabled) { 79 if (this.enabled) {
72 return await this.refresh(); 80 return await this.refresh();
81 } else {
82 return this.clear();
73 } 83 }
84 }
85
86 clear() {
74 this.allEditors.forEach(it => { 87 this.allEditors.forEach(it => {
75 this.setTypeDecorations(it, []); 88 this.setTypeDecorations(it, []);
76 this.setParameterDecorations(it, []); 89 this.setParameterDecorations(it, []);
@@ -79,6 +92,8 @@ class HintsUpdater {
79 92
80 async refresh() { 93 async refresh() {
81 if (!this.enabled) return; 94 if (!this.enabled) return;
95 console.log("freshin!");
96
82 await Promise.all(this.allEditors.map(it => this.refreshEditor(it))); 97 await Promise.all(this.allEditors.map(it => this.refreshEditor(it)));
83 } 98 }
84 99