Przeglądaj źródła

fix: only show diagnostics block when errors exist (#6175)

JackNorris 1 miesiąc temu
rodzic
commit
46c7a41d5f

+ 2 - 2
packages/opencode/src/tool/edit.ts

@@ -142,8 +142,8 @@ export const EditTool = Tool.define("edit", {
     const diagnostics = await LSP.diagnostics()
     const normalizedFilePath = Filesystem.normalizePath(filePath)
     const issues = diagnostics[normalizedFilePath] ?? []
-    if (issues.length > 0) {
-      const errors = issues.filter((item) => item.severity === 1)
+    const errors = issues.filter((item) => item.severity === 1)
+    if (errors.length > 0) {
       const limited = errors.slice(0, MAX_DIAGNOSTICS_PER_FILE)
       const suffix =
         errors.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${errors.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""

+ 4 - 4
packages/opencode/src/tool/write.ts

@@ -83,11 +83,11 @@ export const WriteTool = Tool.define("write", {
     const normalizedFilepath = Filesystem.normalizePath(filepath)
     let projectDiagnosticsCount = 0
     for (const [file, issues] of Object.entries(diagnostics)) {
-      if (issues.length === 0) continue
-      const sorted = issues.toSorted((a, b) => (a.severity ?? 4) - (b.severity ?? 4))
-      const limited = sorted.slice(0, MAX_DIAGNOSTICS_PER_FILE)
+      const errors = issues.filter((item) => item.severity === 1)
+      if (errors.length === 0) continue
+      const limited = errors.slice(0, MAX_DIAGNOSTICS_PER_FILE)
       const suffix =
-        issues.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${issues.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""
+        errors.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${errors.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""
       if (file === normalizedFilepath) {
         output += `\nThis file has errors, please fix\n<file_diagnostics>\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</file_diagnostics>\n`
         continue