Skip to content

Commit e880968

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 9321b25 commit e880968

File tree

8 files changed

+83
-40
lines changed

8 files changed

+83
-40
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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ export default class MessengerUtils {
4646
if (jdkVersion === JDKVersion.JDK8) {
4747
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(1.8)}`
4848
} else if (jdkVersion === JDKVersion.JDK11) {
49-
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(11)}`
50-
} else if (jdkVersion === JDKVersion.JDK17) {
51-
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(17)}`
49+
javaHomePrompt += ` ${CodeWhispererConstants.macJava11HomeHelpChatMessage}`
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
@@ -626,9 +626,11 @@ export const viewProposedChangesChatMessage =
626626
export const viewProposedChangesNotification =
627627
'Download complete. You can view a summary of the transformation and accept or reject the proposed changes in the Transformation Hub.'
628628

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

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

633635
export const noOpenProjectsFoundChatMessage = `I couldn\'t find a project that I can upgrade. Currently, I support Java 8, Java 11, and Java 17 projects built on Maven. Make sure your project is open in the IDE. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
634636

@@ -660,9 +662,6 @@ export const windowsJavaHomeHelpChatMessage =
660662
export const macJavaVersionHomeHelpChatMessage = (version: number) =>
661663
`To find the JDK path, run the following command in a new terminal: \`/usr/libexec/java_home -v ${version}\``
662664

663-
export const macJava17HomeHelpChatMessage =
664-
'To find the JDK path, run the following command in a new terminal: `/usr/libexec/java_home -v 17`'
665-
666665
export const linuxJavaHomeHelpChatMessage =
667666
'To find the JDK path, run the following command in a new terminal: `update-java-alternatives --list`'
668667

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ export async function zipCode(
408408
transformByQState.getChatControllers()?.transformationFinished.fire({
409409
message: CodeWhispererConstants.projectSizeTooLargeChatMessage,
410410
tabID: ChatSessionManager.Instance.getSession().tabID,
411+
includeStartNewTransformationButton: 'true',
411412
})
412413
throw new ZipExceedsSizeLimitError()
413414
}

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

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

110110
export class PatchFileNode {
111-
readonly label: string
111+
label: string
112112
readonly patchFilePath: string
113113
children: ProposedChangeNode[] = []
114114

@@ -158,7 +158,8 @@ export class DiffModel {
158158
public parseDiff(
159159
pathToDiff: string,
160160
pathToWorkspace: string,
161-
diffDescription: PatchInfo | undefined
161+
diffDescription: PatchInfo | undefined,
162+
totalDiffPatches: number
162163
): PatchFileNode {
163164
this.patchFileNodes = []
164165
const diffContents = fs.readFileSync(pathToDiff, 'utf8')
@@ -196,6 +197,7 @@ export class DiffModel {
196197
},
197198
})
198199
const patchFileNode = new PatchFileNode(diffDescription ? diffDescription.name : pathToDiff)
200+
patchFileNode.label = `Patch ${this.currentPatchIndex + 1} of ${totalDiffPatches}: ${patchFileNode.label}`
199201
patchFileNode.children = changedFiles.flatMap((file) => {
200202
/* ex. file.oldFileName = 'a/src/java/com/project/component/MyFile.java'
201203
* ex. file.newFileName = 'b/src/java/com/project/component/MyFile.java'
@@ -260,7 +262,7 @@ export class TransformationResultsProvider implements vscode.TreeDataProvider<Pr
260262
if (element instanceof PatchFileNode) {
261263
return {
262264
label: element.label,
263-
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
265+
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
264266
}
265267
} else {
266268
return {
@@ -309,7 +311,6 @@ export class ProposedTransformationExplorer {
309311
treeDataProvider: transformDataProvider,
310312
})
311313

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

@@ -404,6 +405,7 @@ export class ProposedTransformationExplorer {
404405
transformByQState.getChatControllers()?.transformationFinished.fire({
405406
message: `${CodeWhispererConstants.errorDownloadingDiffChatMessage} The download failed due to: ${downloadErrorMessage}`,
406407
tabID: ChatSessionManager.Instance.getSession().tabID,
408+
includeStartNewTransformationButton: 'true',
407409
})
408410
await setContext('gumby.reviewState', TransformByQReviewStatus.NotStarted)
409411
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
@@ -435,7 +437,8 @@ export class ProposedTransformationExplorer {
435437
diffModel.parseDiff(
436438
patchFiles[0],
437439
transformByQState.getProjectPath(),
438-
patchFilesDescriptions ? patchFilesDescriptions[0] : undefined
440+
patchFilesDescriptions ? patchFilesDescriptions[0] : undefined,
441+
patchFiles.length
439442
)
440443

441444
await setContext('gumby.reviewState', TransformByQReviewStatus.InReview)
@@ -451,6 +454,7 @@ export class ProposedTransformationExplorer {
451454
transformByQState.getChatControllers()?.transformationFinished.fire({
452455
message: CodeWhispererConstants.viewProposedChangesChatMessage,
453456
tabID: ChatSessionManager.Instance.getSession().tabID,
457+
includeStartNewTransformationButton: 'true',
454458
})
455459
await vscode.commands.executeCommand('aws.amazonq.transformationHub.summary.reveal')
456460
} catch (e: any) {
@@ -459,6 +463,7 @@ export class ProposedTransformationExplorer {
459463
transformByQState.getChatControllers()?.transformationFinished.fire({
460464
message: `${CodeWhispererConstants.errorDeserializingDiffChatMessage} ${deserializeErrorMessage}`,
461465
tabID: ChatSessionManager.Instance.getSession().tabID,
466+
includeStartNewTransformationButton: 'true',
462467
})
463468
void vscode.window.showErrorMessage(
464469
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
@@ -496,12 +501,27 @@ export class ProposedTransformationExplorer {
496501
vscode.commands.registerCommand('aws.amazonq.transformationHub.reviewChanges.acceptChanges', async () => {
497502
diffModel.saveChanges()
498503
telemetry.ui_click.emit({ elementId: 'transformationHub_acceptChanges' })
499-
void vscode.window.showInformationMessage(CodeWhispererConstants.changesAppliedNotification)
504+
void vscode.window.showInformationMessage(
505+
CodeWhispererConstants.changesAppliedNotification(diffModel.currentPatchIndex, patchFiles.length)
506+
)
500507
//We do this to ensure that the changesAppliedChatMessage is only sent to user when they accept the first diff.patch
501-
if (diffModel.currentPatchIndex === 0) {
508+
if (diffModel.currentPatchIndex === patchFiles.length - 1) {
509+
transformByQState.getChatControllers()?.transformationFinished.fire({
510+
message: CodeWhispererConstants.changesAppliedChatMessage(
511+
diffModel.currentPatchIndex,
512+
patchFiles.length
513+
),
514+
tabID: ChatSessionManager.Instance.getSession().tabID,
515+
includeStartNewTransformationButton: 'true',
516+
})
517+
} else {
502518
transformByQState.getChatControllers()?.transformationFinished.fire({
503-
message: CodeWhispererConstants.changesAppliedChatMessage,
519+
message: CodeWhispererConstants.changesAppliedChatMessage(
520+
diffModel.currentPatchIndex,
521+
patchFiles.length
522+
),
504523
tabID: ChatSessionManager.Instance.getSession().tabID,
524+
includeStartNewTransformationButton: 'false',
505525
})
506526
}
507527

@@ -512,7 +532,12 @@ export class ProposedTransformationExplorer {
512532
const nextPatchFileDescription = patchFilesDescriptions
513533
? patchFilesDescriptions[diffModel.currentPatchIndex]
514534
: undefined
515-
diffModel.parseDiff(nextPatchFile, transformByQState.getProjectPath(), nextPatchFileDescription)
535+
diffModel.parseDiff(
536+
nextPatchFile,
537+
transformByQState.getProjectPath(),
538+
nextPatchFileDescription,
539+
patchFiles.length
540+
)
516541
transformDataProvider.refresh()
517542
} else {
518543
// All patches have been applied, reset the state

0 commit comments

Comments
 (0)