fix(language_server): Replace invalid LSP_MAX_INT ranges with zero ranges#13992
fix(language_server): Replace invalid LSP_MAX_INT ranges with zero ranges#13992
Conversation
…nges Fixes "Range#create called with invalid arguments" error in coc-oxc by replacing invalid diagnostic ranges that used LSP_MAX_INT (2147483647) with valid zero ranges (0, 0) when no span information is available. This is a standard practice for diagnostics without specific location information and ensures compatibility with LSP clients. Fixes oxc-project/coc-oxc#50 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an LSP protocol violation where invalid range values were causing diagnostic errors in editors. The language server was using LSP_MAX_INT (2147483647) as fallback positions for diagnostics without span information, which exceeded LSP specification limits.
- Replace invalid
LSP_MAX_INTfallback ranges with valid zero ranges(0, 0) - Remove the unused
LSP_MAX_INTconstant from the codebase - Update range comparison logic to use
u32::MAXfor internal comparisons while maintaining valid LSP output
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| main.rs | Removes the unused LSP_MAX_INT constant definition |
| error_with_position.rs | Updates fallback range logic to use zero ranges and fixes comparison initialization |
| debugger.ts.snap | Updates test snapshot to reflect the new valid zero range behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
|
@Sysix not entirely sure if this is the right fix, or should we filter out these invalid spans |
| start: Position { line: u32::MAX, character: u32::MAX }, | ||
| end: Position { line: u32::MAX, character: u32::MAX }, |
There was a problem hiding this comment.
The use of u32::MAX (4294967295) here is inconsistent with the PR's approach of using (0, 0) for invalid ranges. While this works for comparison purposes, u32::MAX still exceeds the LSP specification's maximum value (2^31 - 1).
Consider an alternative approach for the initial comparison:
- Use an
Option<Range>that starts asNone - Use a boolean flag to track if a valid range has been found
- Or initialize with the first range found, then compare subsequent ranges
This would maintain consistency with the PR's goal of eliminating invalid range values throughout the codebase.
| start: Position { line: u32::MAX, character: u32::MAX }, | |
| end: Position { line: u32::MAX, character: u32::MAX }, | |
| start: Position { line: 0, character: 0 }, | |
| end: Position { line: 0, character: 0 }, |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Yes! IntelliJ expects to be in a valid LSP Range and will fail. We had it on u32::MAX and needed to change it for IntelliJ integration
CodSpeed Instrumentation Performance ReportMerging #13992 will not alter performanceComparing Summary
|
| start: Position { line: u32::MAX, character: u32::MAX }, | ||
| end: Position { line: u32::MAX, character: u32::MAX }, |
There was a problem hiding this comment.
Yes! IntelliJ expects to be in a valid LSP Range and will fail. We had it on u32::MAX and needed to change it for IntelliJ integration
|
next part is here: #14057 |
Summary
Fixes "Range#create called with invalid arguments" error reported in oxc-project/coc-oxc#50
When diagnostics had no related span information, the language server was using
LSP_MAX_INT(2147483647) as a fallback position, which is invalid for LSP ranges and caused editors to reject the diagnostic.Changes
LSP_MAX_INTto(0, 0)when no span information is availableLSP_MAX_INTconstantTest Plan
(0, 0)which is a standard practice for diagnostics without specific location informationFixes oxc-project/coc-oxc#50
🤖 Generated with Claude Code