Skip to content

Async and Faster Folding Calculation #331

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

Open
wants to merge 38 commits into
base: feat/code-folding
Choose a base branch
from

Conversation

thecoolwinter
Copy link
Collaborator

@thecoolwinter thecoolwinter commented Jun 3, 2025

Description

Updates line folding to happen asynchronously off the main thread, and to work while editing text. It now remembers folded ranges and correctly handles nested folds.

Sorry for this huge commit log, it's terrible! Thankfully it'll be squashed when merged.

The meat of the changes here are in LineFoldCalculator, LineFoldModel, and LineFoldStorage. I've moved some files, resulting in the large diff and I'm sorry for that for reviewers I know that makes it hard.

  • Refactors the folding model to use a new LineFoldCalculator type.
    • This type accepts an async stream of edit notifications, and produces a stream of the new LineFoldStorage type.
    • Asynchronously accesses text on the main thread for safety.
  • Adds a new LineFoldStorage type.
    • Internally uses the RangeStore type to quickly store fold ranges as spans in a text document.
    • Has methods for querying text ranges, collapsing ranges, and updating using new values from the LineFoldCalculator stream.
    • Is Sendable to work easily with async streams.
  • Updates the drawing code to handle new behaviors of the fold model.

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

Screen.Recording.2025-06-03.at.10.46.47.AM.mov

thecoolwinter and others added 30 commits May 8, 2025 09:29
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.

2 participants