Skip to content

Commit 910d5a2

Browse files
authored
1.5.8 (#170)
1 parent 12bd206 commit 910d5a2

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies {
4242
exclude(group = "org.jetbrains.kotlin", module = "")
4343
}
4444

45-
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.59")
45+
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.60")
4646
{
4747
exclude(group = "org.jetbrains.kotlin", module = "")
4848
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pluginName=intellij-aicoder
22
pluginRepositoryUrl=https://github.com/SimiaCryptus/intellij-aicoder
3-
pluginVersion=1.5.7
3+
pluginVersion=1.5.8
44

55
jvmArgs=-Xmx8g
66
org.gradle.jvmargs=-Xmx8g
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.github.simiacryptus.aicoder.actions
2+
3+
import com.github.simiacryptus.aicoder.util.UITools
4+
import com.intellij.openapi.actionSystem.AnActionEvent
5+
import com.intellij.openapi.command.WriteCommandAction
6+
import com.intellij.openapi.ui.Messages
7+
import com.intellij.openapi.vfs.VirtualFile
8+
import com.intellij.psi.PsiManager
9+
import com.simiacryptus.diff.IterativePatchUtil
10+
11+
class ApplyPatchAction : BaseAction(
12+
name = "Apply Patch",
13+
description = "Applies a patch to the current file"
14+
) {
15+
16+
override fun handle(event: AnActionEvent) {
17+
val project = event.project ?: return
18+
val virtualFile = UITools.getSelectedFile(event) ?: return
19+
20+
// Prompt user to input patch content
21+
val patchContent = Messages.showMultilineInputDialog(
22+
project,
23+
"Enter the patch content:",
24+
"Input Patch",
25+
"",
26+
null,
27+
null
28+
) ?: return
29+
30+
applyPatch(virtualFile, patchContent, project)
31+
}
32+
33+
private fun applyPatch(file: VirtualFile, patchContent: String, project: com.intellij.openapi.project.Project) {
34+
WriteCommandAction.runWriteCommandAction(project) {
35+
val psiFile = PsiManager.getInstance(project).findFile(file) ?: return@runWriteCommandAction
36+
val newContent = IterativePatchUtil.patch(psiFile.text, patchContent)
37+
psiFile.virtualFile.setBinaryContent(newContent.toByteArray())
38+
}
39+
}
40+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989

9090
<add-to-group group-id="com.github.simiacryptus.aicoder.ui.ProjectMenu" anchor="last"/>
9191
</action>
92+
<action class="com.github.simiacryptus.aicoder.actions.ApplyPatchAction"
93+
text="Apply Patch"
94+
description="Apply a patch to the selected file">
95+
96+
<add-to-group group-id="com.github.simiacryptus.aicoder.ui.ProjectMenu" anchor="last"/>
97+
</action>
9298
<action class="com.github.simiacryptus.aicoder.actions.generic.MultiCodeChatAction"
9399
text="Code Chat"
94100
description="Open a chat session with multiple files">

0 commit comments

Comments
 (0)