diff options
author | Igor Matuszewski <[email protected]> | 2019-03-18 21:30:23 +0000 |
---|---|---|
committer | Igor Matuszewski <[email protected]> | 2019-03-18 21:30:23 +0000 |
commit | 60cac299640912ad1ad75644bfa0088d7ba6e367 (patch) | |
tree | 50aab7bd4a56995fa965ebd4b53d70506a8b9b4d /editors/code/src/extension.ts | |
parent | 5c3cc8c95f392c523bb638d78e0217780d6e8476 (diff) |
Separate out the interactive cargo watch procedure
Diffstat (limited to 'editors/code/src/extension.ts')
-rw-r--r-- | editors/code/src/extension.ts | 66 |
1 files changed, 3 insertions, 63 deletions
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index f915a5023..2e13c87de 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -1,10 +1,8 @@ | |||
1 | import { exec } from 'child_process'; | ||
2 | import * as util from 'util'; | ||
3 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
4 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
5 | 3 | ||
6 | import * as commands from './commands'; | 4 | import * as commands from './commands'; |
7 | import { autoCargoWatchTask, createTask } from './commands/runnables'; | 5 | import { interactivelyStartCargoWatch } from './commands/runnables'; |
8 | import { SyntaxTreeContentProvider } from './commands/syntaxTree'; | 6 | import { SyntaxTreeContentProvider } from './commands/syntaxTree'; |
9 | import * as events from './events'; | 7 | import * as events from './events'; |
10 | import * as notifications from './notifications'; | 8 | import * as notifications from './notifications'; |
@@ -122,8 +120,8 @@ export function activate(context: vscode.ExtensionContext) { | |||
122 | context.subscriptions | 120 | context.subscriptions |
123 | ); | 121 | ); |
124 | 122 | ||
125 | // Attempts to run `cargo watch`, which provides inline diagnostics on save | 123 | // Executing `cargo watch` provides us with inline diagnostics on save |
126 | askToCargoWatch(); | 124 | interactivelyStartCargoWatch(); |
127 | 125 | ||
128 | // Start the language server, finally! | 126 | // Start the language server, finally! |
129 | Server.start(allNotifications); | 127 | Server.start(allNotifications); |
@@ -135,61 +133,3 @@ export function deactivate(): Thenable<void> { | |||
135 | } | 133 | } |
136 | return Server.client.stop(); | 134 | return Server.client.stop(); |
137 | } | 135 | } |
138 | |||
139 | async function askToCargoWatch() { | ||
140 | const watch = await vscode.window.showInformationMessage( | ||
141 | 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)', | ||
142 | 'yes', | ||
143 | 'no' | ||
144 | ); | ||
145 | if (watch === 'no') { | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | const { stderr } = await util | ||
150 | .promisify(exec)('cargo watch --version') | ||
151 | .catch(e => e); | ||
152 | if (stderr.includes('no such subcommand: `watch`')) { | ||
153 | const msg = | ||
154 | 'The `cargo-watch` subcommand is not installed. Install? (takes ~1-2 minutes)'; | ||
155 | const install = await vscode.window.showInformationMessage( | ||
156 | msg, | ||
157 | 'yes', | ||
158 | 'no' | ||
159 | ); | ||
160 | if (install === 'no') { | ||
161 | return; | ||
162 | } | ||
163 | |||
164 | const label = 'install-cargo-watch'; | ||
165 | const taskFinished = new Promise((resolve, reject) => { | ||
166 | let disposable = vscode.tasks.onDidEndTask(({ execution }) => { | ||
167 | if (execution.task.name === label) { | ||
168 | disposable.dispose(); | ||
169 | resolve(); | ||
170 | } | ||
171 | }); | ||
172 | }); | ||
173 | |||
174 | vscode.tasks.executeTask( | ||
175 | createTask({ | ||
176 | label, | ||
177 | bin: 'cargo', | ||
178 | args: ['install', 'cargo-watch'], | ||
179 | env: {} | ||
180 | }) | ||
181 | ); | ||
182 | await taskFinished; | ||
183 | const { stderr } = await util | ||
184 | .promisify(exec)('cargo watch --version') | ||
185 | .catch(e => e); | ||
186 | if (stderr !== '') { | ||
187 | vscode.window.showErrorMessage( | ||
188 | `Couldn't install \`cargo-\`watch: ${stderr}` | ||
189 | ); | ||
190 | return; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | vscode.tasks.executeTask(autoCargoWatchTask); | ||
195 | } | ||