Skip to content

Commit bcbe6bc

Browse files
committed
feat(code): support multiple code blocks in CodeHighlightSketch #331
- Add example structure to plan.devin files for clarity - Refactor CodeHighlightSketch to handle multiple code blocks using VerticalLayout - Remove outdated TODO comment in AgentStateService
1 parent 1262136 commit bcbe6bc

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

core/src/main/kotlin/cc/unitmesh/devti/observer/agent/AgentStateService.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class AgentStateService {
3333
*/
3434
fun processMessages(messages: List<Message>): List<Message> {
3535
state.messages = messages
36-
/// todo compress message in here
3736
return messages
3837
}
3938

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/code/CodeHighlightSketch.kt

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ import com.intellij.openapi.util.text.StringUtil
3434
import com.intellij.openapi.vfs.VirtualFile
3535
import com.intellij.psi.PsiManager
3636
import cc.unitmesh.devti.util.whenDisposed
37+
import com.intellij.openapi.ui.VerticalFlowLayout
3738
import com.intellij.testFramework.LightVirtualFile
3839
import com.intellij.ui.components.JBPanel
40+
import com.intellij.ui.components.panels.VerticalLayout
3941
import com.intellij.util.concurrency.annotations.RequiresReadLock
4042
import com.intellij.util.ui.JBEmptyBorder
4143
import com.intellij.util.ui.JBUI
@@ -162,32 +164,38 @@ open class CodeHighlightSketch(
162164
}
163165
}
164166

165-
val parse = CodeFence.parse(editorFragment!!.editor.document.text)
166-
var panel: JComponent? = null
167-
when (parse.originLanguage) {
168-
"diff", "patch" -> {
169-
val langSketch = LanguageSketchProvider.provide("patch")?.create(project, parse.text) ?: return
170-
panel = langSketch.getComponent()
171-
langSketch.onDoneStream(allText)
172-
}
167+
val codes = CodeFence.parseAll(editorFragment!!.editor.document.text)
168+
val blockedPanel = JPanel(VerticalLayout(JBUI.scale(0)))
173169

174-
"html" -> {
175-
val langSketch = LanguageSketchProvider.provide("html")?.create(project, parse.text) ?: return
176-
panel = langSketch.getComponent()
177-
langSketch.onDoneStream(allText)
178-
}
170+
codes.forEach { code ->
171+
var panel: JComponent? = null
172+
when (code.originLanguage) {
173+
"diff", "patch" -> {
174+
val langSketch = LanguageSketchProvider.provide("patch")?.create(project, code.text) ?: return
175+
panel = langSketch.getComponent()
176+
langSketch.onDoneStream(allText)
177+
}
178+
179+
"html" -> {
180+
val langSketch = LanguageSketchProvider.provide("html")?.create(project, code.text) ?: return
181+
panel = langSketch.getComponent()
182+
langSketch.onDoneStream(allText)
183+
}
179184

180-
"bash", "shell" -> {
181-
val langSketch = LanguageSketchProvider.provide("shell")?.create(project, parse.text) ?: return
182-
panel = langSketch.getComponent()
183-
langSketch.onDoneStream(allText)
185+
"bash", "shell" -> {
186+
val langSketch = LanguageSketchProvider.provide("shell")?.create(project, code.text) ?: return
187+
panel = langSketch.getComponent()
188+
langSketch.onDoneStream(allText)
189+
}
184190
}
185-
}
186191

187-
if (panel == null) return
192+
if (panel == null) return@forEach
193+
194+
panel.border = JBEmptyBorder(4)
195+
blockedPanel.add(panel)
196+
}
188197

189-
panel.border = JBEmptyBorder(4)
190-
add(panel, BorderLayout.SOUTH)
198+
add(blockedPanel, BorderLayout.SOUTH)
191199

192200
editorFragment?.updateExpandCollapseLabel()
193201

core/src/main/resources/genius/en/code/plan.devin

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ Here is the rule you should follow:
5858
If `<user.question>` directly contradicts any of these steps, follow the instructions from `<user.question>`
5959
first. Be thorough in your thinking process, so it's okay if it is lengthy.
6060

61+
For example:
62+
63+
<THOUGHT>
64+
<PLAN>
65+
Some plan
66+
</PLAN>
67+
</THOUGHT>
68+
6169
Here is user.question:
6270

6371
<user.question>user.question</user.question>

core/src/main/resources/genius/zh/code/plan.devin

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ Here is the rule you should follow:
5858
If `<user.question>` directly contradicts any of these steps, follow the instructions from `<user.question>`
5959
first. Be thorough in your thinking process, so it's okay if it is lengthy.
6060

61+
For example:
62+
63+
<THOUGHT>
64+
<PLAN>
65+
Some plan
66+
</PLAN>
67+
</THOUGHT>
68+
6169
Here is user.question:
6270

6371
<user.question>user.question</user.question>

0 commit comments

Comments
 (0)