Skip to content

Commit 72297dc

Browse files
authored
Merge pull request #33 from devchat-ai/bug-fix
Bug fix
2 parents f3ff7ab + 6241876 commit 72297dc

File tree

7 files changed

+31
-20
lines changed

7 files changed

+31
-20
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "ai.devchat"
9-
version = "0.0.2"
9+
version = "0.0.3"
1010

1111
repositories {
1212
mavenCentral()
@@ -56,4 +56,4 @@ tasks {
5656
}
5757
kotlin {
5858
jvmToolchain(17)
59-
}
59+
}

gui

src/main/kotlin/ai/devchat/cli/DevChatWrapper.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ class DevChatWrapper(
9393
private fun execCommandAsync(
9494
commands: List<String>,
9595
onOutput: (String) -> Unit,
96-
onError: (String) -> Unit = Log::error
96+
onError: (String) -> Unit = Log::warn
9797
): Job {
9898
Log.info("Executing command: ${commands.joinToString(" ")}}")
9999
val exceptionHandler = CoroutineExceptionHandler { _, exception ->
100100
Log.warn("Failed to execute command: $commands, Exception: $exception")
101-
throw CommandExecutionException("Failed to execute command: $commands, $exception")
101+
onError("DevChat failed to response the message.")
102102
}
103103
val cmdScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
104104

@@ -112,16 +112,17 @@ class DevChatWrapper(
112112

113113
val prompt: (MutableList<Pair<String, String?>>, String, ((String) -> Unit)?) -> Unit get() = {
114114
flags: MutableList<Pair<String, String?>>, message: String, callback: ((String) -> Unit)? ->
115-
if (apiKey.isNullOrEmpty()) {
116-
DevChatNotifier.stickyError("DevChat Error", "Please config your API key first.")
117-
} else if (!apiKey!!.startsWith("DC.")) {
118-
DevChatNotifier.stickyError("DevChat Error", "Invalid API key format.")
115+
when {
116+
apiKey.isNullOrEmpty() -> DevChatNotifier.stickyError("Please config your API key first.")
117+
!apiKey!!.startsWith("DC.") -> DevChatNotifier.stickyError("Invalid API key format.")
118+
else -> {
119+
flags
120+
.find { it.first == "model" && !it.second.isNullOrEmpty() }
121+
.alsoIfNull { flags.add("model" to defaultModel) }
122+
flags.add("" to message)
123+
subCommand(listOf("prompt"))(flags, callback)
124+
}
119125
}
120-
flags
121-
.find { it.first == "model" && !it.second.isNullOrEmpty() }
122-
.alsoIfNull { flags.add("model" to defaultModel) }
123-
flags.add("" to message)
124-
subCommand(listOf("prompt"))(flags, callback)
125126
}
126127

127128
val run get() = subCommand(listOf("run"))
@@ -166,7 +167,7 @@ class DevChatWrapper(
166167
cmd.addIfNotNull(value)
167168
}
168169
return try {
169-
callback?.let { execCommandAsync(cmd, callback); "" } ?: execCommand(cmd)
170+
callback?.let { execCommandAsync(cmd, callback, DevChatNotifier::stickyError); "" } ?: execCommand(cmd)
170171
} catch (e: Exception) {
171172
Log.warn("Failed to run command $cmd: ${e.message}")
172173
throw CommandExecutionException("Failed to run command $cmd, $e")
@@ -182,7 +183,7 @@ class DevChatWrapper(
182183
cmd.addIfNotNull(value)
183184
}
184185
try {
185-
callback?.let { execCommandAsync(cmd, callback); "" } ?: execCommand(cmd)
186+
callback?.let { execCommandAsync(cmd, callback, DevChatNotifier::stickyError); "" } ?: execCommand(cmd)
186187
} catch (e: Exception) {
187188
Log.warn("Failed to run command $cmd: ${e.message}")
188189
throw CommandExecutionException("Failed to run command $cmd: ${e.message}")

src/main/kotlin/ai/devchat/idea/DevChatSetupThread.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ class DevChatSetupThread(private val project: Project) : Thread() {
2020
val envManager = PythonEnvManager(workPath)
2121
val devChatEnv = envManager.createEnv("devchat", "3.11.4")
2222
devChatEnv.installPackage("devchat", "0.2.10")
23-
DevChatWrapper().run(mutableListOf("update-sys" to null), null)
23+
try {
24+
DevChatWrapper().run(mutableListOf("update-sys" to null), null)
25+
} catch (e: Exception) {
26+
Log.warn("Failed to update-sys.")
27+
}
2428
listOf("sys", "org", "usr")
2529
.map { "$workPath/workflows/$it/requirements.txt" }
2630
.firstOrNull { File(it).exists() }

src/main/kotlin/ai/devchat/idea/balloon/DevChatNotifier.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ object DevChatNotifier {
2424
.notify(project)
2525
}
2626

27-
fun stickyError(title: String, content: String) {
27+
fun stickyError(content: String) {
2828
val notification = Notification(
29-
"stickyBalloon", title, content, NotificationType.ERROR
29+
"stickyBalloon", "DevChat error", content, NotificationType.ERROR
3030
)
3131
Notifications.Bus.notify(notification)
3232
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<!-- Extension points defined by the plugin.
2929
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
3030
<extensions defaultExtensionNs="com.intellij">
31-
<toolWindow id="DevChat" secondary="false" icon="AllIcons.Toolwindows.WebToolWindow" anchor="right"
31+
<toolWindow id="DevChat" secondary="false" icon="/icons/pluginIcon_dark.svg" anchor="right"
3232
factoryClass="ai.devchat.idea.DevChatToolWindow"/>
3333
<applicationConfigurable parentId="tools" instance="ai.devchat.idea.settings.DevChatSettingsConfigurable"
3434
id="org.intellij.sdk.settings.AppSettingsConfigurable"
Lines changed: 6 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)