@@ -27,6 +27,7 @@ import software.amazon.awssdk.services.codewhispererstreaming.model.GenerateAssi
27
27
import software.amazon.awssdk.services.codewhispererstreaming.model.Position
28
28
import software.amazon.awssdk.services.codewhispererstreaming.model.ProgrammingLanguage
29
29
import software.amazon.awssdk.services.codewhispererstreaming.model.Range
30
+ import software.amazon.awssdk.services.codewhispererstreaming.model.RelevantTextDocument
30
31
import software.amazon.awssdk.services.codewhispererstreaming.model.SupplementaryWebLinksEvent
31
32
import software.amazon.awssdk.services.codewhispererstreaming.model.SymbolType
32
33
import software.amazon.awssdk.services.codewhispererstreaming.model.TextDocument
@@ -50,6 +51,7 @@ import software.aws.toolkits.jetbrains.services.cwc.clients.chat.model.Reference
50
51
import software.aws.toolkits.jetbrains.services.cwc.clients.chat.model.SuggestedFollowUp
51
52
import software.aws.toolkits.jetbrains.services.cwc.clients.chat.model.Suggestion
52
53
import software.aws.toolkits.jetbrains.services.cwc.editor.context.ActiveFileContext
54
+ import software.aws.toolkits.jetbrains.services.cwc.editor.context.project.RelevantDocument
53
55
54
56
class ChatSessionV1 (
55
57
private val project : Project ,
@@ -60,7 +62,6 @@ class ChatSessionV1(
60
62
override fun chat (data : ChatRequestData ): Flow <ChatResponseEvent > = callbackFlow {
61
63
var requestId: String = " "
62
64
var statusCode: Int = 0
63
-
64
65
val responseHandler = GenerateAssistantResponseResponseHandler .builder()
65
66
.onResponse {
66
67
requestId = it.responseMetadata().requestId()
@@ -197,9 +198,7 @@ class ChatSessionV1(
197
198
*/
198
199
private fun ChatRequestData.toChatRequest (): GenerateAssistantResponseRequest {
199
200
val userInputMessageContextBuilder = UserInputMessageContext .builder()
200
- if (activeFileContext.fileContext != null ) {
201
- userInputMessageContextBuilder.editorState(activeFileContext.toEditorState())
202
- }
201
+ userInputMessageContextBuilder.editorState(activeFileContext.toEditorState(relevantTextDocuments))
203
202
val userInputMessageContext = userInputMessageContextBuilder.build()
204
203
205
204
val userInput = UserInputMessage .builder()
@@ -218,67 +217,74 @@ class ChatSessionV1(
218
217
.build()
219
218
}
220
219
221
- private fun ActiveFileContext.toEditorState (): EditorState {
222
- // Cursor State
223
- val start = focusAreaContext?.codeSelectionRange?.start
224
- val end = focusAreaContext?.codeSelectionRange?.end
220
+ private fun ActiveFileContext.toEditorState (relevantDocuments : List <RelevantDocument >): EditorState {
221
+ val editorStateBuilder = EditorState .builder()
222
+ if (fileContext != null ) {
223
+ val cursorStateBuilder = CursorState .builder()
224
+ // Cursor State
225
+ val start = focusAreaContext?.codeSelectionRange?.start
226
+ val end = focusAreaContext?.codeSelectionRange?.end
225
227
226
- val cursorStateBuilder = CursorState .builder()
228
+ if (start != null && end != null ) {
229
+ cursorStateBuilder.range(
230
+ Range .builder()
231
+ .start(
232
+ Position .builder()
233
+ .line(start.row)
234
+ .character(start.column)
235
+ .build(),
236
+ )
237
+ .end(
238
+ Position .builder()
239
+ .line(end.row)
240
+ .character(end.column)
241
+ .build(),
242
+ ).build(),
243
+ )
244
+ }
245
+ editorStateBuilder.cursorState(cursorStateBuilder.build())
227
246
228
- if (start != null && end != null ) {
229
- cursorStateBuilder.range(
230
- Range .builder()
231
- .start(
232
- Position .builder()
233
- .line(start.row)
234
- .character(start.column)
235
- .build(),
236
- )
237
- .end(
238
- Position .builder()
239
- .line(end.row)
240
- .character(end.column)
241
- .build(),
242
- ).build(),
243
- )
244
- }
247
+ // Code Names -> DocumentSymbols
248
+ val documentBuilder = TextDocument .builder()
249
+ val codeNames = focusAreaContext?.codeNames
245
250
246
- // Code Names -> DocumentSymbols
247
- val codeNames = focusAreaContext?.codeNames
248
- val documentBuilder = TextDocument .builder()
251
+ val documentSymbolList = codeNames?.fullyQualifiedNames?.used?.map {
252
+ DocumentSymbol .builder()
253
+ .name(it.symbol?.joinToString(separator = " ." ))
254
+ .type(SymbolType .USAGE )
255
+ .source(it.source?.joinToString(separator = " ." ))
256
+ .build()
257
+ }?.filter { it.name().length in ChatConstants .FQN_SIZE_MIN until ChatConstants .FQN_SIZE_LIMIT }.orEmpty()
258
+ documentBuilder.documentSymbols(documentSymbolList)
249
259
250
- val documentSymbolList = codeNames?.fullyQualifiedNames?.used?.map {
251
- DocumentSymbol .builder()
252
- .name(it.symbol?.joinToString(separator = " ." ))
253
- .type(SymbolType .USAGE )
254
- .source(it.source?.joinToString(separator = " ." ))
255
- .build()
256
- }?.filter { it.name().length in ChatConstants .FQN_SIZE_MIN until ChatConstants .FQN_SIZE_LIMIT }.orEmpty()
257
- documentBuilder.documentSymbols(documentSymbolList)
260
+ // File Text
261
+ val trimmedFileText = focusAreaContext?.trimmedSurroundingFileText
262
+ documentBuilder.text(trimmedFileText)
258
263
259
- // File Text
260
- val trimmedFileText = focusAreaContext?.trimmedSurroundingFileText
261
- documentBuilder.text(trimmedFileText)
264
+ // Programming Language
265
+ val programmingLanguage = fileContext.fileLanguage
266
+ if (programmingLanguage != null && validLanguages.contains(programmingLanguage)) {
267
+ documentBuilder.programmingLanguage(
268
+ ProgrammingLanguage .builder()
269
+ .languageName(programmingLanguage).build(),
270
+ )
271
+ }
262
272
263
- // Programming Language
264
- val programmingLanguage = fileContext?.fileLanguage
265
- if (programmingLanguage != null && validLanguages.contains(programmingLanguage)) {
266
- documentBuilder.programmingLanguage(
267
- ProgrammingLanguage .builder()
268
- .languageName(programmingLanguage).build(),
269
- )
273
+ // Relative File Path
274
+ val filePath = fileContext.filePath
275
+ if (filePath != null ) {
276
+ documentBuilder.relativeFilePath(filePath.take(ChatConstants .FILE_PATH_SIZE_LIMIT ))
277
+ }
278
+ editorStateBuilder.document(documentBuilder.build())
270
279
}
271
280
272
- // Relative File Path
273
- val filePath = fileContext?.filePath
274
- if (filePath != null ) {
275
- documentBuilder.relativeFilePath(filePath.take(ChatConstants .FILE_PATH_SIZE_LIMIT ))
281
+ // Relevant Documents
282
+ val documents: List <RelevantTextDocument > = relevantDocuments.map { doc ->
283
+ RelevantTextDocument .builder().text(doc.text).relativeFilePath(doc.relativeFilePath.take(ChatConstants .FILE_PATH_SIZE_LIMIT )).build()
276
284
}
277
285
278
- return EditorState .builder()
279
- .cursorState(cursorStateBuilder.build())
280
- .document(documentBuilder.build())
281
- .build()
286
+ editorStateBuilder.relevantDocuments(documents)
287
+ return editorStateBuilder.build()
282
288
}
283
289
284
290
private fun UserIntent?.toFollowUpType () = when (this ) {
0 commit comments