Skip to content

Make styled range store generic #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

thecoolwinter
Copy link
Collaborator

@thecoolwinter thecoolwinter commented May 28, 2025

Description

This makes the StyledRangeStore type generic and Sendable. This type was originally created for storing relative ranges of highlight values (captures and modifiers). It excels at storing values for subranges of data even for large documents. I'm hoping to make this type a generic type we can use in other places in the package, like code folding, to store document state that needs to be maintained in lock-step with the document's real contents.

Detailed changes:

  • Renamed StyledRangeStore to RangeStore, as well as all associated types.
  • Made RangeStore a value type (struct) with copy-on-write semantics, allowing for it to be concurrency safe and Sendable.

    This doesn't have any effect on performance with the existing highlighter code. The highlighter code modifies the storage objects it uses in-place, so there is no copying necessary, only mutating.

  • Made RangeStore store a new, generic, RangeStoreElement type.
  • Updated StyledRangeContainer to use the updated RangeStore, with a custom element type that stores captures and modifiers.
  • Updated StyledRangeContainer to use a raised version of the combineLower[Higher]Priority methods only where they're relevant (instead of the requirement being on RangeStoreElement).
  • Updated relevant tests.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

No behavior changes. This is in prep for #43, but also lays the groundwork for other features using a type like this.

Copy link
Member

@tom-ludwig tom-ludwig left a comment

Choose a reason for hiding this comment

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

Looks great!
Generally, I try to avoid using Self for readability reasons, but since it’s already present in the existing files, it’s fine here.

@thecoolwinter thecoolwinter merged commit deaca0e into CodeEditApp:main May 30, 2025
2 checks passed
@thecoolwinter thecoolwinter deleted the make-styled-range-store-generic branch May 30, 2025 16:12
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.

4 participants