Skip to content

Commit dd38fb8

Browse files
committed
refactor(lint): consolidate inspection error handling
- Removed `PsiErrorCollector` and `PsiSyntaxCheckingVisitor` as they are no longer needed. - Introduced `SketchInspectionError` in a separate file to centralize error handling logic. - Cleaned up and reorganized related code in `SketchCodeInspection` for better readability.
1 parent 6f61f81 commit dd38fb8

File tree

4 files changed

+32
-151
lines changed

4 files changed

+32
-151
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/lint/PsiErrorCollector.kt

Lines changed: 0 additions & 112 deletions
This file was deleted.

core/src/main/kotlin/cc/unitmesh/devti/sketch/lint/PsiSyntaxCheckingVisitor.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

core/src/main/kotlin/cc/unitmesh/devti/sketch/lint/SketchCodeInspection.kt

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator
66
import com.intellij.codeInspection.InspectionEngine
77
import com.intellij.codeInspection.InspectionManager
88
import com.intellij.codeInspection.ProblemDescriptor
9-
import com.intellij.codeInspection.ProblemHighlightType
109
import com.intellij.codeInspection.ex.GlobalInspectionContextBase
1110
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper
1211
import com.intellij.lang.annotation.HighlightSeverity
@@ -32,22 +31,6 @@ import javax.swing.JPanel
3231
import javax.swing.JTable
3332
import javax.swing.table.DefaultTableModel
3433

35-
data class SketchInspectionError(
36-
val lineNumber: Int,
37-
val description: String,
38-
val highlightType: ProblemHighlightType,
39-
) {
40-
companion object {
41-
fun from(problemDescriptor: ProblemDescriptor): SketchInspectionError {
42-
return SketchInspectionError(
43-
problemDescriptor.lineNumber,
44-
problemDescriptor.descriptionTemplate,
45-
problemDescriptor.highlightType
46-
)
47-
}
48-
}
49-
}
50-
5134
object SketchCodeInspection {
5235
fun showErrors(errors: List<SketchInspectionError>, panel: JPanel) {
5336
val columnNames = arrayOf("Line", "Description", "Highlight Type")
@@ -64,17 +47,19 @@ object SketchCodeInspection {
6447
val scrollPane = JBScrollPane(table).apply {
6548
preferredSize = Dimension(480, 400)
6649
}
50+
6751
val errorLabel = JBLabel(AutoDevBundle.message("sketch.lint.error", errors.size)).apply {
6852
border = BorderFactory.createEmptyBorder(5, 5, 5, 5)
53+
addMouseListener(object : MouseAdapter() {
54+
override fun mouseClicked(e: MouseEvent?) {
55+
createPopup(scrollPane, table, errors).showInCenterOf(panel)
56+
}
57+
58+
override fun mouseEntered(e: MouseEvent) {
59+
toolTipText = AutoDevBundle.message("sketch.lint.error.tooltip")
60+
}
61+
})
6962
}
70-
errorLabel.addMouseListener(object : MouseAdapter() {
71-
override fun mouseClicked(e: MouseEvent?) {
72-
createPopup(scrollPane, table, errors).showInCenterOf(panel)
73-
}
74-
override fun mouseEntered(e: MouseEvent) {
75-
errorLabel.toolTipText = AutoDevBundle.message("sketch.lint.error.tooltip")
76-
}
77-
})
7863

7964
val errorPanel = JPanel().apply {
8065
background = JBColor.WHITE
@@ -142,7 +127,8 @@ object SketchCodeInspection {
142127
it.initialize(globalContext)
143128
}
144129

145-
val toolsCopy: MutableList<LocalInspectionToolWrapper> = ArrayList<LocalInspectionToolWrapper>(toolWrappers.size)
130+
val toolsCopy: MutableList<LocalInspectionToolWrapper> =
131+
ArrayList<LocalInspectionToolWrapper>(toolWrappers.size)
146132
for (tool in toolWrappers) {
147133
if (tool is LocalInspectionToolWrapper) {
148134
toolsCopy.add(tool.createCopy())
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cc.unitmesh.devti.sketch.lint
2+
3+
import com.intellij.codeInspection.ProblemDescriptor
4+
import com.intellij.codeInspection.ProblemHighlightType
5+
6+
data class SketchInspectionError(
7+
val lineNumber: Int,
8+
val description: String,
9+
val highlightType: ProblemHighlightType,
10+
) {
11+
companion object {
12+
fun from(problemDescriptor: ProblemDescriptor): SketchInspectionError {
13+
return SketchInspectionError(
14+
problemDescriptor.lineNumber,
15+
problemDescriptor.descriptionTemplate,
16+
problemDescriptor.highlightType
17+
)
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)