Skip to content

Commit

Permalink
added numbering to make it obvious to user which patch file they're v…
Browse files Browse the repository at this point in the history
…iewing and updated chat messaging with start transformation prompt
  • Loading branch information
ntarakad-aws committed Oct 29, 2024
1 parent 02a418c commit b714214
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ describe('DiffModel', function () {
testDiffModel.parseDiff(
getTestResourceFilePath('resources/files/addedFile.diff'),
workspacePath,
parsedTestDescriptions[0]
parsedTestDescriptions[0],
1
)

assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
assert.strictEqual(testDiffModel.patchFileNodes[0].patchFilePath, parsedTestDescriptions[0].name)
assert(testDiffModel.patchFileNodes[0].label.endsWith(parsedTestDescriptions[0].name))
const change = testDiffModel.patchFileNodes[0].children[0]

assert.strictEqual(change instanceof AddedChangeNode, true)
Expand All @@ -66,12 +68,14 @@ describe('DiffModel', function () {
testDiffModel.parseDiff(
getTestResourceFilePath('resources/files/modifiedFile.diff'),
workspacePath,
parsedTestDescriptions[0]
parsedTestDescriptions[0],
1
)

assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
assert.strictEqual(testDiffModel.patchFileNodes[0].patchFilePath, parsedTestDescriptions[0].name)
assert(testDiffModel.patchFileNodes[0].label.endsWith(parsedTestDescriptions[0].name))
const change = testDiffModel.patchFileNodes[0].children[0]

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

testDiffModel.parseDiff(getTestResourceFilePath('resources/files/modifiedFile.diff'), workspacePath, undefined)
testDiffModel.parseDiff(
getTestResourceFilePath('resources/files/modifiedFile.diff'),
workspacePath,
undefined,
1
)

assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
assert.strictEqual(
testDiffModel.patchFileNodes[0].patchFilePath,
getTestResourceFilePath('resources/files/modifiedFile.diff')
)
assert(testDiffModel.patchFileNodes[0].label.endsWith('modifiedFile.diff'))
const change = testDiffModel.patchFileNodes[0].children[0]

assert.strictEqual(change instanceof ModifiedChangeNode, true)
Expand Down
14 changes: 11 additions & 3 deletions packages/core/src/amazonqGumby/chat/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,15 @@ export class GumbyController {
await this.prepareProjectForSubmission(message)
}

private transformationFinished(data: { message: string | undefined; tabID: string }) {
private transformationFinished(data: {
message: string | undefined
tabID: string
includeStartNewTransformationButton: string
}) {
this.resetTransformationChatFlow()
// at this point job is either completed, partially_completed, cancelled, or failed
if (data.message) {
this.messenger.sendJobFinishedMessage(data.tabID, data.message)
this.messenger.sendJobFinishedMessage(data.tabID, data.message, data.includeStartNewTransformationButton)
}
}

Expand Down Expand Up @@ -543,7 +547,11 @@ export class GumbyController {
try {
await finishHumanInTheLoop()
} catch (err: any) {
this.transformationFinished({ tabID: message.tabID, message: (err as Error).message })
this.transformationFinished({
tabID: message.tabID,
message: (err as Error).message,
includeStartNewTransformationButton: 'true',
})
}

this.messenger.sendStaticTextResponse('end-HIL-early', message.tabID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,11 @@ export class Messenger {
options: [
{
value: JDKVersion.JDK8,
label: JDKVersion.JDK8,
label: JDKVersion.JDK8.toString(),
},
{
value: JDKVersion.JDK11,
label: JDKVersion.JDK11,
},
{
value: JDKVersion.JDK17,
label: JDKVersion.JDK17,
label: JDKVersion.JDK11.toString(),
},
{
value: JDKVersion.UNSUPPORTED,
Expand Down Expand Up @@ -413,13 +409,19 @@ export class Messenger {
this.dispatcher.sendCommandMessage(new SendCommandMessage(message.command, message.tabID, message.eventId))
}

public sendJobFinishedMessage(tabID: string, message: string) {
public sendJobFinishedMessage(
tabID: string,
message: string,
includeStartNewTransformationButton: string = 'true'
) {
const buttons: ChatItemButton[] = []
buttons.push({
keepCardAfterClick: false,
text: CodeWhispererConstants.startTransformationButtonText,
id: ButtonActions.CONFIRM_START_TRANSFORMATION_FLOW,
})
if (includeStartNewTransformationButton === 'true') {
buttons.push({
keepCardAfterClick: false,
text: CodeWhispererConstants.startTransformationButtonText,
id: ButtonActions.CONFIRM_START_TRANSFORMATION_FLOW,
})
}

this.dispatcher.sendChatMessage(
new ChatMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export default class MessengerUtils {
javaHomePrompt += ` ${CodeWhispererConstants.macJava8HomeHelpChatMessage}`
} else if (jdkVersion === JDKVersion.JDK11) {
javaHomePrompt += ` ${CodeWhispererConstants.macJava11HomeHelpChatMessage}`
} else if (jdkVersion === JDKVersion.JDK17) {
javaHomePrompt += ` ${CodeWhispererConstants.macJava17HomeHelpChatMessage}`
}
} else {
javaHomePrompt += ` ${CodeWhispererConstants.linuxJavaHomeHelpChatMessage}`
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/codewhisperer/commands/startTransformByQ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ async function validateJavaHome(): Promise<boolean> {
javaVersionUsedByMaven = JDKVersion.JDK8
} else if (javaVersionUsedByMaven === '11.') {
javaVersionUsedByMaven = JDKVersion.JDK11
} else if (javaVersionUsedByMaven === '17.') {
javaVersionUsedByMaven = JDKVersion.JDK17
}
}
if (javaVersionUsedByMaven !== transformByQState.getSourceJDKVersion()) {
Expand Down Expand Up @@ -713,9 +711,11 @@ export async function postTransformationJob() {
chatMessage = CodeWhispererConstants.jobPartiallyCompletedChatMessage
}

transformByQState
.getChatControllers()
?.transformationFinished.fire({ message: chatMessage, tabID: ChatSessionManager.Instance.getSession().tabID })
transformByQState.getChatControllers()?.transformationFinished.fire({
message: chatMessage,
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: 'true',
})
const durationInMs = calculateTotalLatency(CodeTransformTelemetryState.instance.getStartTime())
const resultStatusMessage = transformByQState.getStatus()

Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/codewhisperer/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,11 @@ export const viewProposedChangesChatMessage =
export const viewProposedChangesNotification =
'Download complete. You can view a summary of the transformation and accept or reject the proposed changes in the Transformation Hub.'

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

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

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

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

export const macJava17HomeHelpChatMessage =
'To find the JDK path, run the following command in a new terminal: `/usr/libexec/java_home -v 17`'

export const linuxJavaHomeHelpChatMessage =
'To find the JDK path, run the following command in a new terminal: `update-java-alternatives --list`'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export async function zipCode(
transformByQState.getChatControllers()?.transformationFinished.fire({
message: CodeWhispererConstants.projectSizeTooLargeChatMessage,
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: 'true',
})
throw new ZipExceedsSizeLimitError()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class AddedChangeNode extends ProposedChangeNode {
}

export class PatchFileNode {
readonly label: string
label: string
readonly patchFilePath: string
children: ProposedChangeNode[] = []

Expand Down Expand Up @@ -157,7 +157,8 @@ export class DiffModel {
public parseDiff(
pathToDiff: string,
pathToWorkspace: string,
diffDescription: PatchInfo | undefined
diffDescription: PatchInfo | undefined,
totalDiffPatches: number
): PatchFileNode {
this.patchFileNodes = []
const diffContents = fs.readFileSync(pathToDiff, 'utf8')
Expand Down Expand Up @@ -195,6 +196,7 @@ export class DiffModel {
},
})
const patchFileNode = new PatchFileNode(diffDescription ? diffDescription.name : pathToDiff)
patchFileNode.label = `Patch ${this.currentPatchIndex + 1} of ${totalDiffPatches}: ${patchFileNode.label}`
patchFileNode.children = changedFiles.flatMap((file) => {
/* ex. file.oldFileName = 'a/src/java/com/project/component/MyFile.java'
* ex. file.newFileName = 'b/src/java/com/project/component/MyFile.java'
Expand Down Expand Up @@ -259,7 +261,7 @@ export class TransformationResultsProvider implements vscode.TreeDataProvider<Pr
if (element instanceof PatchFileNode) {
return {
label: element.label,
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
}
} else {
return {
Expand Down Expand Up @@ -308,7 +310,6 @@ export class ProposedTransformationExplorer {
treeDataProvider: transformDataProvider,
})

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

Expand Down Expand Up @@ -403,6 +404,7 @@ export class ProposedTransformationExplorer {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: `${CodeWhispererConstants.errorDownloadingDiffChatMessage} The download failed due to: ${downloadErrorMessage}`,
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: 'true',
})
await setContext('gumby.reviewState', TransformByQReviewStatus.NotStarted)
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
Expand Down Expand Up @@ -434,7 +436,8 @@ export class ProposedTransformationExplorer {
diffModel.parseDiff(
patchFiles[0],
transformByQState.getProjectPath(),
patchFilesDescriptions ? patchFilesDescriptions[0] : undefined
patchFilesDescriptions ? patchFilesDescriptions[0] : undefined,
patchFiles.length
)

await setContext('gumby.reviewState', TransformByQReviewStatus.InReview)
Expand All @@ -450,6 +453,7 @@ export class ProposedTransformationExplorer {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: CodeWhispererConstants.viewProposedChangesChatMessage,
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: 'true',
})
await vscode.commands.executeCommand('aws.amazonq.transformationHub.summary.reveal')
} catch (e: any) {
Expand All @@ -458,6 +462,7 @@ export class ProposedTransformationExplorer {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: `${CodeWhispererConstants.errorDeserializingDiffChatMessage} ${deserializeErrorMessage}`,
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: 'true',
})
void vscode.window.showErrorMessage(
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
Expand All @@ -468,12 +473,27 @@ export class ProposedTransformationExplorer {
vscode.commands.registerCommand('aws.amazonq.transformationHub.reviewChanges.acceptChanges', async () => {
diffModel.saveChanges()
telemetry.ui_click.emit({ elementId: 'transformationHub_acceptChanges' })
void vscode.window.showInformationMessage(CodeWhispererConstants.changesAppliedNotification)
void vscode.window.showInformationMessage(
CodeWhispererConstants.changesAppliedNotification(diffModel.currentPatchIndex, patchFiles.length)
)
//We do this to ensure that the changesAppliedChatMessage is only sent to user when they accept the first diff.patch
if (diffModel.currentPatchIndex === 0) {
if (diffModel.currentPatchIndex === patchFiles.length - 1) {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: CodeWhispererConstants.changesAppliedChatMessage(
diffModel.currentPatchIndex,
patchFiles.length
),
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: 'true',
})
} else {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: CodeWhispererConstants.changesAppliedChatMessage,
message: CodeWhispererConstants.changesAppliedChatMessage(
diffModel.currentPatchIndex,
patchFiles.length
),
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: 'false',
})
}

Expand All @@ -484,7 +504,12 @@ export class ProposedTransformationExplorer {
const nextPatchFileDescription = patchFilesDescriptions
? patchFilesDescriptions[diffModel.currentPatchIndex]
: undefined
diffModel.parseDiff(nextPatchFile, transformByQState.getProjectPath(), nextPatchFileDescription)
diffModel.parseDiff(
nextPatchFile,
transformByQState.getProjectPath(),
nextPatchFileDescription,
patchFiles.length
)
transformDataProvider.refresh()
} else {
// All patches have been applied, reset the state
Expand Down

0 comments on commit b714214

Please sign in to comment.