aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/main.ts
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-30 19:25:01 +0000
committerGitHub <[email protected]>2019-12-30 19:25:01 +0000
commit17dda0972a68dd88a766c223390317dc2cb3ea00 (patch)
tree67ef26be75ec5db5fd66761a67b65a09e42d363e /editors/code/src/main.ts
parent237abb85c40672e8cdafa423db6187c107369a09 (diff)
parent9ead314005afd835ca64b5db9117e1c495814e17 (diff)
Merge #2693
2693: Encapsulate inlay hints activation r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r--editors/code/src/main.ts68
1 files changed, 10 insertions, 58 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index b8e3396a6..7e63a9cac 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -2,8 +2,8 @@ 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 './commands/inlay_hints'; 5import { activateInlayHints } from './inlay_hints';
6import { StatusDisplay } from './commands/watch_status'; 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';
9import { Server } from './server'; 9import { Server } from './server';
@@ -13,6 +13,8 @@ let ctx!: Ctx;
13 13
14export async function activate(context: vscode.ExtensionContext) { 14export async function activate(context: vscode.ExtensionContext) {
15 ctx = new Ctx(context); 15 ctx = new Ctx(context);
16
17 // Commands which invokes manually via command pallet, shortcut, etc.
16 ctx.registerCommand('analyzerStatus', commands.analyzerStatus); 18 ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
17 ctx.registerCommand('collectGarbage', commands.collectGarbage); 19 ctx.registerCommand('collectGarbage', commands.collectGarbage);
18 ctx.registerCommand('matchingBrace', commands.matchingBrace); 20 ctx.registerCommand('matchingBrace', commands.matchingBrace);
@@ -20,30 +22,11 @@ export async function activate(context: vscode.ExtensionContext) {
20 ctx.registerCommand('parentModule', commands.parentModule); 22 ctx.registerCommand('parentModule', commands.parentModule);
21 ctx.registerCommand('syntaxTree', commands.syntaxTree); 23 ctx.registerCommand('syntaxTree', commands.syntaxTree);
22 ctx.registerCommand('expandMacro', commands.expandMacro); 24 ctx.registerCommand('expandMacro', commands.expandMacro);
25 ctx.registerCommand('run', commands.run);
23 26
24 function disposeOnDeactivation(disposable: vscode.Disposable) { 27 // Internal commands which are invoked by the server.
25 context.subscriptions.push(disposable); 28 ctx.registerCommand('runSingle', commands.runSingle);
26 } 29 ctx.registerCommand('showReferences', commands.showReferences);
27
28 function registerCommand(name: string, f: any) {
29 disposeOnDeactivation(vscode.commands.registerCommand(name, f));
30 }
31
32 // Commands are requests from vscode to the language server
33 registerCommand('rust-analyzer.run', commands.runnables.handle);
34 // Unlike the above this does not send requests to the language server
35 registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle);
36 registerCommand(
37 'rust-analyzer.showReferences',
38 (uri: string, position: lc.Position, locations: lc.Location[]) => {
39 vscode.commands.executeCommand(
40 'editor.action.showReferences',
41 vscode.Uri.parse(uri),
42 Server.client.protocol2CodeConverter.asPosition(position),
43 locations.map(Server.client.protocol2CodeConverter.asLocation),
44 );
45 },
46 );
47 30
48 if (Server.config.enableEnhancedTyping) { 31 if (Server.config.enableEnhancedTyping) {
49 ctx.overrideCommand('type', commands.onEnter); 32 ctx.overrideCommand('type', commands.onEnter);
@@ -52,7 +35,7 @@ export async function activate(context: vscode.ExtensionContext) {
52 const watchStatus = new StatusDisplay( 35 const watchStatus = new StatusDisplay(
53 Server.config.cargoWatchOptions.command, 36 Server.config.cargoWatchOptions.command,
54 ); 37 );
55 disposeOnDeactivation(watchStatus); 38 ctx.pushCleanup(watchStatus);
56 39
57 // Notifications are events triggered by the language server 40 // Notifications are events triggered by the language server
58 const allNotifications: [string, lc.GenericNotificationHandler][] = [ 41 const allNotifications: [string, lc.GenericNotificationHandler][] = [
@@ -84,38 +67,7 @@ export async function activate(context: vscode.ExtensionContext) {
84 } 67 }
85 68
86 if (Server.config.displayInlayHints) { 69 if (Server.config.displayInlayHints) {
87 const hintsUpdater = new HintsUpdater(); 70 activateInlayHints(ctx);
88 hintsUpdater.refreshHintsForVisibleEditors().then(() => {
89 // vscode may ignore top level hintsUpdater.refreshHintsForVisibleEditors()
90 // so update the hints once when the focus changes to guarantee their presence
91 let editorChangeDisposable: vscode.Disposable | null = null;
92 editorChangeDisposable = vscode.window.onDidChangeActiveTextEditor(
93 _ => {
94 if (editorChangeDisposable !== null) {
95 editorChangeDisposable.dispose();
96 }
97 return hintsUpdater.refreshHintsForVisibleEditors();
98 },
99 );
100
101 disposeOnDeactivation(
102 vscode.window.onDidChangeVisibleTextEditors(_ =>
103 hintsUpdater.refreshHintsForVisibleEditors(),
104 ),
105 );
106 disposeOnDeactivation(
107 vscode.workspace.onDidChangeTextDocument(e =>
108 hintsUpdater.refreshHintsForVisibleEditors(e),
109 ),
110 );
111 disposeOnDeactivation(
112 vscode.workspace.onDidChangeConfiguration(_ =>
113 hintsUpdater.toggleHintsDisplay(
114 Server.config.displayInlayHints,
115 ),
116 ),
117 );
118 });
119 } 71 }
120} 72}
121 73