Skip to content

fix(lsp): gracefully handle panics#9555

Merged
ematipico merged 4 commits intomainfrom
fix/lsp-incorrect-ranges
Mar 20, 2026
Merged

fix(lsp): gracefully handle panics#9555
ematipico merged 4 commits intomainfrom
fix/lsp-incorrect-ranges

Conversation

@ematipico
Copy link
Member

Summary

Closes biomejs/biome-zed#188

We already handle the Result, however, the underlying function didn't emit any Err. Now we do.

Test Plan

Added three tests with the help of Claude Code.

Docs

@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2026

🦋 Changeset detected

Latest commit: 52c0663

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ematipico ematipico force-pushed the fix/lsp-incorrect-ranges branch from 70ce195 to 3a1cf3b Compare March 20, 2026 09:19
@github-actions github-actions bot added the A-LSP Area: language server protocol label Mar 20, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 62250f26-db6f-4187-ad82-1c11627841c8

📥 Commits

Reviewing files that changed from the base of the PR and between 0b6c607 and 52c0663.

📒 Files selected for processing (1)
  • .changeset/neat-oranges-open.md
✅ Files skipped from review due to trivial changes (1)
  • .changeset/neat-oranges-open.md

Walkthrough

Adds runtime validation to LSP range conversion to reject ranges whose computed start offset exceeds end offset, preventing panics. Adds unit and integration regression tests in the LSP converter and server to ensure inverted LSP ranges are ignored and do not mutate document text or crash the server.

Possibly related PRs

  • fix(lsp): changes file corruption #9528 — Reworks handling of incremental document edits and skips stale incremental edits; closely related to document-change handling and tests around ignoring problematic incremental edits.

Suggested reviewers

  • dyc3
  • siketyan
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(lsp): gracefully handle panics' accurately summarises the main change—preventing LSP panics by surfacing errors instead of allowing assertions to fail.
Description check ✅ Passed The description clearly relates to the changeset, explaining the motivation (issue #188), the fix (function now returns Err), and test coverage added.
Linked Issues check ✅ Passed The PR fully addresses issue #188's objective: it prevents runtime panics by returning errors instead of allowing assertions to fail in LSP range handling code.
Out of Scope Changes check ✅ Passed All changes are scoped to the LSP panic fix: validation logic added to range conversion, comprehensive regression tests added, and a changeset entry documented.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/lsp-incorrect-ranges
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/neat-oranges-open.md:
- Line 5: Rewrite the changeset sentence to follow the bug-fix format and fix
typos: change "Fixed a bug where the Biome Langauge Server would suddenly panic
when open files suddenly changes." to start with the required prefix "Fixed
[`#NUMBER`](issue link):" and correct spelling/grammar (e.g., "Fixed
[`#NUMBER`](issue link): Fixed a bug where the Biome Language Server would panic
when open files suddenly change (for example, when switching Git branches)."),
replacing [`#NUMBER`](issue link) with the actual issue reference.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: eadc73e6-e958-4b68-9a66-7016ba3539c4

📥 Commits

Reviewing files that changed from the base of the PR and between d4e3d6e and 3a1cf3b.

📒 Files selected for processing (5)
  • .changeset/neat-oranges-open.md
  • crates/biome_lsp/src/server.tests.rs
  • crates/biome_lsp/src/utils.rs
  • crates/biome_lsp_converters/src/from_proto.rs
  • crates/biome_lsp_converters/src/lib.rs

autofix-ci bot and others added 2 commits March 20, 2026 09:28
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@ematipico ematipico requested review from a team March 20, 2026 09:45
) -> Result<TextRange> {
let start = offset(line_index, range.start, position_encoding)?;
let end = offset(line_index, range.end, position_encoding)?;
anyhow::ensure!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, TIL :)

@ematipico ematipico merged commit 8a3647b into main Mar 20, 2026
13 checks passed
@ematipico ematipico deleted the fix/lsp-incorrect-ranges branch March 20, 2026 10:41
@github-actions github-actions bot mentioned this pull request Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LSP Area: language server protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Biome randomly crashing

2 participants