Skip to content

Fix LSP panic on negative position coordinates - #10858

Open
JRI98 wants to merge 1 commit into
roc-lang:mainfrom
JRI98:fix-10854
Open

Fix LSP panic on negative position coordinates#10858
JRI98 wants to merge 1 commit into
roc-lang:mainfrom
JRI98:fix-10854

Conversation

@JRI98

@JRI98 JRI98 commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

LSP request handlers panicked when receiving negative line or character numbers in request position parameters due to unvalidated integer conversion to unsigned types.

This was addressed by validating incoming position line and character integers across LSP request handlers, returning an invalid parameters error or handling out-of-range values gracefully rather than crashing.

Fixes #10854

@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR prevents malformed LSP position coordinates from reaching unsigned position operations.

  • Uses checked u32 conversion in completion, definition, hover, document-highlight, and selection-range handlers.
  • Returns invalid_params for negative, oversized, missing, or mistyped coordinates instead of panicking or targeting document start.
  • Adds regression tests for negative coordinates across all affected handlers.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/lsp/handlers/document_highlight.zig Replaces fallback-to-zero parsing with explicit validation and checked coordinate conversion, fully addressing the prior finding.
src/lsp/handlers/selection_range.zig Validates every requested position and safely abandons accumulated results before returning one invalid-parameters response.
src/lsp/handlers/completion.zig Rejects coordinates outside the valid u32 range before document-position processing.
src/lsp/handlers/definition.zig Uses checked coordinate conversion and returns an invalid-parameters response on conversion failure.
src/lsp/handlers/hover.zig Uses checked coordinate conversion to prevent negative or oversized values from reaching lookup logic.
src/lsp/test/handler_unit_tests.zig Adds regression coverage confirming negative coordinates produce invalid-parameters errors without panicking.

Reviews (2): Last reviewed commit: "Fix LSP panic on negative position coord..." | Re-trigger Greptile

Comment thread src/lsp/handlers/document_highlight.zig Outdated
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 panic: integer does not fit in destination type

1 participant