-
Notifications
You must be signed in to change notification settings - Fork 274
config(amazonq): Add project context to inline completion #4976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
fbdd4d3
b150cb8
eaf4932
13f2f94
8577d78
43d698f
0655f48
1ff4021
a59204c
3840926
99c3437
fe86a2c
b642283
7b5ea32
b684c01
1e2b21a
3729d98
e45078e
47e3190
5f3ea1a
1628d33
2249c8a
22acbf8
cf4c29c
149e6af
9844c03
5ab3d11
71451b9
d7d65d5
87f4f2c
4663e48
626079d
64cd531
4b461c1
b1936f7
f911b3d
91ae00e
9e79e54
13e04d2
4da830b
ff27d01
1966408
3c39f90
7c7d58b
9f097d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |
| import software.aws.toolkits.core.utils.getLogger | ||
| import software.aws.toolkits.core.utils.info | ||
| import software.aws.toolkits.core.utils.warn | ||
| import software.aws.toolkits.jetbrains.services.amazonq.CodeWhispererFeatureConfigService | ||
| import software.aws.toolkits.jetbrains.services.amazonq.project.ProjectContextController | ||
| import software.aws.toolkits.jetbrains.services.codewhisperer.editor.CodeWhispererEditorUtil | ||
| import software.aws.toolkits.jetbrains.services.codewhisperer.language.CodeWhispererProgrammingLanguage | ||
| import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererJava | ||
|
|
@@ -206,15 +208,49 @@ | |
|
|
||
| override fun isTestFile(psiFile: PsiFile) = psiFile.programmingLanguage().fileCrawler.isTestFile(psiFile.virtualFile, psiFile.project) | ||
|
|
||
| @VisibleForTesting | ||
| suspend fun extractSupplementalFileContextForSrc(psiFile: PsiFile, targetContext: FileContextInfo): SupplementalContextInfo { | ||
| if (!targetContext.programmingLanguage.isSupplementalContextSupported()) { | ||
| return SupplementalContextInfo.emptyCrossFileContextInfo(targetContext.filename) | ||
| } | ||
|
|
||
| // takeLast(11) will extract 10 lines (exclusing current line) of left context as the query parameter | ||
| val query = targetContext.caretContext.leftFileContext.split("\n").takeLast(11).joinToString("\n") | ||
| val query = generateQuery(targetContext) | ||
|
|
||
| val projectContext = if (CodeWhispererFeatureConfigService.getInstance().getInlineCompletion()) { | ||
| fetchProjectContext(query, psiFile, targetContext) | ||
| } else { | ||
| null | ||
| } | ||
|
|
||
| val openTabsContext = fetchOpentabsContext(query, psiFile, targetContext) | ||
|
|
||
| return if (projectContext == null || projectContext.contents.isEmpty()) { | ||
| openTabsContext | ||
| } else { | ||
| projectContext | ||
| } | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| suspend fun fetchProjectContext(query: String, psiFile: PsiFile, targetContext: FileContextInfo): SupplementalContextInfo { | ||
|
||
| val response = ProjectContextController.getInstance(project).queryInline(query, psiFile.virtualFile?.path ?: "") | ||
|
|
||
| return SupplementalContextInfo( | ||
| isUtg = false, | ||
| contents = response.map { | ||
| Chunk( | ||
| content = it.content, | ||
| path = it.filePath, | ||
| nextChunk = it.content, | ||
| score = it.score | ||
| ) | ||
| }, | ||
| targetFileName = targetContext.filename, | ||
| strategy = CrossFileStrategy.ProjectContext | ||
| ) | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| suspend fun fetchOpentabsContext(query: String, psiFile: PsiFile, targetContext: FileContextInfo): SupplementalContextInfo { | ||
| // step 1: prepare data | ||
| val first60Chunks: List<Chunk> = try { | ||
| runReadAction { codewhispererCodeChunksIndex.getFileData(psiFile) } | ||
|
|
@@ -305,6 +341,9 @@ | |
| } | ||
| } | ||
|
|
||
| // takeLast(11) will extract 10 lines (exclusing current line) of left context as the query parameter | ||
| fun generateQuery(fileContext: FileContextInfo) = fileContext.caretContext.leftFileContext.split("\n").takeLast(11).joinToString("\n") | ||
|
Check notice on line 345 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererFileContextProvider.kt
|
||
Check noticeCode scanning / QDJVMC Class member can have 'private' visibility Note
Function 'generateQuery' could be private
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i wanna add test for this query fun later so leave it public for now. |
||
|
|
||
| companion object { | ||
| private val LOG = getLogger<DefaultCodeWhispererFileContextProvider>() | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.