Skip to content

Conversation

samgst-amazon
Copy link
Contributor

@samgst-amazon samgst-amazon commented Jul 10, 2025

Clicking the insert to cursor option on code blocks generated in Q chat previously did not actually apply the change.

This change now inserts the code block to the cursor position on the current active file in the editor.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Description

  • Added missing params to the InsertToCursorPosition params as VSC was doing
  • Handle the workspace/applyEdit message we would get in response to apply the code block to the cursor position.

Checklist

  • My code follows the code style of this project
  • I have added tests to cover my changes
  • A short description of the change has been added to the CHANGELOG if the change is customer-facing in the IDE.
  • I have added metrics for my changes (if required)

License

I confirm that my contribution is made under the terms of the Apache 2.0 license.

@samgst-amazon samgst-amazon requested review from a team as code owners July 10, 2025 22:31
Copy link

github-actions bot commented Jul 10, 2025

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at [email protected]

val textDocument = editor?.let { TextDocumentIdentifier(toUriString(it.virtualFile)) }
val cursorPosition = editor?.let { LspEditorUtil.getCursorPosition(it) }
val enrichedParams = (node.params as? ObjectNode)?.apply {
set<JsonNode>("cursorPosition", serializer.objectMapper.valueToTree(cursorPosition))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see SEND_CHAT_COMMAND_PROMPT to see how we can reduce number of serializer calls

)
}

fun applyWorkspaceEdit(project: Project, edit: WorkspaceEdit) {
Copy link
Contributor

@rli rli Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow up later with tests for at least this method

Comment on lines +43 to +45
virtualFileManager = mockk(relaxed = true)
fileDocumentManager = mockk(relaxed = true)
fileEditorManager = mockk(relaxed = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take a look at CodeInsightTestFixture

@samgst-amazon samgst-amazon merged commit afaec95 into main Jul 15, 2025
14 of 16 checks passed
@samgst-amazon samgst-amazon deleted the samgst/insert-to-cursor-fix branch July 15, 2025 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants