refactor: DRY cleanup — extract shared helpers, remove duplication across tools, LSP, overlays, and runtime
Eliminate ~500 lines of duplicate code across 31 files by extracting shared functions, helpers, and consolidating repeated patterns. Highlights: - Toast helpers (toast_info/success/warning/error) on AppStateRest - push_event() helper for turn-event queue (19 callers consolidated) - log_write_edit_tool() shared fn (turn.rs + engine.rs ~50 lines saved) - resolve_api_key() shared fn (spawn.rs + provider.rs) - LSP call_positional() helper on LspClient - lsp_cursor_params() shared schema for 4 tool files -overlay_block() helper for consistent overlay title/border styling - cycle_selected_index(), path_not_found/a_directory() helpers - mark_dirty(), save_settings() on AppStateRest - Remove redundant Err(e) => Err(e) arms in LSP tools - Consolidate generate_workspace_tree (turn.rs → workspace.rs) - Simplify background-review wrapper args in auto/mod.rs Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
b02754acd2
commit
9a6ab62562
@@ -11,3 +11,22 @@ pub mod quit_confirm;
|
||||
pub mod rewind;
|
||||
pub mod settings;
|
||||
pub mod todo;
|
||||
|
||||
/// Cycle `current` in the range `[0, len)`.
|
||||
///
|
||||
/// * `forward = true` — increment (wrap at len)
|
||||
/// * `forward = false` — decrement (wrap at 0), saturating at 0 when len is 0
|
||||
///
|
||||
/// Return: `0` when `len == 0`, otherwise the wrapped index.
|
||||
pub fn cycle_selected_index(current: usize, len: usize, forward: bool) -> usize {
|
||||
if len == 0 {
|
||||
return 0;
|
||||
}
|
||||
if forward {
|
||||
(current + 1) % len
|
||||
} else if current == 0 {
|
||||
len.saturating_sub(1)
|
||||
} else {
|
||||
current - 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user