Skip to content

Commit e402813

Browse files
committed
Expose SPARK options picker as a reusable command
1 parent ae70b16 commit e402813

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

integration/vscode/ada/src/commands.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const CMD_GET_PROJECT_FILE = 'ada.getProjectFile';
8888
export const CMD_SPARK_LIMIT_SUBP_ARG = 'ada.spark.limitSubpArg';
8989
export const CMD_SPARK_LIMIT_REGION_ARG = 'ada.spark.limitRegionArg';
9090
export const CMD_SPARK_PROVE_SUBP = 'ada.spark.proveSubprogram';
91+
const CMD_SPARK_ASK_OPTIONS = 'ada.spark.askSPARKOptions';
9192

9293
/**
9394
* Identifier for the command that shows the extension's output in the Output panel.
@@ -247,6 +248,8 @@ export function registerCommands(context: vscode.ExtensionContext, clients: Exte
247248
vscode.commands.registerCommand(CMD_SPARK_PROVE_SUBP, sparkProveSubprogram),
248249
);
249250

251+
context.subscriptions.push(commands.registerCommand(CMD_SPARK_ASK_OPTIONS, askSPARKOptions));
252+
250253
context.subscriptions.push(
251254
commands.registerCommand('ada.loadGnatCovXMLReport', loadGnatCovXMLReport),
252255
);
@@ -1052,15 +1055,11 @@ async function sparkProveSubprogram(
10521055
uri: vscode.Uri,
10531056
range: vscode.Range,
10541057
): Promise<vscode.TaskExecution> {
1055-
const [tasks, cliArgs] = await Promise.all([
1056-
vscode.tasks.fetchTasks({ type: TASK_TYPE_SPARK }),
1057-
askSPARKOptions(),
1058-
]);
1059-
10601058
/**
10611059
* Get the 'Prove subprogram' task. Prioritize workspace tasks so that User
10621060
* customization of the task takes precedence.
10631061
*/
1062+
const tasks = await vscode.tasks.fetchTasks({ type: TASK_TYPE_SPARK });
10641063
const task = tasks
10651064
.sort(workspaceTasksFirst)
10661065
.find(
@@ -1094,7 +1093,7 @@ async function sparkProveSubprogram(
10941093
*/
10951094
const taskDef = newTask.definition as SimpleTaskDef;
10961095
assert(taskDef.args);
1097-
const regionArg = '${command:ada.spark.limitSubpArg}';
1096+
const regionArg = `\${command:${CMD_SPARK_LIMIT_SUBP_ARG}}`;
10981097
const regionArgIdx = taskDef.args.findIndex((arg) => arg == regionArg);
10991098
if (regionArgIdx >= 0) {
11001099
const fileBasename = basename(uri.fsPath);
@@ -1106,9 +1105,15 @@ async function sparkProveSubprogram(
11061105
newTask.name = `${task.name} - ${fileBasename}:${range.start.line + 1}`;
11071106

11081107
/**
1109-
* Add the options chosen by the User
1108+
* Add a command to ask the User for options. We do this instead of
1109+
* pre-evaluating the options so that all invocations on the same
1110+
* subprogram have the same set of (unevaluated) arguments, which means
1111+
* that only one task shows up in the task history for each subprogram.
1112+
* If we pre-evaluated the options, then each different set of User
1113+
* choices would yield a different entry in the task history which is
1114+
* noisy.
11101115
*/
1111-
taskDef.args.splice(regionArgIdx + 1, 0, ...cliArgs);
1116+
taskDef.args.splice(regionArgIdx + 1, 0, `\${command:${CMD_SPARK_ASK_OPTIONS}}`);
11121117
} else {
11131118
throw Error(
11141119
`Task '${getConventionalTaskLabel(task)}' is missing a '${regionArg}' argument`,

integration/vscode/ada/src/sparkOptionsPicker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface PickerState {
3030

3131
let lastState: Partial<PickerState> = {};
3232

33-
export async function askSPARKOptions() {
33+
export async function askSPARKOptions(): Promise<string[]> {
3434
const title = 'Select GNATprove Options';
3535
async function pickProofLevel(input: MultiStepInput, state: Partial<PickerState>) {
3636
const choice: SPARKOption = await input.showQuickPick({

integration/vscode/ada/src/taskProviders.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,10 @@ export class SimpleTaskProvider implements vscode.TaskProvider {
682682
await evaluateArgs(args);
683683
execution = new vscode.ShellExecution(taskDef.command, evaluatedArgs);
684684
} catch (err) {
685+
if (err instanceof vscode.CancellationError) {
686+
// It's just a cancellation, propagate as is
687+
throw err;
688+
}
685689
let msg = 'Error while evaluating task arguments.';
686690
logger.error(msg);
687691
logger.error(err);

0 commit comments

Comments
 (0)