@@ -7,6 +7,7 @@ import cc.unitmesh.devti.gui.chat.ChatActionType
7
7
import cc.unitmesh.devti.gui.sendToChatPanel
8
8
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
9
9
import cc.unitmesh.devti.provider.ContextPrompter
10
+ import com.intellij.openapi.diagnostic.logger
10
11
import com.intellij.openapi.editor.Editor
11
12
import com.intellij.openapi.project.Project
12
13
import com.intellij.openapi.util.NlsSafe
@@ -19,6 +20,8 @@ import java.io.StringWriter
19
20
class CustomActionBaseIntention (private val intentionConfig : CustomIntentionConfig ) : ChatBaseIntention() {
20
21
override fun getText (): String = intentionConfig.title
21
22
23
+ private val logger = logger<CustomActionBaseIntention >()
24
+
22
25
override fun getFamilyName (): String = " Custom Intention"
23
26
override fun priority (): Int {
24
27
return intentionConfig.priority
@@ -82,8 +85,18 @@ class CustomActionBaseIntention(private val intentionConfig: CustomIntentionConf
82
85
velocityContext.put(variableType, value)
83
86
}
84
87
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()
87
100
88
101
return CustomIntentionPrompt (output, output, listOf ())
89
102
}
0 commit comments