@@ -9,7 +9,7 @@ import * as fs from 'fs'
9
9
import * as os from 'os'
10
10
import { getLogger } from '../../shared/logger'
11
11
import * as CodeWhispererConstants from '../models/constants'
12
- import { transformByQState , StepProgress , DropdownStep , TransformByQReviewStatus } from '../models/model'
12
+ import { transformByQState , StepProgress , TransformByQReviewStatus } from '../models/model'
13
13
import {
14
14
throwIfCancelled ,
15
15
startJob ,
@@ -24,7 +24,6 @@ import {
24
24
validateProjectSelection ,
25
25
} from '../service/transformByQHandler'
26
26
import { QuickPickItem } from 'vscode'
27
- import { MultiStepInputFlowController } from '../../shared//multiStepInputFlowController'
28
27
import path from 'path'
29
28
import { sleep } from '../../shared/utilities/timeoutUtils'
30
29
import { encodeHTML } from '../../shared/utilities/textUtilities'
@@ -73,38 +72,25 @@ interface UserInputState {
73
72
project : QuickPickItem
74
73
}
75
74
76
- async function collectInputs ( validProjects : vscode . QuickPickItem [ ] | undefined ) {
77
- // const targetLanguages: QuickPickItem[] = CodeWhispererConstants.targetLanguages.map(label => ({ label }))
75
+ async function collectInput ( validProjects : vscode . QuickPickItem [ ] ) {
78
76
const state = { } as Partial < UserInputState >
79
- // only supporting target language of Java and target version of JDK17 for now, so skip to pickModule prompt
80
77
transformByQState . setTargetJDKVersionToJDK17 ( )
81
- await MultiStepInputFlowController . run ( input => pickProject ( input , state , validProjects ) )
82
- // await MultiStepInputFlowController.run(input => pickTargetLanguage(input, state, targetLanguages, validModules))
83
- return state as UserInputState
84
- }
85
-
86
- async function pickProject (
87
- input : MultiStepInputFlowController ,
88
- state : Partial < UserInputState > ,
89
- validProjects : vscode . QuickPickItem [ ] | undefined
90
- ) {
91
- const pick = await input . showQuickPick ( {
78
+ const pick = await vscode . window . showQuickPick ( validProjects , {
92
79
title : CodeWhispererConstants . transformByQWindowTitle ,
93
- step : DropdownStep . STEP_1 ,
94
- totalSteps : DropdownStep . STEP_1 ,
95
- placeholder : CodeWhispererConstants . selectModulePrompt ,
96
- items : validProjects ! ,
97
- shouldResume : ( ) => Promise . resolve ( false ) ,
80
+ placeHolder : CodeWhispererConstants . selectModulePrompt ,
98
81
} )
99
- state . project = pick
100
- transformByQState . setProjectName ( encodeHTML ( state . project . label ) ) // encode to avoid HTML injection risk
82
+ if ( pick ) {
83
+ state . project = pick
84
+ transformByQState . setProjectName ( encodeHTML ( state . project . label ) ) // encode to avoid HTML injection risk
85
+ }
86
+ return state as UserInputState
101
87
}
102
88
103
89
export async function startTransformByQ ( ) {
104
90
let intervalId = undefined
105
91
106
- // 1: Validate inputs. If failed, Error will be thrown and execution stops
107
- const userInputState = await validateTransformJob ( )
92
+ // Validate inputs. If failed, Error will be thrown and execution stops
93
+ const userInputState = await validateTransformationJob ( )
108
94
109
95
// Set the default state variables for our store and the UI
110
96
await setTransformationToRunningState ( userInputState )
@@ -119,29 +105,28 @@ export async function startTransformByQ() {
119
105
} , CodeWhispererConstants . progressIntervalMs )
120
106
121
107
// step 1: CreateCodeUploadUrl and upload code
122
- const uploadId = await preTransformUploadCode ( userInputState )
108
+ const uploadId = await preTransformationUploadCode ( userInputState )
123
109
124
110
// step 2: StartJob and store the returned jobId in TransformByQState
125
- const jobId = await transformStartJob ( uploadId )
111
+ const jobId = await startTransformationJob ( uploadId )
126
112
127
113
// step 3 (intermediate step): show transformation-plan.md file
128
- // TO-DO: on IDE restart, resume here if a job was ongoing
129
- await pollTransformationStatusTillPlanReady ( jobId )
114
+ await pollTransformationStatusUntilPlanReady ( jobId )
130
115
131
116
// step 4: poll until artifacts are ready to download
132
- const status = await pollTransformationTillComplete ( jobId )
117
+ const status = await pollTransformationStatusUntilComplete ( jobId )
133
118
134
119
// Set the result state variables for our store and the UI
135
120
await finalizeTransformationJob ( status )
136
121
} catch ( error : any ) {
137
- await modernizationJobErrorHandler ( error )
122
+ await transformationJobErrorHandler ( error )
138
123
} finally {
139
- await postTransformJob ( userInputState )
140
- await cleanupTransformJob ( intervalId )
124
+ await postTransformationJob ( userInputState )
125
+ await cleanupTransformationJob ( intervalId )
141
126
}
142
127
}
143
128
144
- export async function preTransformUploadCode ( userInputState : UserInputState ) {
129
+ export async function preTransformationUploadCode ( userInputState : UserInputState ) {
145
130
await vscode . commands . executeCommand ( 'aws.amazonq.refresh' )
146
131
await vscode . commands . executeCommand ( 'aws.amazonq.transformationHub.focus' )
147
132
@@ -173,7 +158,7 @@ export async function preTransformUploadCode(userInputState: UserInputState) {
173
158
return uploadId
174
159
}
175
160
176
- export async function transformStartJob ( uploadId : string ) {
161
+ export async function startTransformationJob ( uploadId : string ) {
177
162
let jobId = ''
178
163
try {
179
164
jobId = await startJob ( uploadId )
@@ -197,7 +182,7 @@ export async function transformStartJob(uploadId: string) {
197
182
return jobId
198
183
}
199
184
200
- export async function pollTransformationStatusTillPlanReady ( jobId : string ) {
185
+ export async function pollTransformationStatusUntilPlanReady ( jobId : string ) {
201
186
try {
202
187
await pollTransformationJob ( jobId , CodeWhispererConstants . validStatesForGettingPlan )
203
188
} catch ( error ) {
@@ -223,7 +208,7 @@ export async function pollTransformationStatusTillPlanReady(jobId: string) {
223
208
throwIfCancelled ( )
224
209
}
225
210
226
- export async function pollTransformationTillComplete ( jobId : string ) {
211
+ export async function pollTransformationStatusUntilComplete ( jobId : string ) {
227
212
let status = ''
228
213
try {
229
214
status = await pollTransformationJob ( jobId , CodeWhispererConstants . validStatesForCheckingDownloadUrl )
@@ -260,15 +245,19 @@ export async function finalizeTransformationJob(status: string) {
260
245
sessionPlanProgress [ 'returnCode' ] = StepProgress . Succeeded
261
246
}
262
247
263
- export async function validateTransformJob ( ) {
248
+ export async function validateTransformationJob ( ) {
264
249
let openProjects : vscode . QuickPickItem [ ] = [ ]
265
250
try {
266
251
openProjects = await getOpenProjects ( )
267
252
} catch ( err ) {
268
253
getLogger ( ) . error ( 'Failed to get open projects: ' , err )
269
254
throw err
270
255
}
271
- const userInputState = await collectInputs ( openProjects )
256
+ const userInputState = await collectInput ( openProjects )
257
+
258
+ if ( ! userInputState . project ) {
259
+ throw new ToolkitError ( 'No project selected' , { code : 'NoProjectSelected' } )
260
+ }
272
261
273
262
try {
274
263
await validateProjectSelection ( userInputState . project )
@@ -333,7 +322,7 @@ export async function setTransformationToRunningState(userInputState: UserInputS
333
322
await vscode . commands . executeCommand ( 'aws.amazonq.refresh' )
334
323
}
335
324
336
- export async function postTransformJob ( userInputState : UserInputState ) {
325
+ export async function postTransformationJob ( userInputState : UserInputState ) {
337
326
await vscode . commands . executeCommand ( 'setContext' , 'gumby.isTransformAvailable' , true )
338
327
const durationInMs = calculateTotalLatency ( codeTransformTelemetryState . getStartTime ( ) )
339
328
const resultStatusMessage = codeTransformTelemetryState . getResultStatus ( )
@@ -368,7 +357,7 @@ export async function postTransformJob(userInputState: UserInputState) {
368
357
}
369
358
}
370
359
371
- export async function modernizationJobErrorHandler ( error : any ) {
360
+ export async function transformationJobErrorHandler ( error : any ) {
372
361
if ( transformByQState . isCancelled ( ) ) {
373
362
codeTransformTelemetryState . setResultStatus ( 'JobCancelled' )
374
363
try {
@@ -403,7 +392,7 @@ export async function modernizationJobErrorHandler(error: any) {
403
392
getLogger ( ) . error ( 'Amazon Q Code Transform' , error )
404
393
}
405
394
406
- export async function cleanupTransformJob ( intervalId : NodeJS . Timeout | undefined ) {
395
+ export async function cleanupTransformationJob ( intervalId : NodeJS . Timeout | undefined ) {
407
396
clearInterval ( intervalId )
408
397
transformByQState . setJobDefaults ( )
409
398
await vscode . commands . executeCommand ( 'setContext' , 'gumby.isStopButtonAvailable' , false )
0 commit comments