@@ -2,13 +2,16 @@ package cc.unitmesh.devti.gui.chat
2
2
3
3
import cc.unitmesh.devti.AutoDevBundle
4
4
import cc.unitmesh.devti.AutoDevIcons
5
+ import cc.unitmesh.devti.counit.configurable.customRagSettings
6
+ import cc.unitmesh.devti.counit.model.CustomRagApp
5
7
import cc.unitmesh.devti.llms.tokenizer.Tokenizer
6
8
import cc.unitmesh.devti.llms.tokenizer.TokenizerImpl
7
9
import cc.unitmesh.devti.settings.AutoDevSettingsState
8
10
import com.intellij.openapi.Disposable
9
11
import com.intellij.openapi.actionSystem.AnActionEvent
10
12
import com.intellij.openapi.actionSystem.Presentation
11
13
import com.intellij.openapi.actionSystem.impl.ActionButton
14
+ import com.intellij.openapi.diagnostic.logger
12
15
import com.intellij.openapi.editor.event.DocumentEvent
13
16
import com.intellij.openapi.editor.event.DocumentListener
14
17
import com.intellij.openapi.editor.ex.EditorEx
@@ -20,13 +23,19 @@ import com.intellij.openapi.ui.ValidationInfo
20
23
import com.intellij.openapi.wm.IdeFocusManager
21
24
import com.intellij.openapi.wm.impl.InternalDecorator
22
25
import com.intellij.temporary.gui.block.AutoDevCoolBorder
26
+ import com.intellij.ui.CollectionComboBoxModel
23
27
import com.intellij.ui.JBColor
28
+ import com.intellij.ui.MutableCollectionComboBoxModel
29
+ import com.intellij.ui.SimpleListCellRenderer
30
+ import com.intellij.ui.components.JBLabel
24
31
import com.intellij.ui.content.ContentManager
25
32
import com.intellij.util.EventDispatcher
26
33
import com.intellij.util.ui.JBEmptyBorder
27
34
import com.intellij.util.ui.JBUI
28
35
import com.intellij.util.ui.UIUtil
29
36
import com.intellij.util.ui.components.BorderLayoutPanel
37
+ import kotlinx.serialization.json.Json
38
+ import kotlinx.serialization.decodeFromString
30
39
import java.awt.Color
31
40
import java.awt.Component
32
41
import java.awt.Dimension
@@ -46,7 +55,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
46
55
private val documentListener: DocumentListener
47
56
private val buttonPresentation: Presentation
48
57
private val button: ActionButton
49
- private val customRag: ComboBox <String >
58
+ private val customRag: ComboBox <CustomRagApp >
59
+ private val logger = logger<AutoDevInputSection >()
50
60
51
61
val editorListeners: EventDispatcher <AutoDevInputListener > =
52
62
EventDispatcher .create(AutoDevInputListener ::class .java)
@@ -93,7 +103,6 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
93
103
input.border = JBEmptyBorder (4 )
94
104
95
105
addToCenter(input)
96
-
97
106
val layoutPanel = BorderLayoutPanel ()
98
107
val horizontalGlue = Box .createHorizontalGlue()
99
108
horizontalGlue.addMouseListener(object : MouseAdapter () {
@@ -107,9 +116,12 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
107
116
JBColor (3684930 , 3750720 )
108
117
)
109
118
layoutPanel.setOpaque(false )
110
- customRag = ComboBox (arrayOf(" Normal" )).also {
111
- // todo: load from json config
112
- }
119
+ customRag = ComboBox (MutableCollectionComboBoxModel (loadRagApps()))
120
+ customRag.setRenderer(SimpleListCellRenderer .create { label: JBLabel , value: CustomRagApp ? , _: Int ->
121
+ if (value != null ) {
122
+ label.text = value.name
123
+ }
124
+ })
113
125
114
126
layoutPanel.addToLeft(customRag)
115
127
layoutPanel.addToCenter(horizontalGlue)
@@ -131,6 +143,19 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
131
143
tokenizer = TokenizerImpl .INSTANCE
132
144
}
133
145
146
+ private fun loadRagApps (): List <CustomRagApp > {
147
+ val ragsJsonConfig = project.customRagSettings.ragsJsonConfig
148
+ val rags = try {
149
+ Json .decodeFromString<List <CustomRagApp >>(ragsJsonConfig)
150
+ } catch (e: Exception ) {
151
+ logger.warn(" Failed to parse custom rag apps" , e)
152
+ listOf ()
153
+ }
154
+
155
+ val firstRag = CustomRagApp (" Normal" , " Normal" )
156
+ return listOf (firstRag) + rags
157
+ }
158
+
134
159
fun initEditor () {
135
160
val editorEx = when (this .input.editor) {
136
161
is EditorEx -> this .input.editor
0 commit comments