The open source coding agent.
TypeScript
fix: only show diagnostics block when errors exist (#6175)
JackNorris46c7a41d5f9d
diff --git a/packages/opencode/src/tool/edit.ts b/packages/opencode/src/tool/edit.tsindex b49bd7abe00..62679974648 100644--- a/packages/opencode/src/tool/edit.ts+++ b/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` : ""diff --git a/packages/opencode/src/tool/write.ts b/packages/opencode/src/tool/write.tsindex 6b8fd3dd111..a0e87299a44 100644--- a/packages/opencode/src/tool/write.ts+++ b/packages/opencode/src/tool/write.ts@@ -83,11 +83,11 @@ export const WriteTool = Tool.define("write", {const normalizedFilepath = Filesystem.normalizePath(filepath)let projectDiagnosticsCount = 0for (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