Add document statistics feature with background calculation#412
Open
romanstingler wants to merge 1 commit intopop-os:masterfrom
Open
Add document statistics feature with background calculation#412romanstingler wants to merge 1 commit intopop-os:masterfrom
romanstingler wants to merge 1 commit intopop-os:masterfrom
Conversation
mmstick
reviewed
Sep 25, 2025
| word_count: usize, | ||
| } | ||
|
|
||
| fn calculate_document_statistics(lines: Vec<String>) -> DocumentStatistics { |
Member
There was a problem hiding this comment.
This should be borrowed since it doesn't need ownership, and that sounds like a very costly vec.
mmstick
reviewed
Sep 25, 2025
| document_stats_pending: Option<u64>, | ||
| document_stats_request_target: Option<Entity>, | ||
| document_stats_dirty: bool, | ||
| document_stats_request_id: u64, |
Member
There was a problem hiding this comment.
Seems like this should be in a DocumentStats struct?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added cached
DocumentStatisticsplus async calculation insrc/main.rsso the statistics drawer never blocks the UI thread.Extended
Appwithdocument_stats,document_stats_dirty,document_stats_pending,document_stats_request_target, anddocument_stats_request_id, and introducedMessage::DocumentStatsto deliver background results.Updated
App::update_tab(), theMessage::TabChangedhandler, andMessage::ToggleContextPageso stats are recomputed only when the Document Statistics drawer is open for the active editor tab.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_blockingto 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
DocumentStatisticsstruct for the main thread to cache and display.