Skip to content

Commit e564ef6

Browse files
LiGaCuJiatong Li
and
Jiatong Li
authored
feat(codewhisperer): add fileUri to FileContext (#7294)
## Problem In order to coordinate the new aws/language-servers#1348 change, GenerateCompletions requests would start expecting the `fileUri` field to be set. ## Solution Add `fileUri` to FileContext --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Jiatong Li <[email protected]>
1 parent ea593e2 commit e564ef6

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

packages/amazonq/test/unit/codewhisperer/util/editorContext.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe('editorContext', function () {
5656
const editor = createMockTextEditor('import math\ndef two_sum(nums, target):\n', 'test.py', 'python', 1, 17)
5757
const actual = EditorContext.extractContextForCodeWhisperer(editor)
5858
const expected: codewhispererClient.FileContext = {
59+
fileUri: 'file:///test.py',
5960
filename: 'test.py',
6061
programmingLanguage: {
6162
languageName: 'python',
@@ -76,6 +77,7 @@ describe('editorContext', function () {
7677
)
7778
const actual = EditorContext.extractContextForCodeWhisperer(editor)
7879
const expected: codewhispererClient.FileContext = {
80+
fileUri: 'file:///test.py',
7981
filename: 'test.py',
8082
programmingLanguage: {
8183
languageName: 'python',
@@ -112,6 +114,7 @@ describe('editorContext', function () {
112114

113115
const actual = EditorContext.extractContextForCodeWhisperer(editor)
114116
const expected: codewhispererClient.FileContext = {
117+
fileUri: editor.document.uri.toString(),
115118
filename: 'Untitled-1.py',
116119
programmingLanguage: {
117120
languageName: 'python',

packages/core/src/codewhisperer/client/service-2.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,20 @@
612612
"filename": {
613613
"shape": "FileContextFilenameString"
614614
},
615+
"fileUri": {
616+
"shape": "FileContextFileUriString"
617+
},
615618
"programmingLanguage": {
616619
"shape": "ProgrammingLanguage"
617620
}
618621
}
619622
},
623+
"FileContextFileUriString": {
624+
"type": "string",
625+
"max": 1024,
626+
"min": 1,
627+
"sensitive": true
628+
},
620629
"FileContextFilenameString": {
621630
"type": "string",
622631
"max": 1024,

packages/core/src/codewhisperer/client/user-service-2.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,9 +1852,16 @@
18521852
"leftFileContent": { "shape": "FileContextLeftFileContentString" },
18531853
"rightFileContent": { "shape": "FileContextRightFileContentString" },
18541854
"filename": { "shape": "FileContextFilenameString" },
1855+
"fileUri": { "shape": "FileContextFileUriString" },
18551856
"programmingLanguage": { "shape": "ProgrammingLanguage" }
18561857
}
18571858
},
1859+
"FileContextFileUriString": {
1860+
"type": "string",
1861+
"max": 1024,
1862+
"min": 1,
1863+
"sensitive": true
1864+
},
18581865
"FileContextFilenameString": {
18591866
"type": "string",
18601867
"max": 1024,

packages/core/src/codewhisperer/util/editorContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export function extractContextForCodeWhisperer(editor: vscode.TextEditor): codew
167167
}
168168

169169
return {
170+
fileUri: editor.document.uri.toString().substring(0, CodeWhispererConstants.filenameCharsLimit),
170171
filename: getFileRelativePath(editor),
171172
programmingLanguage: {
172173
languageName: languageName,

0 commit comments

Comments
 (0)