Skip to content

Commit 9eee782

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 a4bc4fc commit 9eee782

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
@@ -576,11 +576,15 @@ export class GumbyController {
576576
)
577577
}
578578

579-
private transformationFinished(data: { message: string | undefined; tabID: string }) {
579+
private transformationFinished(data: {
580+
message: string | undefined
581+
tabID: string
582+
includeStartNewTransformationButton: string
583+
}) {
580584
this.resetTransformationChatFlow()
581585
// at this point job is either completed, partially_completed, cancelled, or failed
582586
if (data.message) {
583-
this.messenger.sendJobFinishedMessage(data.tabID, data.message)
587+
this.messenger.sendJobFinishedMessage(data.tabID, data.message, data.includeStartNewTransformationButton)
584588
}
585589
}
586590

@@ -678,7 +682,11 @@ export class GumbyController {
678682
try {
679683
await finishHumanInTheLoop()
680684
} catch (err: any) {
681-
this.transformationFinished({ tabID: message.tabID, message: (err as Error).message })
685+
this.transformationFinished({
686+
tabID: message.tabID,
687+
message: (err as Error).message,
688+
includeStartNewTransformationButton: 'true',
689+
})
682690
}
683691

684692
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
@@ -185,15 +185,11 @@ export class Messenger {
185185
options: [
186186
{
187187
value: JDKVersion.JDK8,
188-
label: JDKVersion.JDK8,
188+
label: JDKVersion.JDK8.toString(),
189189
},
190190
{
191191
value: JDKVersion.JDK11,
192-
label: JDKVersion.JDK11,
193-
},
194-
{
195-
value: JDKVersion.JDK17,
196-
label: JDKVersion.JDK17,
192+
label: JDKVersion.JDK11.toString(),
197193
},
198194
{
199195
value: JDKVersion.UNSUPPORTED,
@@ -492,13 +488,19 @@ export class Messenger {
492488
this.dispatcher.sendCommandMessage(new SendCommandMessage(message.command, message.tabID, message.eventId))
493489
}
494490

495-
public sendJobFinishedMessage(tabID: string, message: string) {
491+
public sendJobFinishedMessage(
492+
tabID: string,
493+
message: string,
494+
includeStartNewTransformationButton: string = 'true'
495+
) {
496496
const buttons: ChatItemButton[] = []
497-
buttons.push({
498-
keepCardAfterClick: false,
499-
text: CodeWhispererConstants.startTransformationButtonText,
500-
id: ButtonActions.CONFIRM_START_TRANSFORMATION_FLOW,
501-
})
497+
if (includeStartNewTransformationButton === 'true') {
498+
buttons.push({
499+
keepCardAfterClick: false,
500+
text: CodeWhispererConstants.startTransformationButtonText,
501+
id: ButtonActions.CONFIRM_START_TRANSFORMATION_FLOW,
502+
})
503+
}
502504

503505
this.dispatcher.sendChatMessage(
504506
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
@@ -47,8 +47,6 @@ export default class MessengerUtils {
4747
javaHomePrompt += ` ${CodeWhispererConstants.macJava8HomeHelpChatMessage}`
4848
} else if (jdkVersion === JDKVersion.JDK11) {
4949
javaHomePrompt += ` ${CodeWhispererConstants.macJava11HomeHelpChatMessage}`
50-
} else if (jdkVersion === JDKVersion.JDK17) {
51-
javaHomePrompt += ` ${CodeWhispererConstants.macJava17HomeHelpChatMessage}`
5250
}
5351
} else {
5452
javaHomePrompt += ` ${CodeWhispererConstants.linuxJavaHomeHelpChatMessage}`

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ async function validateJavaHome(): Promise<boolean> {
174174
javaVersionUsedByMaven = JDKVersion.JDK8
175175
} else if (javaVersionUsedByMaven === '11.') {
176176
javaVersionUsedByMaven = JDKVersion.JDK11
177-
} else if (javaVersionUsedByMaven === '17.') {
178-
javaVersionUsedByMaven = JDKVersion.JDK17
179177
}
180178
}
181179
if (javaVersionUsedByMaven !== transformByQState.getSourceJDKVersion()) {
@@ -782,9 +780,11 @@ export async function postTransformationJob() {
782780
chatMessage = CodeWhispererConstants.jobPartiallyCompletedChatMessage
783781
}
784782

785-
transformByQState
786-
.getChatControllers()
787-
?.transformationFinished.fire({ message: chatMessage, tabID: ChatSessionManager.Instance.getSession().tabID })
783+
transformByQState.getChatControllers()?.transformationFinished.fire({
784+
message: chatMessage,
785+
tabID: ChatSessionManager.Instance.getSession().tabID,
786+
includeStartNewTransformationButton: 'true',
787+
})
788788
const durationInMs = calculateTotalLatency(CodeTransformTelemetryState.instance.getStartTime())
789789
const resultStatusMessage = transformByQState.getStatus()
790790

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

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

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

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

626628
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}).`
627629

@@ -656,9 +658,6 @@ export const macJava8HomeHelpChatMessage =
656658
export const macJava11HomeHelpChatMessage =
657659
'To find the JDK path, run the following command in a new terminal: `/usr/libexec/java_home -v 11`'
658660

659-
export const macJava17HomeHelpChatMessage =
660-
'To find the JDK path, run the following command in a new terminal: `/usr/libexec/java_home -v 17`'
661-
662661
export const linuxJavaHomeHelpChatMessage =
663662
'To find the JDK path, run the following command in a new terminal: `update-java-alternatives --list`'
664663

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ export async function zipCode(
404404
transformByQState.getChatControllers()?.transformationFinished.fire({
405405
message: CodeWhispererConstants.projectSizeTooLargeChatMessage,
406406
tabID: ChatSessionManager.Instance.getSession().tabID,
407+
includeStartNewTransformationButton: 'true',
407408
})
408409
throw new ZipExceedsSizeLimitError()
409410
}

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)