Skip to content

Commit 8ce0eee

Browse files
committed
Merge branch 'master' into refactor-sam-sync-deploy-build
2 parents 1e986ad + ac72bca commit 8ce0eee

File tree

31 files changed

+1123
-162
lines changed

31 files changed

+1123
-162
lines changed

package-lock.json

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Chat container exceeds width of container"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "file details and name unneccessary cropping"
4+
}

packages/amazonq/test/unit/amazonqFeatureDev/session/session.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe('session', () => {
109109
it('only insert non rejected files', async () => {
110110
const fsSpyWriteFile = sinon.spy(fs, 'writeFile')
111111
const session = await createCodeGenState()
112+
sinon.stub(session, 'sendLinesOfCodeAcceptedTelemetry').resolves()
112113
await sessionWriteFile(session, uri, encodedContent)
113114
await session.insertChanges()
114115

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"content": [
3+
{
4+
"name": "Added file",
5+
"fileName": "resources/files/addedFile.diff",
6+
"isSuccessful": true
7+
}
8+
]
9+
}

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

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
*/
55
import assert from 'assert'
66
import sinon from 'sinon'
7-
import os from 'os'
87
import { DiffModel, AddedChangeNode, ModifiedChangeNode } from 'aws-core-vscode/codewhisperer/node'
8+
import { DescriptionContent } from 'aws-core-vscode/codewhisperer'
99
import path from 'path'
1010
import { getTestResourceFilePath } from './amazonQGumbyUtil'
1111
import { fs } from 'aws-core-vscode/shared'
12+
import { createTestWorkspace } from 'aws-core-vscode/test'
1213

1314
describe('DiffModel', function () {
15+
let parsedTestDescriptions: DescriptionContent
16+
beforeEach(async () => {
17+
parsedTestDescriptions = JSON.parse(await fs.readFileText(getTestResourceFilePath('resources/files/diff.json')))
18+
})
19+
1420
afterEach(() => {
1521
sinon.restore()
1622
})
@@ -28,34 +34,76 @@ describe('DiffModel', function () {
2834

2935
return true
3036
})
37+
testDiffModel.parseDiff(
38+
getTestResourceFilePath('resources/files/addedFile.diff'),
39+
workspacePath,
40+
parsedTestDescriptions.content[0],
41+
1
42+
)
3143

32-
testDiffModel.parseDiff(getTestResourceFilePath('resources/files/addedFile.diff'), workspacePath)
33-
34-
assert.strictEqual(testDiffModel.changes.length, 1)
35-
const change = testDiffModel.changes[0]
44+
assert.strictEqual(
45+
testDiffModel.patchFileNodes[0].patchFilePath,
46+
getTestResourceFilePath('resources/files/addedFile.diff')
47+
)
48+
assert(testDiffModel.patchFileNodes[0].label.includes(parsedTestDescriptions.content[0].name))
49+
const change = testDiffModel.patchFileNodes[0].children[0]
3650

3751
assert.strictEqual(change instanceof AddedChangeNode, true)
3852
})
3953

4054
it('WHEN parsing a diff patch where a file was modified THEN returns an array representing the modified file', async function () {
4155
const testDiffModel = new DiffModel()
4256

43-
const workspacePath = os.tmpdir()
44-
45-
sinon.replace(fs, 'exists', async (path) => true)
57+
const fileAmount = 1
58+
const workspaceFolder = await createTestWorkspace(fileAmount, { fileContent: '' })
4659

4760
await fs.writeFile(
48-
path.join(workspacePath, 'README.md'),
61+
path.join(workspaceFolder.uri.fsPath, 'README.md'),
4962
'This guide walks you through using Gradle to build a simple Java project.'
5063
)
5164

52-
testDiffModel.parseDiff(getTestResourceFilePath('resources/files/modifiedFile.diff'), workspacePath)
65+
testDiffModel.parseDiff(
66+
getTestResourceFilePath('resources/files/modifiedFile.diff'),
67+
workspaceFolder.uri.fsPath,
68+
parsedTestDescriptions.content[0],
69+
1
70+
)
5371

54-
assert.strictEqual(testDiffModel.changes.length, 1)
55-
const change = testDiffModel.changes[0]
72+
assert.strictEqual(
73+
testDiffModel.patchFileNodes[0].patchFilePath,
74+
getTestResourceFilePath('resources/files/modifiedFile.diff')
75+
)
76+
assert(testDiffModel.patchFileNodes[0].label.includes(parsedTestDescriptions.content[0].name))
77+
const change = testDiffModel.patchFileNodes[0].children[0]
5678

5779
assert.strictEqual(change instanceof ModifiedChangeNode, true)
80+
})
81+
82+
it('WHEN parsing a diff patch where diff.json is not present and a file was modified THEN returns an array representing the modified file', async function () {
83+
const testDiffModel = new DiffModel()
5884

59-
await fs.delete(path.join(workspacePath, 'README.md'), { recursive: true })
85+
const fileAmount = 1
86+
const workspaceFolder = await createTestWorkspace(fileAmount, { fileContent: '' })
87+
88+
await fs.writeFile(
89+
path.join(workspaceFolder.uri.fsPath, 'README.md'),
90+
'This guide walks you through using Gradle to build a simple Java project.'
91+
)
92+
93+
testDiffModel.parseDiff(
94+
getTestResourceFilePath('resources/files/modifiedFile.diff'),
95+
workspaceFolder.uri.fsPath,
96+
undefined,
97+
1
98+
)
99+
100+
assert.strictEqual(
101+
testDiffModel.patchFileNodes[0].patchFilePath,
102+
getTestResourceFilePath('resources/files/modifiedFile.diff')
103+
)
104+
assert(testDiffModel.patchFileNodes[0].label.endsWith('modifiedFile.diff'))
105+
const change = testDiffModel.patchFileNodes[0].children[0]
106+
107+
assert.strictEqual(change instanceof ModifiedChangeNode, true)
60108
})
61109
})

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@
435435
"c8": "^9.0.0",
436436
"circular-dependency-plugin": "^5.2.2",
437437
"css-loader": "^6.10.0",
438-
"diff": "^5.1.0",
439438
"esbuild-loader": "2.20.0",
440439
"file-loader": "^6.2.0",
441440
"jsdom": "^23.0.1",
@@ -470,7 +469,7 @@
470469
"@aws-sdk/property-provider": "3.46.0",
471470
"@aws-sdk/smithy-client": "^3.46.0",
472471
"@aws-sdk/util-arn-parser": "^3.46.0",
473-
"@aws/mynah-ui": "^4.18.0",
472+
"@aws/mynah-ui": "^4.18.1",
474473
"@gerhobbelt/gitignore-parser": "^0.2.0-9",
475474
"@iarna/toml": "^2.2.5",
476475
"@smithy/middleware-retry": "^2.3.1",
@@ -488,6 +487,7 @@
488487
"bytes": "^3.1.2",
489488
"cross-fetch": "^4.0.0",
490489
"cross-spawn": "^7.0.3",
490+
"diff": "^5.1.0",
491491
"fast-json-patch": "^3.1.1",
492492
"glob": "^10.3.10",
493493
"got": "^11.8.5",

packages/core/src/amazonq/commons/diff.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as vscode from 'vscode'
77
import { featureDevScheme } from '../../amazonqFeatureDev/constants'
88
import { fs } from '../../shared'
9+
import { diffLines } from 'diff'
910

1011
export async function openDiff(leftPath: string, rightPath: string, tabId: string) {
1112
const { left, right } = await getFileDiffUris(leftPath, rightPath, tabId)
@@ -29,6 +30,34 @@ export async function getFileDiffUris(leftPath: string, rightPath: string, tabId
2930
return { left, right }
3031
}
3132

33+
export async function computeDiff(leftPath: string, rightPath: string, tabId: string) {
34+
const { left, right } = await getFileDiffUris(leftPath, rightPath, tabId)
35+
const leftFile = await vscode.workspace.openTextDocument(left)
36+
const rightFile = await vscode.workspace.openTextDocument(right)
37+
38+
const changes = diffLines(leftFile.getText(), rightFile.getText(), {
39+
ignoreWhitespace: true,
40+
})
41+
42+
let charsAdded = 0
43+
let charsRemoved = 0
44+
let linesAdded = 0
45+
let linesRemoved = 0
46+
changes.forEach((change) => {
47+
const lines = change.value.split('\n')
48+
const charCount = lines.reduce((sum, line) => sum + line.length, 0)
49+
const lineCount = change.count ?? lines.length - 1 // ignoring end-of-file empty line
50+
if (change.added) {
51+
charsAdded += charCount
52+
linesAdded += lineCount
53+
} else if (change.removed) {
54+
charsRemoved += charCount
55+
linesRemoved += lineCount
56+
}
57+
})
58+
return { changes, charsAdded, linesAdded, charsRemoved, linesRemoved }
59+
}
60+
3261
export function createAmazonQUri(path: string, tabId: string) {
3362
// TODO change the featureDevScheme to a more general amazon q scheme
3463
return vscode.Uri.from({ scheme: featureDevScheme, path, query: `tabID=${tabId}` })

packages/core/src/amazonq/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ export { amazonQHelpUrl } from '../shared/constants'
2727
export { listCodeWhispererCommandsWalkthrough } from '../codewhisperer/ui/statusBarMenu'
2828
export { focusAmazonQPanel, focusAmazonQPanelKeybinding } from '../codewhispererChat/commands/registerCommands'
2929
export { TryChatCodeLensProvider, tryChatCodeLensCommand } from '../codewhispererChat/editor/codelens'
30-
export { createAmazonQUri, openDiff, openDeletedDiff, getOriginalFileUri, getFileDiffUris } from './commons/diff'
30+
export {
31+
createAmazonQUri,
32+
openDiff,
33+
openDeletedDiff,
34+
getOriginalFileUri,
35+
getFileDiffUris,
36+
computeDiff,
37+
} from './commons/diff'
3138
export { CodeReference } from '../codewhispererChat/view/connector/connector'
3239
export { AuthMessageDataMap, AuthFollowUpType } from './auth/model'
3340
export { extractAuthFollowUp } from './util/authUtils'

packages/core/src/amazonqFeatureDev/client/codewhispererruntime-2022-11-11.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,44 @@
873873
"max": 100,
874874
"min": 0
875875
},
876+
"FeatureDevCodeAcceptanceEvent": {
877+
"type": "structure",
878+
"required": ["conversationId", "linesOfCodeAccepted", "charactersOfCodeAccepted"],
879+
"members": {
880+
"conversationId": { "shape": "ConversationId" },
881+
"linesOfCodeAccepted": { "shape": "FeatureDevCodeAcceptanceEventLinesOfCodeAcceptedInteger" },
882+
"charactersOfCodeAccepted": { "shape": "FeatureDevCodeAcceptanceEventCharactersOfCodeAcceptedInteger" },
883+
"programmingLanguage": { "shape": "ProgrammingLanguage" }
884+
}
885+
},
886+
"FeatureDevCodeAcceptanceEventCharactersOfCodeAcceptedInteger": {
887+
"type": "integer",
888+
"min": 0
889+
},
890+
"FeatureDevCodeAcceptanceEventLinesOfCodeAcceptedInteger": {
891+
"type": "integer",
892+
"min": 0
893+
},
894+
"FeatureDevCodeGenerationEvent": {
895+
"type": "structure",
896+
"required": ["conversationId", "linesOfCodeGenerated", "charactersOfCodeGenerated"],
897+
"members": {
898+
"conversationId": { "shape": "ConversationId" },
899+
"linesOfCodeGenerated": { "shape": "FeatureDevCodeGenerationEventLinesOfCodeGeneratedInteger" },
900+
"charactersOfCodeGenerated": {
901+
"shape": "FeatureDevCodeGenerationEventCharactersOfCodeGeneratedInteger"
902+
},
903+
"programmingLanguage": { "shape": "ProgrammingLanguage" }
904+
}
905+
},
906+
"FeatureDevCodeGenerationEventCharactersOfCodeGeneratedInteger": {
907+
"type": "integer",
908+
"min": 0
909+
},
910+
"FeatureDevCodeGenerationEventLinesOfCodeGeneratedInteger": {
911+
"type": "integer",
912+
"min": 0
913+
},
876914
"FeatureDevEvent": {
877915
"type": "structure",
878916
"required": ["conversationId"],
@@ -1741,6 +1779,8 @@
17411779
"chatUserModificationEvent": { "shape": "ChatUserModificationEvent" },
17421780
"terminalUserInteractionEvent": { "shape": "TerminalUserInteractionEvent" },
17431781
"featureDevEvent": { "shape": "FeatureDevEvent" },
1782+
"featureDevCodeGenerationEvent": { "shape": "FeatureDevCodeGenerationEvent" },
1783+
"featureDevCodeAcceptanceEvent": { "shape": "FeatureDevCodeAcceptanceEvent" },
17441784
"inlineChatEvent": { "shape": "InlineChatEvent" }
17451785
},
17461786
"union": true

0 commit comments

Comments
 (0)