Skip to content

Commit 825fc65

Browse files
committed
refactor(devins-lang): limit patch parse error notifications
- Introduce a mechanism to limit the number of error notifications for patch parsing - Add a time window and count threshold to avoid overwhelming users with repeated notifications - Remove direct logger warning for parse errors, opting instead for a more user-facing notification approach
1 parent 0fcbd97 commit 825fc65

File tree

1 file changed

+25
-4
lines changed
  • exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec

1 file changed

+25
-4
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/PatchInsCommand.kt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
77
import cc.unitmesh.devti.sketch.AutoSketchMode
88
import cc.unitmesh.devti.sketch.ui.patch.readText
99
import cc.unitmesh.devti.sketch.ui.patch.writeText
10-
import com.intellij.openapi.diagnostic.logger
1110
import com.intellij.openapi.diff.impl.patch.ApplyPatchStatus
1211
import com.intellij.openapi.diff.impl.patch.PatchReader
1312
import com.intellij.openapi.diff.impl.patch.TextFilePatch
@@ -18,13 +17,15 @@ import com.intellij.openapi.util.Disposer
1817

1918
class PatchInsCommand(val myProject: Project, val prop: String, val codeContent: String) : InsCommand {
2019
override val commandName: BuiltinCommand = BuiltinCommand.PATCH
21-
private val logger = logger<PatchInsCommand>()
2220

2321
override suspend fun execute(): String? {
2422
val filePatches = parsePatches(codeContent)
2523
if (filePatches == null) {
26-
logger.warn("Failed to parse patches from content: \n$codeContent")
27-
AutoDevNotifications.warn(myProject, "Failed to parse patches from content")
24+
val shouldShowNotification = shouldShowParseErrorNotification()
25+
if (shouldShowNotification) {
26+
AutoDevNotifications.warn(myProject, "Failed to parse patches from content")
27+
}
28+
2829
return "$DEVINS_ERROR: Failed to parse patches"
2930
}
3031

@@ -76,4 +77,24 @@ class PatchInsCommand(val myProject: Project, val prop: String, val codeContent:
7677
null
7778
}
7879
}
80+
81+
private fun shouldShowParseErrorNotification(): Boolean {
82+
val currentTime = System.currentTimeMillis()
83+
if (currentTime - lastErrorTime > ERROR_TIME_WINDOW_MS) {
84+
parseErrorCount = 0
85+
lastErrorTime = currentTime
86+
}
87+
88+
parseErrorCount++
89+
90+
return parseErrorCount <= MAX_ERRORS_IN_WINDOW
91+
}
92+
93+
companion object {
94+
private const val MAX_ERRORS_IN_WINDOW = 3
95+
// Time window in milliseconds (e.g., 60000ms = 1 minute)
96+
private const val ERROR_TIME_WINDOW_MS = 60000L
97+
private var parseErrorCount = 0
98+
private var lastErrorTime = 0L
99+
}
79100
}

0 commit comments

Comments
 (0)