Skip to content

Commit

Permalink
Merge pull request #33 from devchat-ai/bug-fix
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
pplam authored Dec 18, 2023
2 parents f3ff7ab + 6241876 commit 72297dc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "ai.devchat"
version = "0.0.2"
version = "0.0.3"

repositories {
mavenCentral()
Expand Down Expand Up @@ -56,4 +56,4 @@ tasks {
}
kotlin {
jvmToolchain(17)
}
}
2 changes: 1 addition & 1 deletion gui
27 changes: 14 additions & 13 deletions src/main/kotlin/ai/devchat/cli/DevChatWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ class DevChatWrapper(
private fun execCommandAsync(
commands: List<String>,
onOutput: (String) -> Unit,
onError: (String) -> Unit = Log::error
onError: (String) -> Unit = Log::warn
): Job {
Log.info("Executing command: ${commands.joinToString(" ")}}")
val exceptionHandler = CoroutineExceptionHandler { _, exception ->
Log.warn("Failed to execute command: $commands, Exception: $exception")
throw CommandExecutionException("Failed to execute command: $commands, $exception")
onError("DevChat failed to response the message.")
}
val cmdScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)

Expand All @@ -112,16 +112,17 @@ class DevChatWrapper(

val prompt: (MutableList<Pair<String, String?>>, String, ((String) -> Unit)?) -> Unit get() = {
flags: MutableList<Pair<String, String?>>, message: String, callback: ((String) -> Unit)? ->
if (apiKey.isNullOrEmpty()) {
DevChatNotifier.stickyError("DevChat Error", "Please config your API key first.")
} else if (!apiKey!!.startsWith("DC.")) {
DevChatNotifier.stickyError("DevChat Error", "Invalid API key format.")
when {
apiKey.isNullOrEmpty() -> DevChatNotifier.stickyError("Please config your API key first.")
!apiKey!!.startsWith("DC.") -> DevChatNotifier.stickyError("Invalid API key format.")
else -> {
flags
.find { it.first == "model" && !it.second.isNullOrEmpty() }
.alsoIfNull { flags.add("model" to defaultModel) }
flags.add("" to message)
subCommand(listOf("prompt"))(flags, callback)
}
}
flags
.find { it.first == "model" && !it.second.isNullOrEmpty() }
.alsoIfNull { flags.add("model" to defaultModel) }
flags.add("" to message)
subCommand(listOf("prompt"))(flags, callback)
}

val run get() = subCommand(listOf("run"))
Expand Down Expand Up @@ -166,7 +167,7 @@ class DevChatWrapper(
cmd.addIfNotNull(value)
}
return try {
callback?.let { execCommandAsync(cmd, callback); "" } ?: execCommand(cmd)
callback?.let { execCommandAsync(cmd, callback, DevChatNotifier::stickyError); "" } ?: execCommand(cmd)
} catch (e: Exception) {
Log.warn("Failed to run command $cmd: ${e.message}")
throw CommandExecutionException("Failed to run command $cmd, $e")
Expand All @@ -182,7 +183,7 @@ class DevChatWrapper(
cmd.addIfNotNull(value)
}
try {
callback?.let { execCommandAsync(cmd, callback); "" } ?: execCommand(cmd)
callback?.let { execCommandAsync(cmd, callback, DevChatNotifier::stickyError); "" } ?: execCommand(cmd)
} catch (e: Exception) {
Log.warn("Failed to run command $cmd: ${e.message}")
throw CommandExecutionException("Failed to run command $cmd: ${e.message}")
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/ai/devchat/idea/DevChatSetupThread.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class DevChatSetupThread(private val project: Project) : Thread() {
val envManager = PythonEnvManager(workPath)
val devChatEnv = envManager.createEnv("devchat", "3.11.4")
devChatEnv.installPackage("devchat", "0.2.10")
DevChatWrapper().run(mutableListOf("update-sys" to null), null)
try {
DevChatWrapper().run(mutableListOf("update-sys" to null), null)
} catch (e: Exception) {
Log.warn("Failed to update-sys.")
}
listOf("sys", "org", "usr")
.map { "$workPath/workflows/$it/requirements.txt" }
.firstOrNull { File(it).exists() }
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/ai/devchat/idea/balloon/DevChatNotifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ object DevChatNotifier {
.notify(project)
}

fun stickyError(title: String, content: String) {
fun stickyError(content: String) {
val notification = Notification(
"stickyBalloon", title, content, NotificationType.ERROR
"stickyBalloon", "DevChat error", content, NotificationType.ERROR
)
Notifications.Bus.notify(notification)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<!-- Extension points defined by the plugin.
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
<extensions defaultExtensionNs="com.intellij">
<toolWindow id="DevChat" secondary="false" icon="AllIcons.Toolwindows.WebToolWindow" anchor="right"
<toolWindow id="DevChat" secondary="false" icon="/icons/pluginIcon_dark.svg" anchor="right"
factoryClass="ai.devchat.idea.DevChatToolWindow"/>
<applicationConfigurable parentId="tools" instance="ai.devchat.idea.settings.DevChatSettingsConfigurable"
id="org.intellij.sdk.settings.AppSettingsConfigurable"
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/icons/pluginIcon_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 72297dc

Please sign in to comment.