Skip to content

Constrain Position offsets to the LSP uinteger type#5

Merged
christiankissig merged 1 commit into
masterfrom
add-range-format
Jun 3, 2026
Merged

Constrain Position offsets to the LSP uinteger type#5
christiankissig merged 1 commit into
masterfrom
add-range-format

Conversation

@christiankissig

Copy link
Copy Markdown
Owner

Summary

Implements Range/Position in the format mandated by LSP 3.17 — Range.

The spec types Position.line and Position.character as uinteger — a non-negative integer bounded to [0, 2^31 - 1] — not a signed int. The previous models used plain int, which silently accepted negative offsets.

Changes

  • Add a uinteger type alias (Annotated[int, Field(ge=0, le=2147483647)]) per the spec's base type.
  • Apply it to Position.line / Position.character, so negative or out-of-range offsets are rejected at validation time.
  • Add spec-accurate docstrings to Position and Range (zero-based offsets, exclusive end, empty range = single position, encoding-dependent character unit).

Testing

  • 9 new tests: zero/max boundaries accepted, negative line/character and above-max rejected, Range structure and nested-position validation.
  • poetry run pytest (46 passed), ruff check, ruff format --check, and mypy all clean.

🤖 Generated with Claude Code

Per the LSP 3.17 Range/Position spec, line and character offsets are
uinteger (non-negative, 0..2^31-1), not signed integers. Add a uinteger
type alias and apply it to Position so negative or out-of-range offsets
are rejected at validation time. Also document Position/Range per spec.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@christiankissig christiankissig merged commit 2b86427 into master Jun 3, 2026
7 checks passed
@christiankissig christiankissig deleted the add-range-format branch June 3, 2026 17:14
christiankissig added a commit that referenced this pull request Jul 7, 2026
Constrain Position offsets to the LSP uinteger type
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.

1 participant