Skip to content

Commit 13eba06

Browse files
committed
fix(devti): handle exception in diff panel creation and update planner icon
- Add exception handling when creating diff panels to prevent crashes - Update planner icon size from 13x16 to 11x13 pixels
1 parent a00b9f8 commit 13eba06

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/AutoDevInputSection.kt

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,14 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
191191
setupEditorListener()
192192
setupRelatedListener()
193193

194-
/// get current open file and add to the list
195194
val currentFile = FileEditorManager.getInstance(project).selectedFiles.firstOrNull()
196195
currentFile?.let {
197196
listModel.addIfAbsent(currentFile, first = true)
197+
val index = listModel.indexOf(currentFile)
198+
if (index != -1) {
199+
listModel.remove(index)
200+
listModel.insertElementAt(listModel.getElementAt(index), 0)
201+
}
198202
}
199203
}
200204

@@ -231,45 +235,48 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
231235

232236
elementsList.addMouseListener(object : MouseAdapter() {
233237
override fun mouseClicked(e: MouseEvent) {
234-
val list = e.source as JBList<*>
235-
val index = list.locationToIndex(e.point)
236-
if (index == -1) return
237-
238-
val wrapper = listModel.getElementAt(index)
239-
val cellBounds = list.getCellBounds(index, index)
240-
wrapper.panel?.components?.firstOrNull { it.contains(e.x - cellBounds.x - it.x, it.height - 1) }
241-
?.let { component ->
242-
when {
243-
component is JPanel -> {
244-
listModel.removeElement(wrapper)
245-
val vfile = wrapper.virtualFile
246-
val relativePath = vfile.path.substringAfter(project.basePath!!).removePrefix("/")
247-
listModel.addIfAbsent(vfile)
248-
249-
input.appendText("\n/" + "file" + ":${relativePath}")
250-
listModel.indexOf(wrapper.virtualFile).takeIf { it != -1 }
251-
?.let { listModel.remove(it) }
252-
253-
// invoake later
254-
ApplicationManager.getApplication().invokeLater {
255-
val psiFile = PsiManager.getInstance(project).findFile(vfile) ?: return@invokeLater
256-
val relatedElements =
257-
RelatedClassesProvider.provide(psiFile.language)?.lookupIO(psiFile)
258-
updateElements(relatedElements)
259-
}
260-
}
261-
262-
component is JLabel && component.icon == AllIcons.Actions.Close -> listModel.removeElement(
263-
wrapper
264-
)
265-
266-
else -> list.clearSelection()
267-
}
268-
} ?: list.clearSelection()
238+
calculateRelativeFile(e)
269239
}
270240
})
271241
}
272242

243+
private fun calculateRelativeFile(e: MouseEvent) {
244+
val list = e.source as JBList<*>
245+
val index = list.locationToIndex(e.point)
246+
if (index == -1) return
247+
248+
val wrapper = listModel.getElementAt(index)
249+
val cellBounds = list.getCellBounds(index, index)
250+
wrapper.panel?.components?.firstOrNull { it.contains(e.x - cellBounds.x - it.x, it.height - 1) }
251+
?.let { component ->
252+
when {
253+
component is JPanel -> {
254+
listModel.removeElement(wrapper)
255+
val vfile = wrapper.virtualFile
256+
val relativePath = vfile.path.substringAfter(project.basePath!!).removePrefix("/")
257+
listModel.addIfAbsent(vfile)
258+
259+
input.appendText("\n/" + "file" + ":${relativePath}")
260+
listModel.indexOf(wrapper.virtualFile).takeIf { it != -1 }
261+
?.let { listModel.remove(it) }
262+
263+
ApplicationManager.getApplication().invokeLater {
264+
val psiFile = PsiManager.getInstance(project).findFile(vfile) ?: return@invokeLater
265+
val relatedElements =
266+
RelatedClassesProvider.provide(psiFile.language)?.lookupIO(psiFile)
267+
updateElements(relatedElements)
268+
}
269+
}
270+
271+
component is JLabel && component.icon == AllIcons.Actions.Close -> listModel.removeElement(
272+
wrapper
273+
)
274+
275+
else -> list.clearSelection()
276+
}
277+
} ?: list.clearSelection()
278+
}
279+
273280
private fun updateElements(elements: List<PsiElement>?) {
274281
elements?.forEach { listModel.addIfAbsent(it.containingFile.virtualFile) }
275282
}

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchInputListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ open class SketchInputListener(
126126
}
127127

128128
fun stop() {
129-
TODO("Not yet implemented")
129+
130130
}
131131
}

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/PlanLangSketch.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import cc.unitmesh.devti.observer.plan.AgentTaskEntry
55
import cc.unitmesh.devti.observer.plan.MarkdownPlanParser
66
import cc.unitmesh.devti.observer.plan.TaskStatus
77
import cc.unitmesh.devti.sketch.ui.ExtensionLangSketch
8-
import com.intellij.lang.Language
98
import com.intellij.openapi.project.Project
109
import com.intellij.ui.components.JBPanel
1110
import com.intellij.ui.components.JBScrollPane
1211
import com.intellij.ui.components.panels.VerticalLayout
1312
import com.intellij.util.ui.JBUI
14-
import com.intellij.util.ui.UIUtil
1513
import java.awt.BorderLayout
1614
import java.awt.Dimension
1715
import javax.swing.JComponent

0 commit comments

Comments
 (0)