Repository navigation
fix: limit LSP diagnostics to prevent context window waste - #5480
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds limits to LSP diagnostics returned after file writes and edits to prevent context window overflow when projects have many errors. The implementation sorts diagnostics by severity (errors first) and truncates the output with a clear indication of how many additional diagnostics exist.
- Adds configurable constants for limiting diagnostics per file (10) and project-wide files (5 in write tool)
- Implements sorting by severity with errors prioritized
- Adds "... and N more" suffix when diagnostics are truncated
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/opencode/src/tool/write.ts | Adds MAX_DIAGNOSTICS_PER_FILE and MAX_PROJECT_DIAGNOSTICS_FILES constants; implements sorting and limiting for both file-specific and project-wide diagnostics with truncation messages |
| packages/opencode/src/tool/edit.ts | Adds MAX_DIAGNOSTICS_PER_FILE constant; replaces severity filtering (errors-only) with sorting and limiting that includes all diagnostic severities |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
/review |
Contributor
|
lgtm |
nalin-singh
pushed a commit
to nalin-singh/opencode
that referenced
this pull request
Dec 17, 2025
…#5480) Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
rekram1-node
added a commit
that referenced
this pull request
Dec 27, 2025
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Rwanbt
pushed a commit
to Rwanbt/unifia
that referenced
this pull request
May 5, 2026
…#5480) Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
AIALRA-0
pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
…#5480) Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Rwanbt
pushed a commit
to Rwanbt/unifia
that referenced
this pull request
Jun 14, 2026
…#5480) Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
MarsQiu007
referenced
this pull request
in MarsQiu007/openNovel
Jul 31, 2026
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
meSingh
pushed a commit
to meSingh/opencode
that referenced
this pull request
Sep 6, 2026
…#5480) Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
androidand
pushed a commit
to androidand/opencode-skein
that referenced
this pull request
Sep 19, 2026
…#5480) Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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