Skip to content

fix: filter LSP diagnostics by client root#16365

Closed
dotuananh0712 wants to merge 2 commits intoanomalyco:devfrom
dotuananh0712:fix/16353-lsp-diagnostics-leak
Closed

fix: filter LSP diagnostics by client root#16365
dotuananh0712 wants to merge 2 commits intoanomalyco:devfrom
dotuananh0712:fix/16353-lsp-diagnostics-leak

Conversation

@dotuananh0712
Copy link

@dotuananh0712 dotuananh0712 commented Mar 6, 2026

Issue for this PR

Closes #16353

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes issue #16353 where LSP diagnostics from external projects leak into tool results and context window.

In packages/opencode/src/lsp/index.ts, the diagnostics() function now filters diagnostics to only include files within each LSP client's workspace root (client.root).

This prevents:

  1. Context window pollution in write.ts (which appends up to 5 "other files" diagnostics)
  2. metadata.diagnostics pollution in write, edit, and apply_patch tools

The original code aggregated diagnostics from ALL active LSP clients without filtering by workspace path. When TypeScript language server follows imports across project boundaries, diagnostics from external projects would leak into the current project's results.

How did you verify my code works?

  • Built locally to verify TypeScript compilation

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Fixes issue anomalyco#16353 where diagnostics from external projects leak into
tool results and context window. Only include diagnostics for files
within each LSP client's workspace root.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 6, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

The following comment was made by an LLM, it may be inaccurate:

Potential related PR found:

However, this appears to be an older related PR addressing different issues rather than a true duplicate.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 6, 2026
@github-actions github-actions bot closed this Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LSP diagnostics from external projects leak into tool results and context window

1 participant