diff options
author | Aleksey Kladov <[email protected]> | 2019-12-30 19:21:25 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-30 19:24:30 +0000 |
commit | 9ead314005afd835ca64b5db9117e1c495814e17 (patch) | |
tree | 67ef26be75ec5db5fd66761a67b65a09e42d363e /editors/code/src/inlay_hints.ts | |
parent | b8368f09b4857a225ff9e59dd8977ed21c408536 (diff) |
Encapsulate inlay hints activation
Diffstat (limited to 'editors/code/src/inlay_hints.ts')
-rw-r--r-- | editors/code/src/inlay_hints.ts | 38 |
1 files changed, 37 insertions, 1 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 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import { Server } from './server'; | 3 | import { Server } from './server'; |
4 | import { Ctx } from './ctx'; | ||
5 | |||
6 | export 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 | ||
5 | interface InlayHintsParams { | 41 | interface InlayHintsParams { |
6 | textDocument: lc.TextDocumentIdentifier; | 42 | textDocument: lc.TextDocumentIdentifier; |
@@ -18,7 +54,7 @@ const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ | |||
18 | }, | 54 | }, |
19 | }); | 55 | }); |
20 | 56 | ||
21 | export class HintsUpdater { | 57 | class 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> { |