aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/code/src/inlay_hints.ts38
-rw-r--r--editors/code/src/main.ts39
2 files changed, 39 insertions, 38 deletions
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index b975915ca..4581e2278 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -1,6 +1,42 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3import { Server } from './server'; 3import { Server } from './server';
4import { Ctx } from './ctx';
5
6export function activateInlayHints(ctx: Ctx) {
7 const hintsUpdater = new HintsUpdater();
8 hintsUpdater.refreshHintsForVisibleEditors().then(() => {
9 // vscode may ignore top level hintsUpdater.refreshHintsForVisibleEditors()
10 // so update the hints once when the focus changes to guarantee their presence
11 let editorChangeDisposable: vscode.Disposable | null = null;
12 editorChangeDisposable = vscode.window.onDidChangeActiveTextEditor(
13 _ => {
14 if (editorChangeDisposable !== null) {
15 editorChangeDisposable.dispose();
16 }
17 return hintsUpdater.refreshHintsForVisibleEditors();
18 },
19 );
20
21 ctx.pushCleanup(
22 vscode.window.onDidChangeVisibleTextEditors(_ =>
23 hintsUpdater.refreshHintsForVisibleEditors(),
24 ),
25 );
26 ctx.pushCleanup(
27 vscode.workspace.onDidChangeTextDocument(e =>
28 hintsUpdater.refreshHintsForVisibleEditors(e),
29 ),
30 );
31 ctx.pushCleanup(
32 vscode.workspace.onDidChangeConfiguration(_ =>
33 hintsUpdater.toggleHintsDisplay(
34 Server.config.displayInlayHints,
35 ),
36 ),
37 );
38 });
39}
4 40
5interface InlayHintsParams { 41interface InlayHintsParams {
6 textDocument: lc.TextDocumentIdentifier; 42 textDocument: lc.TextDocumentIdentifier;
@@ -18,7 +54,7 @@ const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
18 }, 54 },
19}); 55});
20 56
21export class HintsUpdater { 57class HintsUpdater {
22 private displayHints = true; 58 private displayHints = true;
23 59
24 public async toggleHintsDisplay(displayHints: boolean): Promise<void> { 60 public async toggleHintsDisplay(displayHints: boolean): Promise<void> {
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index d6c210579..7e63a9cac 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3 3
4import * as commands from './commands'; 4import * as commands from './commands';
5import { HintsUpdater } from './inlay_hints'; 5import { activateInlayHints } from './inlay_hints';
6import { StatusDisplay } from './status_display'; 6import { StatusDisplay } from './status_display';
7import * as events from './events'; 7import * as events from './events';
8import * as notifications from './notifications'; 8import * as notifications from './notifications';
@@ -37,10 +37,6 @@ export async function activate(context: vscode.ExtensionContext) {
37 ); 37 );
38 ctx.pushCleanup(watchStatus); 38 ctx.pushCleanup(watchStatus);
39 39
40 function disposeOnDeactivation(disposable: vscode.Disposable) {
41 context.subscriptions.push(disposable);
42 }
43
44 // Notifications are events triggered by the language server 40 // Notifications are events triggered by the language server
45 const allNotifications: [string, lc.GenericNotificationHandler][] = [ 41 const allNotifications: [string, lc.GenericNotificationHandler][] = [
46 [ 42 [
@@ -71,38 +67,7 @@ export async function activate(context: vscode.ExtensionContext) {
71 } 67 }
72 68
73 if (Server.config.displayInlayHints) { 69 if (Server.config.displayInlayHints) {
74 const hintsUpdater = new HintsUpdater(); 70 activateInlayHints(ctx);
75 hintsUpdater.refreshHintsForVisibleEditors().then(() => {
76 // vscode may ignore top level hintsUpdater.refreshHintsForVisibleEditors()
77 // so update the hints once when the focus changes to guarantee their presence
78 let editorChangeDisposable: vscode.Disposable | null = null;
79 editorChangeDisposable = vscode.window.onDidChangeActiveTextEditor(
80 _ => {
81 if (editorChangeDisposable !== null) {
82 editorChangeDisposable.dispose();
83 }
84 return hintsUpdater.refreshHintsForVisibleEditors();
85 },
86 );
87
88 disposeOnDeactivation(
89 vscode.window.onDidChangeVisibleTextEditors(_ =>
90 hintsUpdater.refreshHintsForVisibleEditors(),
91 ),
92 );
93 disposeOnDeactivation(
94 vscode.workspace.onDidChangeTextDocument(e =>
95 hintsUpdater.refreshHintsForVisibleEditors(e),
96 ),
97 );
98 disposeOnDeactivation(
99 vscode.workspace.onDidChangeConfiguration(_ =>
100 hintsUpdater.toggleHintsDisplay(
101 Server.config.displayInlayHints,
102 ),
103 ),
104 );
105 });
106 } 71 }
107} 72}
108 73