Add document statistics feature with background calculation #412
+164
−34
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.