diff options
| author | JackNorris <[email protected]> | 2025-12-26 04:24:48 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-25 22:24:48 -0600 |
| commit | 46c7a41d5f9d1e40e31a81b00e4fcd422843c69e (patch) | |
| tree | b921c2790b9dc26571ba578e1316f8f172579819 | |
| parent | 7cc4b24ac2a57ab46e0dcbc3f1cb91d5f1c011be (diff) | |
| download | opencode-46c7a41d5f9d1e40e31a81b00e4fcd422843c69e.tar.gz opencode-46c7a41d5f9d1e40e31a81b00e4fcd422843c69e.zip | |
fix: only show diagnostics block when errors exist (#6175)
| -rw-r--r-- | packages/opencode/src/tool/edit.ts | 4 | ||||
| -rw-r--r-- | packages/opencode/src/tool/write.ts | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/packages/opencode/src/tool/edit.ts b/packages/opencode/src/tool/edit.ts index b49bd7abe..626799746 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.ts index 6b8fd3dd1..a0e87299a 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 = 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 |
