Skip to content

Commit 0c3e013

Browse files
committed
accept/reject all apply changes jetbrains
1 parent 11a4be1 commit 0c3e013

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,25 @@ class IdeProtocolClient(
432432
}
433433
}
434434

435+
"acceptDiff" -> {
436+
val params = Gson().fromJson(
437+
dataElement.toString(),
438+
AcceptDiffParams::class.java
439+
)
440+
val filepath = params.filepath;
441+
442+
acceptOrRejectDiff(filepath, true)
443+
}
444+
445+
"rejectDiff" -> {
446+
val params = Gson().fromJson(
447+
dataElement.toString(),
448+
RejectDiffParams::class.java
449+
)
450+
val filepath = params.filepath;
451+
acceptOrRejectDiff(filepath, false)
452+
}
453+
435454
"applyToFile" -> {
436455
val params = Gson().fromJson(
437456
dataElement.toString(),
@@ -648,6 +667,29 @@ class IdeProtocolClient(
648667
continuePluginService.sendToWebview("acceptRejectDiff", AcceptRejectDiff(accepted, stepIndex), uuid())
649668
}
650669

670+
fun acceptOrRejectDiff(filepath: String, accepted: Boolean) {
671+
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(filepath)
672+
673+
if (virtualFile != null) {
674+
ApplicationManager.getApplication().invokeAndWait {
675+
val openedEditor =
676+
FileEditorManager.getInstance(project).openFile(virtualFile, true)?.first()
677+
if (openedEditor != null) {
678+
val editor: Editor? = FileEditorManager.getInstance(project).selectedTextEditor
679+
680+
if (editor != null) {
681+
val diffStreamService = project.service<DiffStreamService>()
682+
if (accepted) {
683+
diffStreamService.accept(editor)
684+
} else {
685+
diffStreamService.reject(editor)
686+
}
687+
}
688+
}
689+
}
690+
}
691+
}
692+
651693
fun deleteAtIndex(index: Int) {
652694
continuePluginService.sendToWebview("deleteAtIndex", DeleteAtIndex(index), uuid())
653695
}

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/protocol/ideWebview.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ data class ApplyToFileParams(
1515
val toolCallId: String?
1616
)
1717

18+
data class AcceptDiffParams(
19+
val filepath: String,
20+
val streamId: String
21+
)
22+
23+
data class RejectDiffParams(
24+
val filepath: String,
25+
val streamId: String
26+
)
27+
1828
data class InsertAtCursorParams(
1929
val text: String
2030
)

0 commit comments

Comments
 (0)