Skip to content

Comments

fix(language_server): Replace invalid LSP_MAX_INT ranges with zero ranges#13992

Closed
Boshen wants to merge 1 commit intomainfrom
fix/lsp-invalid-range
Closed

fix(language_server): Replace invalid LSP_MAX_INT ranges with zero ranges#13992
Boshen wants to merge 1 commit intomainfrom
fix/lsp-invalid-range

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Sep 22, 2025

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

  • Changed the fallback range from LSP_MAX_INT to (0, 0) when no span information is available
  • Removed unused LSP_MAX_INT constant
  • Updated test snapshot to reflect the new valid range behavior

Test Plan

  • All existing tests pass
  • Updated snapshot test confirms the fix works correctly
  • The fix uses a zero range (0, 0) which is a standard practice for diagnostics without specific location information

Fixes oxc-project/coc-oxc#50

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings September 22, 2025 05:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_INT fallback ranges with valid zero ranges (0, 0)
  • Remove the unused LSP_MAX_INT constant from the codebase
  • Update range comparison logic to use u32::MAX for 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.

@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 22, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-editor Area - Editor and Language Server C-bug Category - Bug labels Sep 22, 2025
@Boshen
Copy link
Member Author

Boshen commented Sep 22, 2025

@Sysix not entirely sure if this is the right fix, or should we filter out these invalid spans

Comment on lines +81 to +82
start: Position { line: u32::MAX, character: u32::MAX },
end: Position { line: u32::MAX, character: u32::MAX },
Copy link
Contributor

Choose a reason for hiding this comment

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

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 as None
  • 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.

Suggested change
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

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Copy link
Member

Choose a reason for hiding this comment

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

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-hq
Copy link

codspeed-hq bot commented Sep 22, 2025

CodSpeed Instrumentation Performance Report

Merging #13992 will not alter performance

Comparing fix/lsp-invalid-range (8e72e2a) with main (3ce0775)

Summary

✅ 37 untouched

Copy link
Member

@Sysix Sysix left a comment

Choose a reason for hiding this comment

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

I do not think the server is in fault of the nvim error.
I am fine to set everything to 0, but u32::MAX is not a valid integer in LSP.

Would close it in favor of #14010

Comment on lines +81 to +82
start: Position { line: u32::MAX, character: u32::MAX },
end: Position { line: u32::MAX, character: u32::MAX },
Copy link
Member

Choose a reason for hiding this comment

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

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

@Sysix
Copy link
Member

Sysix commented Sep 23, 2025

next part is here: #14057

@Sysix Sysix closed this Sep 23, 2025
@Boshen Boshen deleted the fix/lsp-invalid-range branch September 26, 2025 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-editor Area - Editor and Language Server C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: Range#create called with invalid arguments

2 participants