diff options
author | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
commit | b21d9337d9200e2cfdc90b386591c72c302dc03e (patch) | |
tree | f81f5c08f821115cee26fa4d3ceaae88c7807fd5 /editors/code/src/extension.ts | |
parent | 18a0937585b836ec5ed054b9ae48e0156ab6d9ef (diff) | |
parent | ce07a2daa9e53aa86a769f8641b14c2878444fbc (diff) |
Merge branch 'master' into feature/themes
Diffstat (limited to 'editors/code/src/extension.ts')
-rw-r--r-- | editors/code/src/extension.ts | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 683497dfd..815f3692c 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -7,14 +7,14 @@ import { ExpandMacroContentProvider } from './commands/expand_macro'; | |||
7 | import { HintsUpdater } from './commands/inlay_hints'; | 7 | import { HintsUpdater } from './commands/inlay_hints'; |
8 | import { | 8 | import { |
9 | interactivelyStartCargoWatch, | 9 | interactivelyStartCargoWatch, |
10 | startCargoWatch | 10 | startCargoWatch, |
11 | } from './commands/runnables'; | 11 | } from './commands/runnables'; |
12 | import { SyntaxTreeContentProvider } from './commands/syntaxTree'; | 12 | import { SyntaxTreeContentProvider } from './commands/syntaxTree'; |
13 | import * as events from './events'; | 13 | import * as events from './events'; |
14 | import * as notifications from './notifications'; | 14 | import * as notifications from './notifications'; |
15 | import { Server } from './server'; | 15 | import { Server } from './server'; |
16 | 16 | ||
17 | export function activate(context: vscode.ExtensionContext) { | 17 | export async function activate(context: vscode.ExtensionContext) { |
18 | function disposeOnDeactivation(disposable: vscode.Disposable) { | 18 | function disposeOnDeactivation(disposable: vscode.Disposable) { |
19 | context.subscriptions.push(disposable); | 19 | context.subscriptions.push(disposable); |
20 | } | 20 | } |
@@ -24,7 +24,7 @@ export function activate(context: vscode.ExtensionContext) { | |||
24 | } | 24 | } |
25 | function overrideCommand( | 25 | function overrideCommand( |
26 | name: string, | 26 | name: string, |
27 | f: (...args: any[]) => Promise<boolean> | 27 | f: (...args: any[]) => Promise<boolean>, |
28 | ) { | 28 | ) { |
29 | const defaultCmd = `default:${name}`; | 29 | const defaultCmd = `default:${name}`; |
30 | const original = (...args: any[]) => | 30 | const original = (...args: any[]) => |
@@ -46,7 +46,7 @@ export function activate(context: vscode.ExtensionContext) { | |||
46 | }); | 46 | }); |
47 | } catch (_) { | 47 | } catch (_) { |
48 | vscode.window.showWarningMessage( | 48 | vscode.window.showWarningMessage( |
49 | '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' | 49 | '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', |
50 | ); | 50 | ); |
51 | } | 51 | } |
52 | } | 52 | } |
@@ -54,14 +54,14 @@ export function activate(context: vscode.ExtensionContext) { | |||
54 | // Commands are requests from vscode to the language server | 54 | // Commands are requests from vscode to the language server |
55 | registerCommand( | 55 | registerCommand( |
56 | 'rust-analyzer.analyzerStatus', | 56 | 'rust-analyzer.analyzerStatus', |
57 | commands.analyzerStatus.makeCommand(context) | 57 | commands.analyzerStatus.makeCommand(context), |
58 | ); | 58 | ); |
59 | registerCommand('rust-analyzer.collectGarbage', () => | 59 | registerCommand('rust-analyzer.collectGarbage', () => |
60 | Server.client.sendRequest<null>('rust-analyzer/collectGarbage', null) | 60 | Server.client.sendRequest<null>('rust-analyzer/collectGarbage', null), |
61 | ); | 61 | ); |
62 | registerCommand( | 62 | registerCommand( |
63 | 'rust-analyzer.matchingBrace', | 63 | 'rust-analyzer.matchingBrace', |
64 | commands.matchingBrace.handle | 64 | commands.matchingBrace.handle, |
65 | ); | 65 | ); |
66 | registerCommand('rust-analyzer.joinLines', commands.joinLines.handle); | 66 | registerCommand('rust-analyzer.joinLines', commands.joinLines.handle); |
67 | registerCommand('rust-analyzer.parentModule', commands.parentModule.handle); | 67 | registerCommand('rust-analyzer.parentModule', commands.parentModule.handle); |
@@ -70,7 +70,7 @@ export function activate(context: vscode.ExtensionContext) { | |||
70 | registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle); | 70 | registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle); |
71 | registerCommand( | 71 | registerCommand( |
72 | 'rust-analyzer.applySourceChange', | 72 | 'rust-analyzer.applySourceChange', |
73 | commands.applySourceChange.handle | 73 | commands.applySourceChange.handle, |
74 | ); | 74 | ); |
75 | registerCommand( | 75 | registerCommand( |
76 | 'rust-analyzer.showReferences', | 76 | 'rust-analyzer.showReferences', |
@@ -79,9 +79,9 @@ export function activate(context: vscode.ExtensionContext) { | |||
79 | 'editor.action.showReferences', | 79 | 'editor.action.showReferences', |
80 | vscode.Uri.parse(uri), | 80 | vscode.Uri.parse(uri), |
81 | Server.client.protocol2CodeConverter.asPosition(position), | 81 | Server.client.protocol2CodeConverter.asPosition(position), |
82 | locations.map(Server.client.protocol2CodeConverter.asLocation) | 82 | locations.map(Server.client.protocol2CodeConverter.asLocation), |
83 | ); | 83 | ); |
84 | } | 84 | }, |
85 | ); | 85 | ); |
86 | 86 | ||
87 | if (Server.config.enableEnhancedTyping) { | 87 | if (Server.config.enableEnhancedTyping) { |
@@ -89,48 +89,49 @@ export function activate(context: vscode.ExtensionContext) { | |||
89 | } | 89 | } |
90 | 90 | ||
91 | // Notifications are events triggered by the language server | 91 | // Notifications are events triggered by the language server |
92 | const allNotifications: Iterable< | 92 | const allNotifications: Iterable<[ |
93 | [string, lc.GenericNotificationHandler] | 93 | string, |
94 | > = [ | 94 | lc.GenericNotificationHandler, |
95 | ]> = [ | ||
95 | [ | 96 | [ |
96 | 'rust-analyzer/publishDecorations', | 97 | 'rust-analyzer/publishDecorations', |
97 | notifications.publishDecorations.handle | 98 | notifications.publishDecorations.handle, |
98 | ] | 99 | ], |
99 | ]; | 100 | ]; |
100 | const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); | 101 | const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); |
101 | const expandMacroContentProvider = new ExpandMacroContentProvider(); | 102 | const expandMacroContentProvider = new ExpandMacroContentProvider(); |
102 | 103 | ||
103 | // The events below are plain old javascript events, triggered and handled by vscode | 104 | // The events below are plain old javascript events, triggered and handled by vscode |
104 | vscode.window.onDidChangeActiveTextEditor( | 105 | vscode.window.onDidChangeActiveTextEditor( |
105 | events.changeActiveTextEditor.makeHandler(syntaxTreeContentProvider) | 106 | events.changeActiveTextEditor.makeHandler(syntaxTreeContentProvider), |
106 | ); | 107 | ); |
107 | 108 | ||
108 | disposeOnDeactivation( | 109 | disposeOnDeactivation( |
109 | vscode.workspace.registerTextDocumentContentProvider( | 110 | vscode.workspace.registerTextDocumentContentProvider( |
110 | 'rust-analyzer', | 111 | 'rust-analyzer', |
111 | syntaxTreeContentProvider | 112 | syntaxTreeContentProvider, |
112 | ) | 113 | ), |
113 | ); | 114 | ); |
114 | disposeOnDeactivation( | 115 | disposeOnDeactivation( |
115 | vscode.workspace.registerTextDocumentContentProvider( | 116 | vscode.workspace.registerTextDocumentContentProvider( |
116 | 'rust-analyzer', | 117 | 'rust-analyzer', |
117 | expandMacroContentProvider | 118 | expandMacroContentProvider, |
118 | ) | 119 | ), |
119 | ); | 120 | ); |
120 | 121 | ||
121 | registerCommand( | 122 | registerCommand( |
122 | 'rust-analyzer.syntaxTree', | 123 | 'rust-analyzer.syntaxTree', |
123 | commands.syntaxTree.createHandle(syntaxTreeContentProvider) | 124 | commands.syntaxTree.createHandle(syntaxTreeContentProvider), |
124 | ); | 125 | ); |
125 | registerCommand( | 126 | registerCommand( |
126 | 'rust-analyzer.expandMacro', | 127 | 'rust-analyzer.expandMacro', |
127 | commands.expandMacro.createHandle(expandMacroContentProvider) | 128 | commands.expandMacro.createHandle(expandMacroContentProvider), |
128 | ); | 129 | ); |
129 | 130 | ||
130 | vscode.workspace.onDidChangeTextDocument( | 131 | vscode.workspace.onDidChangeTextDocument( |
131 | events.changeTextDocument.createHandler(syntaxTreeContentProvider), | 132 | events.changeTextDocument.createHandler(syntaxTreeContentProvider), |
132 | null, | 133 | null, |
133 | context.subscriptions | 134 | context.subscriptions, |
134 | ); | 135 | ); |
135 | 136 | ||
136 | const startServer = () => Server.start(allNotifications); | 137 | const startServer = () => Server.start(allNotifications); |
@@ -159,7 +160,11 @@ export function activate(context: vscode.ExtensionContext) { | |||
159 | }); | 160 | }); |
160 | 161 | ||
161 | // Start the language server, finally! | 162 | // Start the language server, finally! |
162 | startServer(); | 163 | try { |
164 | await startServer(); | ||
165 | } catch (e) { | ||
166 | vscode.window.showErrorMessage(e.message); | ||
167 | } | ||
163 | 168 | ||
164 | if (Server.config.displayInlayHints) { | 169 | if (Server.config.displayInlayHints) { |
165 | const hintsUpdater = new HintsUpdater(); | 170 | const hintsUpdater = new HintsUpdater(); |
@@ -173,25 +178,25 @@ export function activate(context: vscode.ExtensionContext) { | |||
173 | editorChangeDisposable.dispose(); | 178 | editorChangeDisposable.dispose(); |
174 | } | 179 | } |
175 | return hintsUpdater.refreshHintsForVisibleEditors(); | 180 | return hintsUpdater.refreshHintsForVisibleEditors(); |
176 | } | 181 | }, |
177 | ); | 182 | ); |
178 | 183 | ||
179 | disposeOnDeactivation( | 184 | disposeOnDeactivation( |
180 | vscode.window.onDidChangeVisibleTextEditors(_ => | 185 | vscode.window.onDidChangeVisibleTextEditors(_ => |
181 | hintsUpdater.refreshHintsForVisibleEditors() | 186 | hintsUpdater.refreshHintsForVisibleEditors(), |
182 | ) | 187 | ), |
183 | ); | 188 | ); |
184 | disposeOnDeactivation( | 189 | disposeOnDeactivation( |
185 | vscode.workspace.onDidChangeTextDocument(e => | 190 | vscode.workspace.onDidChangeTextDocument(e => |
186 | hintsUpdater.refreshHintsForVisibleEditors(e) | 191 | hintsUpdater.refreshHintsForVisibleEditors(e), |
187 | ) | 192 | ), |
188 | ); | 193 | ); |
189 | disposeOnDeactivation( | 194 | disposeOnDeactivation( |
190 | vscode.workspace.onDidChangeConfiguration(_ => | 195 | vscode.workspace.onDidChangeConfiguration(_ => |
191 | hintsUpdater.toggleHintsDisplay( | 196 | hintsUpdater.toggleHintsDisplay( |
192 | Server.config.displayInlayHints | 197 | Server.config.displayInlayHints, |
193 | ) | 198 | ), |
194 | ) | 199 | ), |
195 | ); | 200 | ); |
196 | }); | 201 | }); |
197 | } | 202 | } |
@@ -204,10 +209,10 @@ export function deactivate(): Thenable<void> { | |||
204 | return Server.client.stop(); | 209 | return Server.client.stop(); |
205 | } | 210 | } |
206 | 211 | ||
207 | async function reloadServer(startServer: () => void) { | 212 | async function reloadServer(startServer: () => Promise<void>) { |
208 | if (Server.client != null) { | 213 | if (Server.client != null) { |
209 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); | 214 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); |
210 | await Server.client.stop(); | 215 | await Server.client.stop(); |
211 | startServer(); | 216 | await startServer(); |
212 | } | 217 | } |
213 | } | 218 | } |