Skip to content

Commit b714214

Browse files
committed
added numbering to make it obvious to user which patch file they're viewing and updated chat messaging with start transformation prompt
1 parent 02a418c commit b714214

File tree

8 files changed

+82
-39
lines changed

8 files changed

+82
-39
lines changed

packages/amazonq/test/unit/amazonqGumby/transformationResultsHandler.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ describe('DiffModel', function () {
4040
testDiffModel.parseDiff(
4141
getTestResourceFilePath('resources/files/addedFile.diff'),
4242
workspacePath,
43-
parsedTestDescriptions[0]
43+
parsedTestDescriptions[0],
44+
1
4445
)
4546

4647
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
4748
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
4849
assert.strictEqual(testDiffModel.patchFileNodes[0].patchFilePath, parsedTestDescriptions[0].name)
50+
assert(testDiffModel.patchFileNodes[0].label.endsWith(parsedTestDescriptions[0].name))
4951
const change = testDiffModel.patchFileNodes[0].children[0]
5052

5153
assert.strictEqual(change instanceof AddedChangeNode, true)
@@ -66,12 +68,14 @@ describe('DiffModel', function () {
6668
testDiffModel.parseDiff(
6769
getTestResourceFilePath('resources/files/modifiedFile.diff'),
6870
workspacePath,
69-
parsedTestDescriptions[0]
71+
parsedTestDescriptions[0],
72+
1
7073
)
7174

7275
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
7376
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
7477
assert.strictEqual(testDiffModel.patchFileNodes[0].patchFilePath, parsedTestDescriptions[0].name)
78+
assert(testDiffModel.patchFileNodes[0].label.endsWith(parsedTestDescriptions[0].name))
7579
const change = testDiffModel.patchFileNodes[0].children[0]
7680

7781
assert.strictEqual(change instanceof ModifiedChangeNode, true)
@@ -91,14 +95,20 @@ describe('DiffModel', function () {
9195
'This guide walks you through using Gradle to build a simple Java project.'
9296
)
9397

94-
testDiffModel.parseDiff(getTestResourceFilePath('resources/files/modifiedFile.diff'), workspacePath, undefined)
98+
testDiffModel.parseDiff(
99+
getTestResourceFilePath('resources/files/modifiedFile.diff'),
100+
workspacePath,
101+
undefined,
102+
1
103+
)
95104

96105
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
97106
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
98107
assert.strictEqual(
99108
testDiffModel.patchFileNodes[0].patchFilePath,
100109
getTestResourceFilePath('resources/files/modifiedFile.diff')
101110
)
111+
assert(testDiffModel.patchFileNodes[0].label.endsWith('modifiedFile.diff'))
102112
const change = testDiffModel.patchFileNodes[0].children[0]
103113

104114
assert.strictEqual(change instanceof ModifiedChangeNode, true)

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,15 @@ export class GumbyController {
454454
await this.prepareProjectForSubmission(message)
455455
}
456456

457-
private transformationFinished(data: { message: string | undefined; tabID: string }) {
457+
private transformationFinished(data: {
458+
message: string | undefined
459+
tabID: string
460+
includeStartNewTransformationButton: string
461+
}) {
458462
this.resetTransformationChatFlow()
459463
// at this point job is either completed, partially_completed, cancelled, or failed
460464
if (data.message) {
461-
this.messenger.sendJobFinishedMessage(data.tabID, data.message)
465+
this.messenger.sendJobFinishedMessage(data.tabID, data.message, data.includeStartNewTransformationButton)
462466
}
463467
}
464468

@@ -543,7 +547,11 @@ export class GumbyController {
543547
try {
544548
await finishHumanInTheLoop()
545549
} catch (err: any) {
546-
this.transformationFinished({ tabID: message.tabID, message: (err as Error).message })
550+
this.transformationFinished({
551+
tabID: message.tabID,
552+
message: (err as Error).message,
553+
includeStartNewTransformationButton: 'true',
554+
})
547555
}
548556

549557
this.messenger.sendStaticTextResponse('end-HIL-early', message.tabID)

packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,11 @@ export class Messenger {
178178
options: [
179179
{
180180
value: JDKVersion.JDK8,
181-
label: JDKVersion.JDK8,
181+
label: JDKVersion.JDK8.toString(),
182182
},
183183
{
184184
value: JDKVersion.JDK11,
185-
label: JDKVersion.JDK11,
186-
},
187-
{
188-
value: JDKVersion.JDK17,
189-
label: JDKVersion.JDK17,
185+
label: JDKVersion.JDK11.toString(),
190186
},
191187
{
192188
value: JDKVersion.UNSUPPORTED,
@@ -413,13 +409,19 @@ export class Messenger {
413409
this.dispatcher.sendCommandMessage(new SendCommandMessage(message.command, message.tabID, message.eventId))
414410
}
415411

416-
public sendJobFinishedMessage(tabID: string, message: string) {
412+
public sendJobFinishedMessage(
413+
tabID: string,
414+
message: string,
415+
includeStartNewTransformationButton: string = 'true'
416+
) {
417417
const buttons: ChatItemButton[] = []
418-
buttons.push({
419-
keepCardAfterClick: false,
420-
text: CodeWhispererConstants.startTransformationButtonText,
421-
id: ButtonActions.CONFIRM_START_TRANSFORMATION_FLOW,
422-
})
418+
if (includeStartNewTransformationButton === 'true') {
419+
buttons.push({
420+
keepCardAfterClick: false,
421+
text: CodeWhispererConstants.startTransformationButtonText,
422+
id: ButtonActions.CONFIRM_START_TRANSFORMATION_FLOW,
423+
})
424+
}
423425

424426
this.dispatcher.sendChatMessage(
425427
new ChatMessage(

packages/core/src/amazonqGumby/chat/controller/messenger/messengerUtils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ export default class MessengerUtils {
4545
javaHomePrompt += ` ${CodeWhispererConstants.macJava8HomeHelpChatMessage}`
4646
} else if (jdkVersion === JDKVersion.JDK11) {
4747
javaHomePrompt += ` ${CodeWhispererConstants.macJava11HomeHelpChatMessage}`
48-
} else if (jdkVersion === JDKVersion.JDK17) {
49-
javaHomePrompt += ` ${CodeWhispererConstants.macJava17HomeHelpChatMessage}`
5048
}
5149
} else {
5250
javaHomePrompt += ` ${CodeWhispererConstants.linuxJavaHomeHelpChatMessage}`

packages/core/src/codewhisperer/commands/startTransformByQ.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ async function validateJavaHome(): Promise<boolean> {
117117
javaVersionUsedByMaven = JDKVersion.JDK8
118118
} else if (javaVersionUsedByMaven === '11.') {
119119
javaVersionUsedByMaven = JDKVersion.JDK11
120-
} else if (javaVersionUsedByMaven === '17.') {
121-
javaVersionUsedByMaven = JDKVersion.JDK17
122120
}
123121
}
124122
if (javaVersionUsedByMaven !== transformByQState.getSourceJDKVersion()) {
@@ -713,9 +711,11 @@ export async function postTransformationJob() {
713711
chatMessage = CodeWhispererConstants.jobPartiallyCompletedChatMessage
714712
}
715713

716-
transformByQState
717-
.getChatControllers()
718-
?.transformationFinished.fire({ message: chatMessage, tabID: ChatSessionManager.Instance.getSession().tabID })
714+
transformByQState.getChatControllers()?.transformationFinished.fire({
715+
message: chatMessage,
716+
tabID: ChatSessionManager.Instance.getSession().tabID,
717+
includeStartNewTransformationButton: 'true',
718+
})
719719
const durationInMs = calculateTotalLatency(CodeTransformTelemetryState.instance.getStartTime())
720720
const resultStatusMessage = transformByQState.getStatus()
721721

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,11 @@ export const viewProposedChangesChatMessage =
600600
export const viewProposedChangesNotification =
601601
'Download complete. You can view a summary of the transformation and accept or reject the proposed changes in the Transformation Hub.'
602602

603-
export const changesAppliedChatMessage = 'I applied the changes to your project.'
603+
export const changesAppliedChatMessage = (currentPatchIndex: number, totalPatchFiles: number) =>
604+
`I applied the changes in diff patch ${currentPatchIndex + 1} of ${totalPatchFiles} to your project.`
604605

605-
export const changesAppliedNotification = 'Amazon Q applied the changes to your project.'
606+
export const changesAppliedNotification = (currentPatchIndex: number, totalPatchFiles: number) =>
607+
`Amazon Q applied the changes in diff patch ${currentPatchIndex + 1} of ${totalPatchFiles} to your project.`
606608

607609
export const noOpenProjectsFoundChatMessage = `Sorry, I couldn\'t find a project that I can upgrade. Currently, I can only upgrade Java 8 or Java 11 projects built on Maven. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
608610

@@ -637,9 +639,6 @@ export const macJava8HomeHelpChatMessage =
637639
export const macJava11HomeHelpChatMessage =
638640
'To find the JDK path, run the following command in a new terminal: `/usr/libexec/java_home -v 11`'
639641

640-
export const macJava17HomeHelpChatMessage =
641-
'To find the JDK path, run the following command in a new terminal: `/usr/libexec/java_home -v 17`'
642-
643642
export const linuxJavaHomeHelpChatMessage =
644643
'To find the JDK path, run the following command in a new terminal: `update-java-alternatives --list`'
645644

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ export async function zipCode(
378378
transformByQState.getChatControllers()?.transformationFinished.fire({
379379
message: CodeWhispererConstants.projectSizeTooLargeChatMessage,
380380
tabID: ChatSessionManager.Instance.getSession().tabID,
381+
includeStartNewTransformationButton: 'true',
381382
})
382383
throw new ZipExceedsSizeLimitError()
383384
}

packages/core/src/codewhisperer/service/transformByQ/transformationResultsViewProvider.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class AddedChangeNode extends ProposedChangeNode {
107107
}
108108

109109
export class PatchFileNode {
110-
readonly label: string
110+
label: string
111111
readonly patchFilePath: string
112112
children: ProposedChangeNode[] = []
113113

@@ -157,7 +157,8 @@ export class DiffModel {
157157
public parseDiff(
158158
pathToDiff: string,
159159
pathToWorkspace: string,
160-
diffDescription: PatchInfo | undefined
160+
diffDescription: PatchInfo | undefined,
161+
totalDiffPatches: number
161162
): PatchFileNode {
162163
this.patchFileNodes = []
163164
const diffContents = fs.readFileSync(pathToDiff, 'utf8')
@@ -195,6 +196,7 @@ export class DiffModel {
195196
},
196197
})
197198
const patchFileNode = new PatchFileNode(diffDescription ? diffDescription.name : pathToDiff)
199+
patchFileNode.label = `Patch ${this.currentPatchIndex + 1} of ${totalDiffPatches}: ${patchFileNode.label}`
198200
patchFileNode.children = changedFiles.flatMap((file) => {
199201
/* ex. file.oldFileName = 'a/src/java/com/project/component/MyFile.java'
200202
* ex. file.newFileName = 'b/src/java/com/project/component/MyFile.java'
@@ -259,7 +261,7 @@ export class TransformationResultsProvider implements vscode.TreeDataProvider<Pr
259261
if (element instanceof PatchFileNode) {
260262
return {
261263
label: element.label,
262-
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
264+
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
263265
}
264266
} else {
265267
return {
@@ -308,7 +310,6 @@ export class ProposedTransformationExplorer {
308310
treeDataProvider: transformDataProvider,
309311
})
310312

311-
// const pathContainingArchive = '/private/var/folders/mn/l6c4t6sd1jn7g4p4nb6wqhh80000gq/T/ExportResultArchive'
312313
const patchFiles: string[] = []
313314
let patchFilesDescriptions: PatchInfo[] | undefined = undefined
314315

@@ -403,6 +404,7 @@ export class ProposedTransformationExplorer {
403404
transformByQState.getChatControllers()?.transformationFinished.fire({
404405
message: `${CodeWhispererConstants.errorDownloadingDiffChatMessage} The download failed due to: ${downloadErrorMessage}`,
405406
tabID: ChatSessionManager.Instance.getSession().tabID,
407+
includeStartNewTransformationButton: 'true',
406408
})
407409
await setContext('gumby.reviewState', TransformByQReviewStatus.NotStarted)
408410
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
@@ -434,7 +436,8 @@ export class ProposedTransformationExplorer {
434436
diffModel.parseDiff(
435437
patchFiles[0],
436438
transformByQState.getProjectPath(),
437-
patchFilesDescriptions ? patchFilesDescriptions[0] : undefined
439+
patchFilesDescriptions ? patchFilesDescriptions[0] : undefined,
440+
patchFiles.length
438441
)
439442

440443
await setContext('gumby.reviewState', TransformByQReviewStatus.InReview)
@@ -450,6 +453,7 @@ export class ProposedTransformationExplorer {
450453
transformByQState.getChatControllers()?.transformationFinished.fire({
451454
message: CodeWhispererConstants.viewProposedChangesChatMessage,
452455
tabID: ChatSessionManager.Instance.getSession().tabID,
456+
includeStartNewTransformationButton: 'true',
453457
})
454458
await vscode.commands.executeCommand('aws.amazonq.transformationHub.summary.reveal')
455459
} catch (e: any) {
@@ -458,6 +462,7 @@ export class ProposedTransformationExplorer {
458462
transformByQState.getChatControllers()?.transformationFinished.fire({
459463
message: `${CodeWhispererConstants.errorDeserializingDiffChatMessage} ${deserializeErrorMessage}`,
460464
tabID: ChatSessionManager.Instance.getSession().tabID,
465+
includeStartNewTransformationButton: 'true',
461466
})
462467
void vscode.window.showErrorMessage(
463468
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
@@ -468,12 +473,27 @@ export class ProposedTransformationExplorer {
468473
vscode.commands.registerCommand('aws.amazonq.transformationHub.reviewChanges.acceptChanges', async () => {
469474
diffModel.saveChanges()
470475
telemetry.ui_click.emit({ elementId: 'transformationHub_acceptChanges' })
471-
void vscode.window.showInformationMessage(CodeWhispererConstants.changesAppliedNotification)
476+
void vscode.window.showInformationMessage(
477+
CodeWhispererConstants.changesAppliedNotification(diffModel.currentPatchIndex, patchFiles.length)
478+
)
472479
//We do this to ensure that the changesAppliedChatMessage is only sent to user when they accept the first diff.patch
473-
if (diffModel.currentPatchIndex === 0) {
480+
if (diffModel.currentPatchIndex === patchFiles.length - 1) {
481+
transformByQState.getChatControllers()?.transformationFinished.fire({
482+
message: CodeWhispererConstants.changesAppliedChatMessage(
483+
diffModel.currentPatchIndex,
484+
patchFiles.length
485+
),
486+
tabID: ChatSessionManager.Instance.getSession().tabID,
487+
includeStartNewTransformationButton: 'true',
488+
})
489+
} else {
474490
transformByQState.getChatControllers()?.transformationFinished.fire({
475-
message: CodeWhispererConstants.changesAppliedChatMessage,
491+
message: CodeWhispererConstants.changesAppliedChatMessage(
492+
diffModel.currentPatchIndex,
493+
patchFiles.length
494+
),
476495
tabID: ChatSessionManager.Instance.getSession().tabID,
496+
includeStartNewTransformationButton: 'false',
477497
})
478498
}
479499

@@ -484,7 +504,12 @@ export class ProposedTransformationExplorer {
484504
const nextPatchFileDescription = patchFilesDescriptions
485505
? patchFilesDescriptions[diffModel.currentPatchIndex]
486506
: undefined
487-
diffModel.parseDiff(nextPatchFile, transformByQState.getProjectPath(), nextPatchFileDescription)
507+
diffModel.parseDiff(
508+
nextPatchFile,
509+
transformByQState.getProjectPath(),
510+
nextPatchFileDescription,
511+
patchFiles.length
512+
)
488513
transformDataProvider.refresh()
489514
} else {
490515
// All patches have been applied, reset the state

0 commit comments

Comments
 (0)