Skip to content

Commit 7767e06

Browse files
author
Jiatong Li
committed
feat(amazonq): add fileUri to FileContext
1 parent 3c07c5b commit 7767e06

File tree

9 files changed

+25
-4
lines changed

9 files changed

+25
-4
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/editor/CodeWhispererEditorUtil.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ object CodeWhispererEditorUtil {
3232
val fileName = getFileName(psiFile)
3333
val programmingLanguage = psiFile.programmingLanguage()
3434
val fileRelativePath = getRelativePathToContentRoot(editor)
35-
return FileContextInfo(caretContext, fileName, programmingLanguage, fileRelativePath)
35+
val fileUri = getFileUri(psiFile)
36+
return FileContextInfo(caretContext, fileName, programmingLanguage, fileRelativePath, fileUri)
3637
}
3738

3839
fun extractCaretContext(editor: Editor): CaretContext {
@@ -73,6 +74,11 @@ object CodeWhispererEditorUtil {
7374
private fun getFileName(psiFile: PsiFile): String =
7475
psiFile.name.substring(0, psiFile.name.length.coerceAtMost(CodeWhispererConstants.FILENAME_CHARS_LIMIT))
7576

77+
private fun getFileUri(psiFile: PsiFile): String? =
78+
psiFile.virtualFile?.takeIf { it.isValid }?.let { vFile ->
79+
vFile.url.substring(0, vFile.url.length.coerceAtMost(CodeWhispererConstants.FILENAME_CHARS_LIMIT))
80+
}
81+
7682
fun getRelativePathToContentRoot(editor: Editor): String? =
7783
editor.project?.let { project ->
7884
FileDocumentManager.getInstance().getFile(editor.document)?.let { vFile ->

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/model/CodeWhispererModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ data class FileContextInfo(
5959
val filename: String,
6060
val programmingLanguage: CodeWhispererProgrammingLanguage,
6161
val fileRelativePath: String?,
62+
val fileUri: String?,
6263
)
6364

6465
data class SupplementalContextInfo(

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
860860
.leftFileContent(fileContextInfo.caretContext.leftFileContext)
861861
.rightFileContent(fileContextInfo.caretContext.rightFileContext)
862862
.filename(fileContextInfo.fileRelativePath ?: fileContextInfo.filename)
863+
.fileUri(fileContextInfo.fileUri)
863864
.programmingLanguage(programmingLanguage)
864865
.build()
865866
val supplementalContexts = supplementalContext?.contents?.map {

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererServiceNew.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
838838
.leftFileContent(fileContextInfo.caretContext.leftFileContext)
839839
.rightFileContent(fileContextInfo.caretContext.rightFileContext)
840840
.filename(fileContextInfo.fileRelativePath ?: fileContextInfo.filename)
841+
.fileUri(fileContextInfo.fileUri)
841842
.programmingLanguage(programmingLanguage)
842843
.build()
843844
val supplementalContexts = supplementalContext?.contents?.map {

plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererCodeCoverageTrackerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
162162
fixture.editor,
163163
mock(),
164164
mock(),
165-
FileContextInfo(mock(), pythonFileName, CodeWhispererPython.INSTANCE, pythonFileName),
165+
FileContextInfo(mock(), pythonFileName, CodeWhispererPython.INSTANCE, pythonFileName, null),
166166
runBlocking {
167167
async {
168168
SupplementalContextInfo(

plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererFileContextProviderTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class CodeWhispererFileContextProviderTest {
109109
),
110110
"Foo.java",
111111
CodeWhispererJava.INSTANCE,
112+
"",
112113
""
113114
)
114115

@@ -128,6 +129,7 @@ class CodeWhispererFileContextProviderTest {
128129
),
129130
"Foo.java",
130131
CodeWhispererJava.INSTANCE,
132+
"",
131133
""
132134
)
133135

plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererServiceTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ class CodeWhispererServiceTest {
117117
CaretContext(leftFileContext = "", rightFileContext = "public class Main {}", leftContextOnCurrentLine = ""),
118118
"main.java",
119119
CodeWhispererJava.INSTANCE,
120-
"main.java"
120+
"main.java",
121+
"temp:///src/main.java"
121122
)
122123
)
123124
}
@@ -240,6 +241,7 @@ private fun CodeWhispererProgrammingLanguage.toSdkModel(): ProgrammingLanguage =
240241

241242
private fun FileContextInfo.toSdkModel(): FileContext = FileContext.builder()
242243
.filename(fileRelativePath)
244+
.fileUri(fileUri)
243245
.programmingLanguage(programmingLanguage.toCodeWhispererRuntimeLanguage().toSdkModel())
244246
.leftFileContent(caretContext.leftFileContext)
245247
.rightFileContent(caretContext.rightFileContext)

plugins/amazonq/codewhisperer/jetbrains-community/tstFixtures/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererTestUtil.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,13 @@ fun aFileContextInfo(language: CodeWhispererProgrammingLanguage? = null): FileCo
397397
val caretContextInfo = CaretContext(aString(), aString(), aString())
398398
val fileName = aString()
399399
val fileRelativePath = Paths.get("test", fileName).toString()
400+
val fileUri = "file:///$fileRelativePath"
400401
val programmingLanguage = language ?: listOf(
401402
CodeWhispererPython.INSTANCE,
402403
CodeWhispererJava.INSTANCE
403404
).random()
404405

405-
return FileContextInfo(caretContextInfo, fileName, programmingLanguage, fileRelativePath)
406+
return FileContextInfo(caretContextInfo, fileName, programmingLanguage, fileRelativePath, fileUri)
406407
}
407408

408409
fun aTriggerType(): CodewhispererTriggerType =

plugins/core/sdk-codegen/codegen-resources/codewhispererruntime/service-2.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,9 +1596,16 @@
15961596
"leftFileContent":{"shape":"FileContextLeftFileContentString"},
15971597
"rightFileContent":{"shape":"FileContextRightFileContentString"},
15981598
"filename":{"shape":"FileContextFilenameString"},
1599+
"fileUri": {"shape":"FileContextFileUriString"},
15991600
"programmingLanguage":{"shape":"ProgrammingLanguage"}
16001601
}
16011602
},
1603+
"FileContextFileUriString": {
1604+
"type": "string",
1605+
"max": 1024,
1606+
"min": 1,
1607+
"sensitive": true
1608+
},
16021609
"FileContextFilenameString":{
16031610
"type":"string",
16041611
"max":1024,

0 commit comments

Comments
 (0)