Skip to content

Commit 46c7a41

Browse files
authored
fix: only show diagnostics block when errors exist (anomalyco#6175)
1 parent 7cc4b24 commit 46c7a41

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

packages/opencode/src/tool/edit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ export const EditTool = Tool.define("edit", {
142142
const diagnostics = await LSP.diagnostics()
143143
const normalizedFilePath = Filesystem.normalizePath(filePath)
144144
const issues = diagnostics[normalizedFilePath] ?? []
145-
if (issues.length > 0) {
146-
const errors = issues.filter((item) => item.severity === 1)
145+
const errors = issues.filter((item) => item.severity === 1)
146+
if (errors.length > 0) {
147147
const limited = errors.slice(0, MAX_DIAGNOSTICS_PER_FILE)
148148
const suffix =
149149
errors.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${errors.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""

packages/opencode/src/tool/write.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ export const WriteTool = Tool.define("write", {
8383
const normalizedFilepath = Filesystem.normalizePath(filepath)
8484
let projectDiagnosticsCount = 0
8585
for (const [file, issues] of Object.entries(diagnostics)) {
86-
if (issues.length === 0) continue
87-
const sorted = issues.toSorted((a, b) => (a.severity ?? 4) - (b.severity ?? 4))
88-
const limited = sorted.slice(0, MAX_DIAGNOSTICS_PER_FILE)
86+
const errors = issues.filter((item) => item.severity === 1)
87+
if (errors.length === 0) continue
88+
const limited = errors.slice(0, MAX_DIAGNOSTICS_PER_FILE)
8989
const suffix =
90-
issues.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${issues.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""
90+
errors.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${errors.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""
9191
if (file === normalizedFilepath) {
9292
output += `\nThis file has errors, please fix\n<file_diagnostics>\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</file_diagnostics>\n`
9393
continue

0 commit comments

Comments
 (0)