Skip to content

Commit 2d59143

Browse files
committed
reduce serializer calls
1 parent ef96d4c commit 2d59143

File tree

1 file changed

+10
-6
lines changed
  • plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview

1 file changed

+10
-6
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,20 @@ class BrowserConnector(
354354

355355
CHAT_INSERT_TO_CURSOR -> {
356356
val editor = FileEditorManager.getInstance(project).selectedTextEditor
357-
val textDocument = editor?.let { TextDocumentIdentifier(toUriString(it.virtualFile)) }
357+
val textDocumentIdentifier = editor?.let { TextDocumentIdentifier(toUriString(it.virtualFile)) }
358358
val cursorPosition = editor?.let { LspEditorUtil.getCursorPosition(it) }
359-
val enrichedParams = (node.params as? ObjectNode)?.apply {
360-
set<JsonNode>("cursorPosition", serializer.objectMapper.valueToTree(cursorPosition))
361-
set<JsonNode>("textDocument", serializer.objectMapper.valueToTree(textDocument))
362-
} ?: node.params
363359

360+
val enrichmentParams = mapOf(
361+
"textDocument" to textDocumentIdentifier,
362+
"cursorPosition" to cursorPosition,
363+
)
364+
365+
val insertToCursorPositionParams: ObjectNode = (node.params as ObjectNode)
366+
.setAll(serializer.objectMapper.valueToTree<ObjectNode>(enrichmentParams))
364367
val enrichedNode = (node as ObjectNode).apply {
365-
set<JsonNode>("params", enrichedParams)
368+
set<JsonNode>("params", insertToCursorPositionParams)
366369
}
370+
367371
handleChat(AmazonQChatServer.insertToCursorPosition, enrichedNode)
368372
}
369373

0 commit comments

Comments
 (0)