accept/reject all apply changes jetbrains

This commit is contained in:
Nate 2025-04-24 17:56:08 -07:00
parent 11a4be1c84
commit 0c3e013250
2 changed files with 52 additions and 0 deletions

View file

@ -432,6 +432,25 @@ class IdeProtocolClient(
}
}
"acceptDiff" -> {
val params = Gson().fromJson(
dataElement.toString(),
AcceptDiffParams::class.java
)
val filepath = params.filepath;
acceptOrRejectDiff(filepath, true)
}
"rejectDiff" -> {
val params = Gson().fromJson(
dataElement.toString(),
RejectDiffParams::class.java
)
val filepath = params.filepath;
acceptOrRejectDiff(filepath, false)
}
"applyToFile" -> {
val params = Gson().fromJson(
dataElement.toString(),
@ -648,6 +667,29 @@ class IdeProtocolClient(
continuePluginService.sendToWebview("acceptRejectDiff", AcceptRejectDiff(accepted, stepIndex), uuid())
}
fun acceptOrRejectDiff(filepath: String, accepted: Boolean) {
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(filepath)
if (virtualFile != null) {
ApplicationManager.getApplication().invokeAndWait {
val openedEditor =
FileEditorManager.getInstance(project).openFile(virtualFile, true)?.first()
if (openedEditor != null) {
val editor: Editor? = FileEditorManager.getInstance(project).selectedTextEditor
if (editor != null) {
val diffStreamService = project.service<DiffStreamService>()
if (accepted) {
diffStreamService.accept(editor)
} else {
diffStreamService.reject(editor)
}
}
}
}
}
}
fun deleteAtIndex(index: Int) {
continuePluginService.sendToWebview("deleteAtIndex", DeleteAtIndex(index), uuid())
}

View file

@ -15,6 +15,16 @@ data class ApplyToFileParams(
val toolCallId: String?
)
data class AcceptDiffParams(
val filepath: String,
val streamId: String
)
data class RejectDiffParams(
val filepath: String,
val streamId: String
)
data class InsertAtCursorParams(
val text: String
)