@@ -14,7 +14,7 @@ const proofLevels: SPARKOption[] = [
1414 { label : '4' , description : 'Slowest, most provers' } ,
1515] . map ( ( v ) => ( { ...v , cliArgs : [ `--level=${ v . label } ` ] } ) ) ;
1616
17- const defaultProofLevel = proofLevels . find ( ( v ) => v . description ?. includes ( 'default' ) ) ;
17+ const defaultProofLevel = proofLevels . find ( ( v ) => v . description ?. includes ( 'default' ) ) ! ;
1818
1919const options : SPARKOption [ ] = [
2020 { label : 'Multiprocessing' , cliArgs : [ '-j0' ] } ,
@@ -29,6 +29,16 @@ interface PickerState {
2929 options : SPARKOption [ ] ;
3030}
3131
32+ /**
33+ * These are the applicable options when no prior selection has been made.
34+ */
35+ const defaultPickerState : PickerState = {
36+ proofLevel : defaultProofLevel ,
37+ options : [
38+ options [ 0 ] , // Multiprocessing
39+ ] ,
40+ } ;
41+
3242interface SavedPickerState {
3343 proofLevelLabel : string ;
3444 optionLabels : string [ ] ;
@@ -92,21 +102,16 @@ export async function askSPARKOptions(): Promise<string[]> {
92102 state . options = choice ;
93103 }
94104
95- const savedState =
96- adaExtState . context . workspaceState . get < Partial < SavedPickerState > > ( WS_STATE_KEY_PICKER ) ??
97- { } ;
98- const pickerState : Partial < PickerState > = {
99- proofLevel : proofLevels . find ( ( v ) => v . label == savedState ?. proofLevelLabel ) ,
100- options : options . filter ( ( o ) => savedState ?. optionLabels ?. find ( ( v ) => v == o . label ) ) ,
101- } ;
105+ const pickerState : PickerState = getSavedPickerState ( ) ;
102106 try {
103107 await MultiStepInput . run ( ( input ) => pickProofLevel ( input , pickerState ) ) ;
104108 /**
105109 * Save chosen selection for next usage
106110 */
107- savedState . proofLevelLabel = pickerState . proofLevel ?. label ;
108- savedState . optionLabels = pickerState . options ?. map ( ( o ) => o . label ) ;
109- adaExtState . context . workspaceState . update ( WS_STATE_KEY_PICKER , savedState ) ;
111+ adaExtState . context . workspaceState . update ( WS_STATE_KEY_PICKER , {
112+ proofLevelLabel : pickerState . proofLevel . label ,
113+ optionLabels : pickerState . options . map ( ( o ) => o . label ) ,
114+ } satisfies SavedPickerState ) ;
110115 } catch ( err ) {
111116 if ( err == InputFlowAction . cancel ) {
112117 // Selection was cancelled, interrupt the process
@@ -117,6 +122,21 @@ export async function askSPARKOptions(): Promise<string[]> {
117122 return toCLIArgs ( pickerState ) ;
118123}
119124
125+ function getSavedPickerState ( ) {
126+ const savedState : SavedPickerState | undefined =
127+ adaExtState . context . workspaceState . get ( WS_STATE_KEY_PICKER ) ;
128+ const pickerState : PickerState = savedState
129+ ? {
130+ // The saved proof level necessarily exists in the list of
131+ // available levels, so we use the ! operator to convince
132+ // TypeScript of that.
133+ proofLevel : proofLevels . find ( ( v ) => v . label == savedState . proofLevelLabel ) ! ,
134+ options : options . filter ( ( o ) => savedState . optionLabels ?. find ( ( v ) => v == o . label ) ) ,
135+ }
136+ : defaultPickerState ;
137+ return pickerState ;
138+ }
139+
120140function toCLIArgs ( choices : Partial < PickerState > ) : string [ ] {
121141 const args : string [ ] = [ ] ;
122142
@@ -131,12 +151,5 @@ function toCLIArgs(choices: Partial<PickerState>): string[] {
131151}
132152
133153export function getLastSPARKOptions ( ) : string [ ] {
134- const savedState =
135- adaExtState . context . workspaceState . get < Partial < SavedPickerState > > ( WS_STATE_KEY_PICKER ) ??
136- { } ;
137- const pickerState : Partial < PickerState > = {
138- proofLevel : proofLevels . find ( ( v ) => v . label == savedState ?. proofLevelLabel ) ,
139- options : options . filter ( ( o ) => savedState ?. optionLabels ?. find ( ( v ) => v == o . label ) ) ,
140- } ;
141- return toCLIArgs ( pickerState ) ;
154+ return toCLIArgs ( getSavedPickerState ( ) ) ;
142155}
0 commit comments