Skip to content

Commit 89adef0

Browse files
committed
Save SPARK options selection to persistent workspace state
1 parent e402813 commit 89adef0

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

integration/vscode/ada/src/sparkOptionsPicker.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CancellationError, QuickPickItem } from 'vscode';
2+
import { adaExtState } from './extension';
23
import { InputFlowAction, MultiStepInput } from './multiStepInput';
34

45
interface SPARKOption extends QuickPickItem {
@@ -28,7 +29,15 @@ interface PickerState {
2829
options: SPARKOption[];
2930
}
3031

31-
let lastState: Partial<PickerState> = {};
32+
interface SavedPickerState {
33+
proofLevelLabel: string;
34+
optionLabels: string[];
35+
}
36+
37+
/**
38+
* Key for storing picker state in the workspace state map.
39+
*/
40+
const WS_STATE_KEY_PICKER = 'ada.spark.lastPickerState';
3241

3342
export async function askSPARKOptions(): Promise<string[]> {
3443
const title = 'Select GNATprove Options';
@@ -58,21 +67,29 @@ export async function askSPARKOptions(): Promise<string[]> {
5867
state.options = choice;
5968
}
6069

70+
const savedState =
71+
adaExtState.context.workspaceState.get<Partial<SavedPickerState>>(WS_STATE_KEY_PICKER) ??
72+
{};
73+
const pickerState: Partial<PickerState> = {
74+
proofLevel: proofLevels.find((v) => v.label == savedState?.proofLevelLabel),
75+
options: options.filter((o) => savedState?.optionLabels?.find((v) => v == o.label)),
76+
};
6177
try {
62-
const tmpState = { ...lastState };
63-
await MultiStepInput.run((input) => pickProofLevel(input, tmpState));
78+
await MultiStepInput.run((input) => pickProofLevel(input, pickerState));
6479
/**
6580
* Save chosen selection for next usage
6681
*/
67-
lastState = tmpState;
82+
savedState.proofLevelLabel = pickerState.proofLevel?.label;
83+
savedState.optionLabels = pickerState.options?.map((o) => o.label);
84+
adaExtState.context.workspaceState.update(WS_STATE_KEY_PICKER, savedState);
6885
} catch (err) {
6986
if (err == InputFlowAction.cancel) {
7087
// Selection was cancelled, interrupt the process
7188
throw new CancellationError();
7289
}
7390
}
7491

75-
return toCLIArgs(lastState);
92+
return toCLIArgs(pickerState);
7693
}
7794

7895
function toCLIArgs(choices: Partial<PickerState>): string[] {

0 commit comments

Comments
 (0)