opencode
opencode copied to clipboard
fix: limit LSP diagnostics to prevent context window waste
LSP diagnostics returned after file writes and edits were unbounded, which could easily fill up the context window when a project has many errors.
This adds limits:
- Max 10 diagnostics per file (sorted by severity - errors first)
- Max 5 files for project-wide diagnostics (in write tool)
- Shows "... and N more" suffix when truncated
Fixes #5259
I encountered this issue while working on a big codebase with many broken scripts. All the LSP issues were filling in the context. I even made a cli to investigate why just 1 file write was consuming so much context. The issue is that LSP diagnostics are unbounded. As you can see in the image a single file write was consuming 400k characters of context