aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/runnables.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/runnables.ts')
-rw-r--r--editors/code/src/commands/runnables.ts52
1 files changed, 27 insertions, 25 deletions
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index ac59bf60d..cf980e257 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -46,17 +46,17 @@ function createTask(spec: Runnable): vscode.Task {
46 label: spec.label, 46 label: spec.label,
47 command: spec.bin, 47 command: spec.bin,
48 args: spec.args, 48 args: spec.args,
49 env: spec.env 49 env: spec.env,
50 }; 50 };
51 51
52 const execOption: vscode.ShellExecutionOptions = { 52 const execOption: vscode.ShellExecutionOptions = {
53 cwd: spec.cwd || '.', 53 cwd: spec.cwd || '.',
54 env: definition.env 54 env: definition.env,
55 }; 55 };
56 const exec = new vscode.ShellExecution( 56 const exec = new vscode.ShellExecution(
57 definition.command, 57 definition.command,
58 definition.args, 58 definition.args,
59 execOption 59 execOption,
60 ); 60 );
61 61
62 const f = vscode.workspace.workspaceFolders![0]; 62 const f = vscode.workspace.workspaceFolders![0];
@@ -66,30 +66,30 @@ function createTask(spec: Runnable): vscode.Task {
66 definition.label, 66 definition.label,
67 TASK_SOURCE, 67 TASK_SOURCE,
68 exec, 68 exec,
69 ['$rustc'] 69 ['$rustc'],
70 ); 70 );
71 t.presentationOptions.clear = true; 71 t.presentationOptions.clear = true;
72 return t; 72 return t;
73} 73}
74 74
75let prevRunnable: RunnableQuickPick | undefined; 75let prevRunnable: RunnableQuickPick | undefined;
76export async function handle() { 76export async function handle(): Promise<vscode.TaskExecution | undefined> {
77 const editor = vscode.window.activeTextEditor; 77 const editor = vscode.window.activeTextEditor;
78 if (editor == null || editor.document.languageId !== 'rust') { 78 if (editor == null || editor.document.languageId !== 'rust') {
79 return; 79 return;
80 } 80 }
81 const textDocument: lc.TextDocumentIdentifier = { 81 const textDocument: lc.TextDocumentIdentifier = {
82 uri: editor.document.uri.toString() 82 uri: editor.document.uri.toString(),
83 }; 83 };
84 const params: RunnablesParams = { 84 const params: RunnablesParams = {
85 textDocument, 85 textDocument,
86 position: Server.client.code2ProtocolConverter.asPosition( 86 position: Server.client.code2ProtocolConverter.asPosition(
87 editor.selection.active 87 editor.selection.active,
88 ) 88 ),
89 }; 89 };
90 const runnables = await Server.client.sendRequest<Runnable[]>( 90 const runnables = await Server.client.sendRequest<Runnable[]>(
91 'rust-analyzer/runnables', 91 'rust-analyzer/runnables',
92 params 92 params,
93 ); 93 );
94 const items: RunnableQuickPick[] = []; 94 const items: RunnableQuickPick[] = [];
95 if (prevRunnable) { 95 if (prevRunnable) {
@@ -105,12 +105,14 @@ export async function handle() {
105 items.push(new RunnableQuickPick(r)); 105 items.push(new RunnableQuickPick(r));
106 } 106 }
107 const item = await vscode.window.showQuickPick(items); 107 const item = await vscode.window.showQuickPick(items);
108 if (item) { 108 if (!item) {
109 item.detail = 'rerun'; 109 return;
110 prevRunnable = item;
111 const task = createTask(item.runnable);
112 return await vscode.tasks.executeTask(task);
113 } 110 }
111
112 item.detail = 'rerun';
113 prevRunnable = item;
114 const task = createTask(item.runnable);
115 return await vscode.tasks.executeTask(task);
114} 116}
115 117
116export async function handleSingle(runnable: Runnable) { 118export async function handleSingle(runnable: Runnable) {
@@ -124,7 +126,7 @@ export async function handleSingle(runnable: Runnable) {
124 task.presentationOptions = { 126 task.presentationOptions = {
125 reveal: vscode.TaskRevealKind.Always, 127 reveal: vscode.TaskRevealKind.Always,
126 panel: vscode.TaskPanelKind.Dedicated, 128 panel: vscode.TaskPanelKind.Dedicated,
127 clear: true 129 clear: true,
128 }; 130 };
129 131
130 return vscode.tasks.executeTask(task); 132 return vscode.tasks.executeTask(task);
@@ -136,7 +138,7 @@ export async function handleSingle(runnable: Runnable) {
136 * that, when accepted, allow us to `cargo install cargo-watch` and then run it. 138 * that, when accepted, allow us to `cargo install cargo-watch` and then run it.
137 */ 139 */
138export async function interactivelyStartCargoWatch( 140export async function interactivelyStartCargoWatch(
139 context: vscode.ExtensionContext 141 context: vscode.ExtensionContext,
140): Promise<CargoWatchProvider | undefined> { 142): Promise<CargoWatchProvider | undefined> {
141 if (Server.config.cargoWatchOptions.enableOnStartup === 'disabled') { 143 if (Server.config.cargoWatchOptions.enableOnStartup === 'disabled') {
142 return; 144 return;
@@ -146,7 +148,7 @@ export async function interactivelyStartCargoWatch(
146 const watch = await vscode.window.showInformationMessage( 148 const watch = await vscode.window.showInformationMessage(
147 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)', 149 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)',
148 'yes', 150 'yes',
149 'no' 151 'no',
150 ); 152 );
151 if (watch !== 'yes') { 153 if (watch !== 'yes') {
152 return; 154 return;
@@ -157,12 +159,12 @@ export async function interactivelyStartCargoWatch(
157} 159}
158 160
159export async function startCargoWatch( 161export async function startCargoWatch(
160 context: vscode.ExtensionContext 162 context: vscode.ExtensionContext,
161): Promise<CargoWatchProvider | undefined> { 163): Promise<CargoWatchProvider | undefined> {
162 const execPromise = util.promisify(child_process.exec); 164 const execPromise = util.promisify(child_process.exec);
163 165
164 const { stderr, code = 0 } = await execPromise( 166 const { stderr, code = 0 } = await execPromise(
165 'cargo watch --version' 167 'cargo watch --version',
166 ).catch(e => e); 168 ).catch(e => e);
167 169
168 if (stderr.includes('no such subcommand: `watch`')) { 170 if (stderr.includes('no such subcommand: `watch`')) {
@@ -171,14 +173,14 @@ export async function startCargoWatch(
171 const install = await vscode.window.showInformationMessage( 173 const install = await vscode.window.showInformationMessage(
172 msg, 174 msg,
173 'yes', 175 'yes',
174 'no' 176 'no',
175 ); 177 );
176 if (install !== 'yes') { 178 if (install !== 'yes') {
177 return; 179 return;
178 } 180 }
179 181
180 const label = 'install-cargo-watch'; 182 const label = 'install-cargo-watch';
181 const taskFinished = new Promise((resolve, reject) => { 183 const taskFinished = new Promise((resolve, _reject) => {
182 const disposable = vscode.tasks.onDidEndTask(({ execution }) => { 184 const disposable = vscode.tasks.onDidEndTask(({ execution }) => {
183 if (execution.task.name === label) { 185 if (execution.task.name === label) {
184 disposable.dispose(); 186 disposable.dispose();
@@ -192,20 +194,20 @@ export async function startCargoWatch(
192 label, 194 label,
193 bin: 'cargo', 195 bin: 'cargo',
194 args: ['install', 'cargo-watch'], 196 args: ['install', 'cargo-watch'],
195 env: {} 197 env: {},
196 }) 198 }),
197 ); 199 );
198 await taskFinished; 200 await taskFinished;
199 const output = await execPromise('cargo watch --version').catch(e => e); 201 const output = await execPromise('cargo watch --version').catch(e => e);
200 if (output.stderr !== '') { 202 if (output.stderr !== '') {
201 vscode.window.showErrorMessage( 203 vscode.window.showErrorMessage(
202 `Couldn't install \`cargo-\`watch: ${output.stderr}` 204 `Couldn't install \`cargo-\`watch: ${output.stderr}`,
203 ); 205 );
204 return; 206 return;
205 } 207 }
206 } else if (code !== 0) { 208 } else if (code !== 0) {
207 vscode.window.showErrorMessage( 209 vscode.window.showErrorMessage(
208 `\`cargo watch\` failed with ${code}: ${stderr}` 210 `\`cargo watch\` failed with ${code}: ${stderr}`,
209 ); 211 );
210 return; 212 return;
211 } 213 }