@@ -31,6 +31,7 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.model.FileContextI
31
31
import software.aws.toolkits.jetbrains.services.codewhisperer.model.SupplementalContextInfo
32
32
import java.io.DataInput
33
33
import java.io.DataOutput
34
+ import java.util.Collections
34
35
35
36
private val contentRootPathProvider = CopyContentRootPathProvider ()
36
37
@@ -147,20 +148,20 @@ class DefaultCodeWhispererFileContextProvider(private val project: Project) : Fi
147
148
148
149
override suspend fun extractCodeChunksFromFiles (psiFile : PsiFile , fileProducers : List <suspend (PsiFile ) -> List <VirtualFile >>): List <Chunk > {
149
150
val parseFilesStart = System .currentTimeMillis()
150
- val hasUsed = mutableSetOf<VirtualFile >()
151
+ val hasUsed = Collections .synchronizedSet( mutableSetOf<VirtualFile >() )
151
152
val chunks = mutableListOf<Chunk >()
152
153
153
154
for (fileProducer in fileProducers) {
154
155
yield ()
155
156
val files = fileProducer(psiFile)
156
-
157
157
files.forEach { file ->
158
158
yield ()
159
159
if (hasUsed.contains(file)) {
160
160
return @forEach
161
161
}
162
162
val relativePath = runReadAction { contentRootPathProvider.getPathToElement(project, file, null ) ? : file.path }
163
163
chunks.addAll(file.toCodeChunk(relativePath))
164
+ hasUsed.add(file)
164
165
if (chunks.size > CHUNK_SIZE ) {
165
166
LOG .debug { " finish fetching 60 chunks in ${System .currentTimeMillis() - parseFilesStart} ms" }
166
167
return chunks.take(CHUNK_SIZE )
@@ -182,7 +183,8 @@ class DefaultCodeWhispererFileContextProvider(private val project: Project) : Fi
182
183
suspend fun extractSupplementalFileContextForSrc (psiFile : PsiFile , targetContext : FileContextInfo ): List <Chunk > {
183
184
if (! targetContext.programmingLanguage.isSupplementalContextSupported()) return emptyList()
184
185
185
- val query = targetContext.caretContext.leftFileContext.split(" \n " ).takeLast(10 ).joinToString(" \n " )
186
+ // takeLast(11) will extract 10 lines (exclusing current line) of left context as the query parameter
187
+ val query = targetContext.caretContext.leftFileContext.split(" \n " ).takeLast(11 ).joinToString(" \n " )
186
188
187
189
// step 1: prepare data
188
190
val first60Chunks: List <Chunk > = try {
0 commit comments