feat(lsp): return optional from PositionMapper boundary methods#82
feat(lsp): return optional from PositionMapper boundary methods#8216bit-ykiko merged 1 commit intomainfrom
Conversation
to_position and to_offset receive untrusted LSP client input that may be out of range. Return std::optional instead of asserting so callers can handle invalid positions gracefully. Internal helpers keep their asserts since they operate on already-validated data. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/ipc/lsp/position.cpp (1)
244-246: Defensive check appears unreachable but harmless.Given the guard at line 239 (
offset > content.size()), anyoffset <= content.size()will always satisfyline_start(line) + column <= line_end_exclusive(line)sincecolumn = offset - line_start(line)andoffsetcannot exceed the line's valid range when within content bounds.This check is dead code but serves as a defensive safety net. Consider removing it for clarity, or adding a comment explaining it guards against future invariant breakage.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/ipc/lsp/position.cpp` around lines 244 - 246, The extra guard `if(line_start(line) + column > line_end_exclusive(line))` is unreachable given the prior `offset > content.size()` check but exists as a defensive safety net; update the `position.cpp` logic around the function that computes position from `offset` (referencing `line_start(line)`, `line_end_exclusive(line)`, `column`, and `offset`) by either removing the dead check or, preferably, keeping it and adding a concise comment clarifying it is a defensive invariant check to protect against future invariant breakage or corrupted input, so readers know why the seemingly unreachable branch remains.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/ipc/lsp/position.cpp`:
- Around line 244-246: The extra guard `if(line_start(line) + column >
line_end_exclusive(line))` is unreachable given the prior `offset >
content.size()` check but exists as a defensive safety net; update the
`position.cpp` logic around the function that computes position from `offset`
(referencing `line_start(line)`, `line_end_exclusive(line)`, `column`, and
`offset`) by either removing the dead check or, preferably, keeping it and
adding a concise comment clarifying it is a defensive invariant check to protect
against future invariant breakage or corrupted input, so readers know why the
seemingly unreachable branch remains.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 19d63e47-4489-4ab0-b7a2-c9f36acdd99c
📒 Files selected for processing (3)
include/eventide/ipc/lsp/position.hsrc/ipc/lsp/position.cpptests/unit/ipc/lsp/position_tests.cpp
Summary
to_positionandto_offsetnow returnstd::optionalinstead of asserting on out-of-range input, since they receive untrusted LSP client inputline_of,line_start, etc.) keep their asserts — validation at the trust boundary, not everywhere[[unlikely]]on all nullopt return pathsTest plan
language_positiontests pass🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests