Skip to content

Commit b900633

Browse files
committed
feat(custom-actions): improve logging and error handling in CustomActionBaseIntention and CustomAgentChatProcessor. #51
1 parent be37693 commit b900633

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/main/kotlin/cc/unitmesh/devti/counit/CustomAgentChatProcessor.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class CustomAgentChatProcessor(val project: Project) {
5656
llmProvider.appendLocalMessage(result, ChatRole.Assistant)
5757
}
5858
}
59+
60+
ResponseAction.WebView -> TODO()
5961
}
6062
}
6163

src/main/kotlin/cc/unitmesh/devti/custom/CustomActionBaseIntention.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import cc.unitmesh.devti.gui.chat.ChatActionType
77
import cc.unitmesh.devti.gui.sendToChatPanel
88
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
99
import cc.unitmesh.devti.provider.ContextPrompter
10+
import com.intellij.openapi.diagnostic.logger
1011
import com.intellij.openapi.editor.Editor
1112
import com.intellij.openapi.project.Project
1213
import com.intellij.openapi.util.NlsSafe
@@ -19,6 +20,8 @@ import java.io.StringWriter
1920
class CustomActionBaseIntention(private val intentionConfig: CustomIntentionConfig) : ChatBaseIntention() {
2021
override fun getText(): String = intentionConfig.title
2122

23+
private val logger = logger<CustomActionBaseIntention>()
24+
2225
override fun getFamilyName(): String = "Custom Intention"
2326
override fun priority(): Int {
2427
return intentionConfig.priority
@@ -82,8 +85,18 @@ class CustomActionBaseIntention(private val intentionConfig: CustomIntentionConf
8285
velocityContext.put(variableType, value)
8386
}
8487

85-
Velocity.evaluate(velocityContext, stringBuilderWriter, "", intentionConfig.template)
86-
val output = stringBuilderWriter.toString()
88+
val oldContextClassLoader = Thread.currentThread().getContextClassLoader()
89+
Thread.currentThread().setContextClassLoader(CustomActionBaseIntention::class.java.getClassLoader())
90+
91+
val sw = StringWriter()
92+
try {
93+
Velocity.evaluate(velocityContext, sw, "#" + this.javaClass.name, intentionConfig.template)
94+
} catch (e: Exception) {
95+
logger.error("Failed to compile template: $intentionConfig", e)
96+
}
97+
98+
Thread.currentThread().setContextClassLoader(oldContextClassLoader)
99+
val output = sw.toString()
87100

88101
return CustomIntentionPrompt(output, output, listOf())
89102
}

0 commit comments

Comments
 (0)