Skip to content

Commit

Permalink
1.2.15 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski authored Sep 25, 2023
1 parent 1243791 commit 2e19884
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 26 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ repositories {
val kotlin_version = "1.7.22"
val jetty_version = "11.0.15"
val slf4j_version = "2.0.5"
val skyenet_version = "1.0.14"
val skyenet_version = "1.0.16"
dependencies {

implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.16")
implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.18")

implementation(group = "com.simiacryptus.skyenet", name = "util", version = skyenet_version)
implementation(group = "com.simiacryptus.skyenet", name = "core", version = skyenet_version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.simiacryptus.aicoder.actions.code

import com.github.simiacryptus.aicoder.actions.SelectionAction
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.util.UITools
import com.intellij.openapi.project.Project
import com.simiacryptus.openai.proxy.ChatProxy
import org.jetbrains.annotations.Nullable
Expand Down Expand Up @@ -60,7 +61,9 @@ class CustomEditAction extends SelectionAction<String> {

@Override
String getConfig(@Nullable Project project) {
return JOptionPane.showInputDialog(null, "Instruction:", "Edit Code", JOptionPane.QUESTION_MESSAGE)
return UITools.showInputDialog(null, "Instruction:", "Edit Code", JOptionPane.QUESTION_MESSAGE
//, AppSettingsState.instance.getRecentCommands("customEdits").mostRecentHistory
)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AnalogueFileAction extends FileContextAction<AnalogueFileAction.Settings>

@Override
File[] processSelection(SelectionState state, Settings config) {
ProjectFile analogue = generateFile(
ProjectFile analogue = generateFile(
new ProjectFile(
path: state.projectRoot.toPath().relativize(state.selectedFile.toPath()),
code: IOUtils.toString(new FileInputStream(state.selectedFile), "UTF-8")
Expand All @@ -73,6 +73,7 @@ class AnalogueFileAction extends FileContextAction<AnalogueFileAction.Settings>
FileUtils.write(outputPath.toFile(), analogue.code, "UTF-8")
Thread.sleep(100)
return [outputPath.toFile()]

}

private ProjectFile generateFile(ProjectFile baseFile, String directive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.stream.Collectors
class ActionSettingsRegistry {

val actionSettings: MutableMap<String, ActionSettings> = HashMap()
val version = 1.6
val version = 1.8

fun edit(superChildren: Array<out AnAction>): Array<AnAction> {
val children = superChildren.toList().toMutableList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class MRUItems {
var historyLimit = 10
fun addInstructionToHistory(instruction: CharSequence) {
synchronized(mostRecentHistory) {
if(mostRecentHistory.contains(instruction.toString())) {
mostRecentHistory.remove(instruction.toString())
}
mostRecentHistory.add(instruction.toString())
while (mostRecentHistory.size > historyLimit) {
mostRecentHistory.removeAt(0)
Expand All @@ -35,9 +38,8 @@ class MRUItems {
toRemove.removeAll(retain.toSet())
toRemove.removeAll(mostRecentHistory.toSet())
toRemove.forEach { key: CharSequence? ->
mostUsedHistory.remove(
key
)
mostUsedHistory.remove(key)
mostRecentHistory.remove(key.toString())
}
}
}
Expand Down
101 changes: 87 additions & 14 deletions src/main/kotlin/com/github/simiacryptus/aicoder/util/UITools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import java.lang.reflect.Modifier
import java.net.URI
import java.util.*
import java.util.concurrent.*
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
import java.util.function.Supplier
import java.util.stream.Collectors
Expand Down Expand Up @@ -788,12 +789,6 @@ object UITools {
return null
}

@JvmStatic
fun isInterruptedException(e: Throwable?): Boolean {
if (e is InterruptedException) return true
return if (e!!.cause != null && e.cause !== e) isInterruptedException(e.cause) else false
}

@JvmStatic
fun writeableFn(
event: AnActionEvent,
Expand All @@ -807,7 +802,10 @@ object UITools {
class ModalTask<T>(
project : Project, title : String, canBeCancelled : Boolean, val task : (ProgressIndicator) -> T
) : Task.WithResult<T, Exception>(project, title, canBeCancelled), Supplier<T> {
private var result: T? = null
private val result = AtomicReference<T>()
private val isError = AtomicBoolean(false)
private val error = AtomicReference<Throwable>()
private val semaphore = Semaphore(0)
override fun compute(indicator: ProgressIndicator): T? {
val currentThread = Thread.currentThread()
val threads = ArrayList<Thread>()
Expand All @@ -818,19 +816,27 @@ object UITools {
}, 0, 1, TimeUnit.SECONDS)
threads.add(currentThread)
return try {
result = task(indicator)
result!!
result.set(task(indicator))
result.get()
} catch (e: Throwable) {
error(log, "Error running task", e)
isError.set(true)
error.set(e)
null
} finally {
semaphore.release()
threads.remove(currentThread)
scheduledFuture.cancel(true)
}
}

override fun get(): T {
return result!!
semaphore.acquire()
semaphore.release()
if (isError.get()) {
throw error.get()
}
return result.get()
}

}
Expand All @@ -839,7 +845,9 @@ object UITools {
project : Project, title : String, canBeCancelled : Boolean, val task : (ProgressIndicator) -> T
) : Task.Backgroundable(project, title ?: "", canBeCancelled, DEAF), Supplier<T> {

private val ref = AtomicReference<T>()
private val result = AtomicReference<T>()
private val isError = AtomicBoolean(false)
private val error = AtomicReference<Throwable>()
private val semaphore = Semaphore(0)
override fun run(indicator: ProgressIndicator) {
val currentThread = Thread.currentThread()
Expand All @@ -852,19 +860,25 @@ object UITools {
threads.add(currentThread)
try {
val result = task(indicator)
ref.set(result)
semaphore.release()
this.result.set(result)
} catch (e: Throwable) {
error(log, "Error running task", e)
error.set(e)
isError.set(true)
} finally {
semaphore.release()
threads.remove(currentThread)
scheduledFuture.cancel(true)
}
}

override fun get(): T {
semaphore.acquire()
return ref.get()
semaphore.release()
if (isError.get()) {
throw error.get()
}
return result.get()
}
}

Expand Down Expand Up @@ -1196,6 +1210,65 @@ object UITools {
return sw.toString()
}

// Wrap JOptionPane.showInputDialog
@JvmStatic fun showInputDialog(
parentComponent: Component?,
message: Any?,
title: String?,
messageType: Int
): Any? {
val icon = null
val selectionValues = null
val initialSelectionValue = null
val pane = JOptionPane(
message,
messageType,
JOptionPane.OK_CANCEL_OPTION,
icon,
null,
null
)
pane.wantsInput = true
pane.selectionValues = selectionValues
pane.initialSelectionValue = initialSelectionValue
//pane.isComponentOrientationLeftToRight = true
val dialog = pane.createDialog(parentComponent, title)
pane.selectInitialValue()
dialog.show()
dialog.dispose()
val value = pane.inputValue
return if (value == JOptionPane.UNINITIALIZED_VALUE) null else value
}

@JvmStatic fun showInputDialog(
parentComponent: Component?,
message: Any?,
title: String?,
messageType: Int,
mru: List<String>,
providedOptions: List<String>?
): Any? {
val icon = null
val selectionValues = (mru + (providedOptions ?: emptyList())).toTypedArray()
val initialSelectionValue = null
val pane = JOptionPane(
message,
messageType,
JOptionPane.OK_CANCEL_OPTION,
icon,
null,
null
)
pane.wantsInput = true
pane.selectionValues = selectionValues
pane.initialSelectionValue = initialSelectionValue
val dialog = pane.createDialog(parentComponent, title)
pane.selectInitialValue()
dialog.show()
dialog.dispose()
val value = pane.inputValue
return if (value == JOptionPane.UNINITIALIZED_VALUE) null else value
}

}

4 changes: 2 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
text="_AI Coder"
icon="AllIcons.Actions.Lightning"
description="AI coding assistant tools">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
<add-to-group group-id="EditorPopupMenu" anchor="first" />
</group>
<group id="com.github.simiacryptus.aicoder.ui.ProjectMenu"
class="com.github.simiacryptus.aicoder.ui.ProjectMenu"
popup="true"
text="_AI Coder"
icon="AllIcons.Actions.Lightning"
description="AI coding assistant tools">
<add-to-group group-id="ProjectViewPopupMenu" anchor="first"/>
<add-to-group group-id="ProjectViewPopupMenu" anchor="after" relative-to-action="WeighingNewGroup"/>
</group>

<action class="com.github.simiacryptus.aicoder.actions.dev.PrintTreeAction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.simiacryptus.aicoder.actions.code

import com.github.simiacryptus.aicoder.actions.SelectionAction
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.util.UITools
import com.intellij.openapi.project.Project
import com.simiacryptus.openai.proxy.ChatProxy
import org.jetbrains.annotations.Nullable
Expand Down Expand Up @@ -60,7 +61,9 @@ class CustomEditAction extends SelectionAction<String> {

@Override
String getConfig(@Nullable Project project) {
return JOptionPane.showInputDialog(null, "Instruction:", "Edit Code", JOptionPane.QUESTION_MESSAGE)
return UITools.showInputDialog(null, "Instruction:", "Edit Code", JOptionPane.QUESTION_MESSAGE
//, AppSettingsState.instance.getRecentCommands("customEdits").mostRecentHistory
)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AnalogueFileAction extends FileContextAction<AnalogueFileAction.Settings>

@Override
File[] processSelection(SelectionState state, Settings config) {
ProjectFile analogue = generateFile(
ProjectFile analogue = generateFile(
new ProjectFile(
path: state.projectRoot.toPath().relativize(state.selectedFile.toPath()),
code: IOUtils.toString(new FileInputStream(state.selectedFile), "UTF-8")
Expand All @@ -73,6 +73,7 @@ class AnalogueFileAction extends FileContextAction<AnalogueFileAction.Settings>
FileUtils.write(outputPath.toFile(), analogue.code, "UTF-8")
Thread.sleep(100)
return [outputPath.toFile()]

}

private ProjectFile generateFile(ProjectFile baseFile, String directive) {
Expand Down

0 comments on commit 2e19884

Please sign in to comment.