Skip to content

Make TextDocument.lines be a Sequence[str] rather than List[str]#553

Merged
alcarney merged 1 commit into
openlawlibrary:mainfrom
nthykier:immutable-lines
Jun 20, 2025
Merged

Make TextDocument.lines be a Sequence[str] rather than List[str]#553
alcarney merged 1 commit into
openlawlibrary:mainfrom
nthykier:immutable-lines

Conversation

@nthykier

Copy link
Copy Markdown
Contributor

The PositionCodec does not need a mutable sequence as it only does read-only operations. Additionally, TextDocument.lines can now return an immutable list (using tuple here for simplicity), which will enable pygls to cache the lines attribute later internally.

The caching is not done in this commit as it would require us to figure out the cache invalidation rules, which will be after this has been accepted.

Description (e.g. "Related to ...", etc.)

See #551

Code review checklist (for code reviewer to complete)

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • Title summarizes what is changing
  • Commit messages are meaningful (see this for details)
  • Tests have been included and/or updated, as appropriate
  • Docstrings have been included and/or updated, as appropriate
  • Standalone docs have been updated accordingly

Automated linters

You can run the lints that are run on CI locally with:

poetry install --all-extras --with dev
poetry run poe lint

@nthykier nthykier force-pushed the immutable-lines branch 3 times, most recently from 2a9d0aa to e54c3da Compare June 18, 2025 18:24
The `PositionCodec` does not need a mutable sequence as it only does
read-only operations. Additionally, `TextDocument.lines` can now
return an immutable list (using tuple here for simplicity), which will
enable `pygls` to cache the `lines` attribute later internally.

The caching is not done in this commit as it would require us to
figure out the cache invalidation rules, which will be after this
has been accepted.
@nthykier nthykier marked this pull request as ready for review June 18, 2025 18:40
@tombh tombh requested a review from alcarney June 18, 2025 18:41
@tombh

tombh commented Jun 18, 2025

Copy link
Copy Markdown
Collaborator

This looks great. I've requested a review from Alex as well as he's done work on the types.

@alcarney alcarney left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great - thank you!

@alcarney alcarney merged commit e2de402 into openlawlibrary:main Jun 20, 2025
18 checks passed
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.

3 participants