|
1 | 1 | import { CancellationError, QuickPickItem } from 'vscode'; |
| 2 | +import { adaExtState } from './extension'; |
2 | 3 | import { InputFlowAction, MultiStepInput } from './multiStepInput'; |
3 | 4 |
|
4 | 5 | interface SPARKOption extends QuickPickItem { |
@@ -28,7 +29,15 @@ interface PickerState { |
28 | 29 | options: SPARKOption[]; |
29 | 30 | } |
30 | 31 |
|
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'; |
32 | 41 |
|
33 | 42 | export async function askSPARKOptions(): Promise<string[]> { |
34 | 43 | const title = 'Select GNATprove Options'; |
@@ -58,21 +67,29 @@ export async function askSPARKOptions(): Promise<string[]> { |
58 | 67 | state.options = choice; |
59 | 68 | } |
60 | 69 |
|
| 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 | + }; |
61 | 77 | try { |
62 | | - const tmpState = { ...lastState }; |
63 | | - await MultiStepInput.run((input) => pickProofLevel(input, tmpState)); |
| 78 | + await MultiStepInput.run((input) => pickProofLevel(input, pickerState)); |
64 | 79 | /** |
65 | 80 | * Save chosen selection for next usage |
66 | 81 | */ |
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); |
68 | 85 | } catch (err) { |
69 | 86 | if (err == InputFlowAction.cancel) { |
70 | 87 | // Selection was cancelled, interrupt the process |
71 | 88 | throw new CancellationError(); |
72 | 89 | } |
73 | 90 | } |
74 | 91 |
|
75 | | - return toCLIArgs(lastState); |
| 92 | + return toCLIArgs(pickerState); |
76 | 93 | } |
77 | 94 |
|
78 | 95 | function toCLIArgs(choices: Partial<PickerState>): string[] { |
|
0 commit comments