aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/main.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r--editors/code/src/main.ts64
1 files changed, 6 insertions, 58 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index a4149a059..d92cd164f 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -4,7 +4,6 @@ import * as lc from 'vscode-languageclient';
4import * as commands from './commands'; 4import * as commands from './commands';
5import { ExpandMacroContentProvider } from './commands/expand_macro'; 5import { ExpandMacroContentProvider } from './commands/expand_macro';
6import { HintsUpdater } from './commands/inlay_hints'; 6import { HintsUpdater } from './commands/inlay_hints';
7import { SyntaxTreeContentProvider } from './commands/syntaxTree';
8import { StatusDisplay } from './commands/watch_status'; 7import { StatusDisplay } from './commands/watch_status';
9import * as events from './events'; 8import * as events from './events';
10import * as notifications from './notifications'; 9import * as notifications from './notifications';
@@ -18,6 +17,9 @@ export async function activate(context: vscode.ExtensionContext) {
18 ctx.registerCommand('analyzerStatus', commands.analyzerStatus); 17 ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
19 ctx.registerCommand('collectGarbage', commands.collectGarbage); 18 ctx.registerCommand('collectGarbage', commands.collectGarbage);
20 ctx.registerCommand('matchingBrace', commands.matchingBrace); 19 ctx.registerCommand('matchingBrace', commands.matchingBrace);
20 ctx.registerCommand('joinLines', commands.joinLines);
21 ctx.registerCommand('parentModule', commands.parentModule);
22 ctx.registerCommand('syntaxTree', commands.syntaxTree);
21 23
22 function disposeOnDeactivation(disposable: vscode.Disposable) { 24 function disposeOnDeactivation(disposable: vscode.Disposable) {
23 context.subscriptions.push(disposable); 25 context.subscriptions.push(disposable);
@@ -26,46 +28,12 @@ export async function activate(context: vscode.ExtensionContext) {
26 function registerCommand(name: string, f: any) { 28 function registerCommand(name: string, f: any) {
27 disposeOnDeactivation(vscode.commands.registerCommand(name, f)); 29 disposeOnDeactivation(vscode.commands.registerCommand(name, f));
28 } 30 }
29 function overrideCommand(
30 name: string,
31 f: (...args: any[]) => Promise<boolean>,
32 ) {
33 const defaultCmd = `default:${name}`;
34 const original = (...args: any[]) =>
35 vscode.commands.executeCommand(defaultCmd, ...args);
36
37 try {
38 registerCommand(name, async (...args: any[]) => {
39 const editor = vscode.window.activeTextEditor;
40 if (
41 !editor ||
42 !editor.document ||
43 editor.document.languageId !== 'rust'
44 ) {
45 return await original(...args);
46 }
47 if (!(await f(...args))) {
48 return await original(...args);
49 }
50 });
51 } catch (_) {
52 vscode.window.showWarningMessage(
53 'Enhanced typing feature is disabled because of incompatibility with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings',
54 );
55 }
56 }
57 31
58 // Commands are requests from vscode to the language server 32 // Commands are requests from vscode to the language server
59 registerCommand('rust-analyzer.joinLines', commands.joinLines.handle);
60 registerCommand('rust-analyzer.parentModule', commands.parentModule.handle);
61 registerCommand('rust-analyzer.run', commands.runnables.handle); 33 registerCommand('rust-analyzer.run', commands.runnables.handle);
62 // Unlike the above this does not send requests to the language server 34 // Unlike the above this does not send requests to the language server
63 registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle); 35 registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle);
64 registerCommand( 36 registerCommand(
65 'rust-analyzer.applySourceChange',
66 commands.applySourceChange.handle,
67 );
68 registerCommand(
69 'rust-analyzer.showReferences', 37 'rust-analyzer.showReferences',
70 (uri: string, position: lc.Position, locations: lc.Location[]) => { 38 (uri: string, position: lc.Position, locations: lc.Location[]) => {
71 vscode.commands.executeCommand( 39 vscode.commands.executeCommand(
@@ -78,7 +46,7 @@ export async function activate(context: vscode.ExtensionContext) {
78 ); 46 );
79 47
80 if (Server.config.enableEnhancedTyping) { 48 if (Server.config.enableEnhancedTyping) {
81 overrideCommand('type', commands.onEnter.handle); 49 ctx.overrideCommand('type', commands.onEnter);
82 } 50 }
83 51
84 const watchStatus = new StatusDisplay( 52 const watchStatus = new StatusDisplay(
@@ -87,10 +55,7 @@ export async function activate(context: vscode.ExtensionContext) {
87 disposeOnDeactivation(watchStatus); 55 disposeOnDeactivation(watchStatus);
88 56
89 // Notifications are events triggered by the language server 57 // Notifications are events triggered by the language server
90 const allNotifications: Iterable<[ 58 const allNotifications: [string, lc.GenericNotificationHandler][] = [
91 string,
92 lc.GenericNotificationHandler,
93 ]> = [
94 [ 59 [
95 'rust-analyzer/publishDecorations', 60 'rust-analyzer/publishDecorations',
96 notifications.publishDecorations.handle, 61 notifications.publishDecorations.handle,
@@ -100,42 +65,25 @@ export async function activate(context: vscode.ExtensionContext) {
100 params => watchStatus.handleProgressNotification(params), 65 params => watchStatus.handleProgressNotification(params),
101 ], 66 ],
102 ]; 67 ];
103 const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
104 const expandMacroContentProvider = new ExpandMacroContentProvider(); 68 const expandMacroContentProvider = new ExpandMacroContentProvider();
105 69
106 // The events below are plain old javascript events, triggered and handled by vscode 70 // The events below are plain old javascript events, triggered and handled by vscode
107 vscode.window.onDidChangeActiveTextEditor( 71 vscode.window.onDidChangeActiveTextEditor(
108 events.changeActiveTextEditor.makeHandler(syntaxTreeContentProvider), 72 events.changeActiveTextEditor.makeHandler(),
109 ); 73 );
110 74
111 disposeOnDeactivation( 75 disposeOnDeactivation(
112 vscode.workspace.registerTextDocumentContentProvider( 76 vscode.workspace.registerTextDocumentContentProvider(
113 'rust-analyzer', 77 'rust-analyzer',
114 syntaxTreeContentProvider,
115 ),
116 );
117 disposeOnDeactivation(
118 vscode.workspace.registerTextDocumentContentProvider(
119 'rust-analyzer',
120 expandMacroContentProvider, 78 expandMacroContentProvider,
121 ), 79 ),
122 ); 80 );
123 81
124 registerCommand( 82 registerCommand(
125 'rust-analyzer.syntaxTree',
126 commands.syntaxTree.createHandle(syntaxTreeContentProvider),
127 );
128 registerCommand(
129 'rust-analyzer.expandMacro', 83 'rust-analyzer.expandMacro',
130 commands.expandMacro.createHandle(expandMacroContentProvider), 84 commands.expandMacro.createHandle(expandMacroContentProvider),
131 ); 85 );
132 86
133 vscode.workspace.onDidChangeTextDocument(
134 events.changeTextDocument.createHandler(syntaxTreeContentProvider),
135 null,
136 context.subscriptions,
137 );
138
139 const startServer = () => Server.start(allNotifications); 87 const startServer = () => Server.start(allNotifications);
140 const reloadCommand = () => reloadServer(startServer); 88 const reloadCommand = () => reloadServer(startServer);
141 89