Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ object CodeWhispererEditorUtil {
val fileName = getFileName(psiFile)
val programmingLanguage = psiFile.programmingLanguage()
val fileRelativePath = getRelativePathToContentRoot(editor)
return FileContextInfo(caretContext, fileName, programmingLanguage, fileRelativePath)
val fileUri = getFileUri(psiFile)
return FileContextInfo(caretContext, fileName, programmingLanguage, fileRelativePath, fileUri)
}

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

private fun getFileUri(psiFile: PsiFile): String? =
psiFile.virtualFile?.takeIf { it.isValid }?.let { vFile ->
vFile.url.substring(0, vFile.url.length.coerceAtMost(CodeWhispererConstants.FILENAME_CHARS_LIMIT))
}

fun getRelativePathToContentRoot(editor: Editor): String? =
editor.project?.let { project ->
FileDocumentManager.getInstance().getFile(editor.document)?.let { vFile ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ data class FileContextInfo(
val filename: String,
val programmingLanguage: CodeWhispererProgrammingLanguage,
val fileRelativePath: String?,
val fileUri: String?,
)

data class SupplementalContextInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
.leftFileContent(fileContextInfo.caretContext.leftFileContext)
.rightFileContent(fileContextInfo.caretContext.rightFileContext)
.filename(fileContextInfo.fileRelativePath ?: fileContextInfo.filename)
.fileUri(fileContextInfo.fileUri)
.programmingLanguage(programmingLanguage)
.build()
val supplementalContexts = supplementalContext?.contents?.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
.leftFileContent(fileContextInfo.caretContext.leftFileContext)
.rightFileContent(fileContextInfo.caretContext.rightFileContext)
.filename(fileContextInfo.fileRelativePath ?: fileContextInfo.filename)
.fileUri(fileContextInfo.fileUri)
.programmingLanguage(programmingLanguage)
.build()
val supplementalContexts = supplementalContext?.contents?.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
fixture.editor,
mock(),
mock(),
FileContextInfo(mock(), pythonFileName, CodeWhispererPython.INSTANCE, pythonFileName),
FileContextInfo(mock(), pythonFileName, CodeWhispererPython.INSTANCE, pythonFileName, null),
runBlocking {
async {
SupplementalContextInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class CodeWhispererFileContextProviderTest {
),
"Foo.java",
CodeWhispererJava.INSTANCE,
"",
""
)

Expand All @@ -128,6 +129,7 @@ class CodeWhispererFileContextProviderTest {
),
"Foo.java",
CodeWhispererJava.INSTANCE,
"",
""
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class CodeWhispererServiceTest {
CaretContext(leftFileContext = "", rightFileContext = "public class Main {}", leftContextOnCurrentLine = ""),
"main.java",
CodeWhispererJava.INSTANCE,
"main.java"
"main.java",
"temp:///src/main.java"
)
)
}
Expand Down Expand Up @@ -240,6 +241,7 @@ private fun CodeWhispererProgrammingLanguage.toSdkModel(): ProgrammingLanguage =

private fun FileContextInfo.toSdkModel(): FileContext = FileContext.builder()
.filename(fileRelativePath)
.fileUri(fileUri)
.programmingLanguage(programmingLanguage.toCodeWhispererRuntimeLanguage().toSdkModel())
.leftFileContent(caretContext.leftFileContext)
.rightFileContent(caretContext.rightFileContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,13 @@ fun aFileContextInfo(language: CodeWhispererProgrammingLanguage? = null): FileCo
val caretContextInfo = CaretContext(aString(), aString(), aString())
val fileName = aString()
val fileRelativePath = Paths.get("test", fileName).toString()
val fileUri = "file:///$fileRelativePath"
val programmingLanguage = language ?: listOf(
CodeWhispererPython.INSTANCE,
CodeWhispererJava.INSTANCE
).random()

return FileContextInfo(caretContextInfo, fileName, programmingLanguage, fileRelativePath)
return FileContextInfo(caretContextInfo, fileName, programmingLanguage, fileRelativePath, fileUri)
}

fun aTriggerType(): CodewhispererTriggerType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1596,9 +1596,16 @@
"leftFileContent":{"shape":"FileContextLeftFileContentString"},
"rightFileContent":{"shape":"FileContextRightFileContentString"},
"filename":{"shape":"FileContextFilenameString"},
"fileUri": {"shape":"FileContextFileUriString"},
"programmingLanguage":{"shape":"ProgrammingLanguage"}
}
},
"FileContextFileUriString": {
"type": "string",
"max": 1024,
"min": 1,
"sensitive": true
},
"FileContextFilenameString":{
"type":"string",
"max":1024,
Expand Down
Loading