Skip to content

Conversation

@romanstingler
Copy link

  • Background document stats
    Added cached DocumentStatistics plus async calculation in src/main.rs so the statistics drawer never blocks the UI thread.
  • State & messaging
    Extended App with document_stats, document_stats_dirty, document_stats_pending, document_stats_request_target, and document_stats_request_id, and introduced Message::DocumentStats to deliver background results.
  • Visibility-based scheduling
    Updated App::update_tab(), the Message::TabChanged handler, and Message::ToggleContextPage so stats are recomputed only when the Document Statistics drawer is open for the active editor tab.
  • UI rendering
    App::document_statistics() now renders cached values (or placeholders) without touching the editor buffer, avoiding main-thread work.

Method Details

  • request_document_statistics_if_needed()(src/main.rs)
    Checks whether the statistics drawer is visible, whether a job is already running, and whether cached stats are still valid.
    If a refresh is required, it snapshots the active editor tab’s lines, assigns a new request ID, records the pending state, clears the dirty flag, and uses Task::perform + tokio::task::spawn_blocking to compute counts off the UI thread.
  • calculate_document_statistics() (src/main.rs)
    Runs on the blocking thread, iterating through the provided lines to tally words, characters (with and without spaces), and lines. Returns a DocumentStatistics struct for the main thread to cache and display.

word_count: usize,
}

fn calculate_document_statistics(lines: Vec<String>) -> DocumentStatistics {
Copy link
Member

Choose a reason for hiding this comment

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

This should be borrowed since it doesn't need ownership, and that sounds like a very costly vec.

document_stats_pending: Option<u64>,
document_stats_request_target: Option<Entity>,
document_stats_dirty: bool,
document_stats_request_id: u64,
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this should be in a DocumentStats struct?

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