From dbe1425bd21ce48651115a93f4a99d7004f9d7af Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Fri, 24 Jul 2026 23:05:04 -0400 Subject: [PATCH] desktop M10.4: apply rustfmt (line wrapping only) cargo fmt --check output from CI run 2849, applied verbatim: wraps long fn signatures, query/execute calls, and method chains. No logic change. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01FRgehjoz7Yv8LkUfADxACm --- desktop/src-tauri/src/local/commands.rs | 43 +++++- desktop/src-tauri/src/local/derive.rs | 15 +- desktop/src-tauri/src/local/store.rs | 192 ++++++++++++++++++------ 3 files changed, 194 insertions(+), 56 deletions(-) diff --git a/desktop/src-tauri/src/local/commands.rs b/desktop/src-tauri/src/local/commands.rs index e000a5d..f5adae3 100644 --- a/desktop/src-tauri/src/local/commands.rs +++ b/desktop/src-tauri/src/local/commands.rs @@ -79,7 +79,11 @@ pub fn notes_snooze_reminder(id: String, minutes: i64, db: State<'_, Db>) -> Res } #[tauri::command] -pub fn notes_set_labels(id: String, label_ids: Vec, db: State<'_, Db>) -> Result { +pub fn notes_set_labels( + id: String, + label_ids: Vec, + db: State<'_, Db>, +) -> Result { let conn = db.0.lock().map_err(|e| e.to_string())?; store::set_labels(&conn, &id, &label_ids).map_err(|e| e.to_string()) } @@ -91,7 +95,12 @@ pub fn notes_add_item(id: String, text: String, db: State<'_, Db>) -> Result) -> Result { +pub fn notes_update_item( + id: String, + item_id: String, + changes: Value, + db: State<'_, Db>, +) -> Result { let conn = db.0.lock().map_err(|e| e.to_string())?; store::update_item(&conn, &id, &item_id, &changes).map_err(|e| e.to_string()) } @@ -103,13 +112,21 @@ pub fn notes_delete_item(id: String, item_id: String, db: State<'_, Db>) -> Resu } #[tauri::command] -pub fn notes_delete_attachment(id: String, att_id: String, db: State<'_, Db>) -> Result { +pub fn notes_delete_attachment( + id: String, + att_id: String, + db: State<'_, Db>, +) -> Result { let conn = db.0.lock().map_err(|e| e.to_string())?; store::delete_attachment(&conn, &id, &att_id).map_err(|e| e.to_string()) } #[tauri::command] -pub fn notes_delete_preview(id: String, preview_id: String, db: State<'_, Db>) -> Result { +pub fn notes_delete_preview( + id: String, + preview_id: String, + db: State<'_, Db>, +) -> Result { let conn = db.0.lock().map_err(|e| e.to_string())?; store::delete_preview(&conn, &id, &preview_id).map_err(|e| e.to_string()) } @@ -145,7 +162,11 @@ pub fn notes_revisions(id: String, db: State<'_, Db>) -> Result) -> Result { +pub fn notes_restore_revision( + id: String, + rev_id: String, + db: State<'_, Db>, +) -> Result { let conn = db.0.lock().map_err(|e| e.to_string())?; store::restore_revision(&conn, &id, &rev_id).map_err(|e| e.to_string()) } @@ -223,7 +244,11 @@ pub fn saved_filters_list(db: State<'_, Db>) -> Result, String> } #[tauri::command] -pub fn saved_filters_create(name: String, params: Value, db: State<'_, Db>) -> Result { +pub fn saved_filters_create( + name: String, + params: Value, + db: State<'_, Db>, +) -> Result { let conn = db.0.lock().map_err(|e| e.to_string())?; store::create_saved_filter(&conn, &name, ¶ms).map_err(|e| e.to_string()) } @@ -235,7 +260,11 @@ pub fn saved_filters_remove(id: String, db: State<'_, Db>) -> Result<(), String> } #[tauri::command] -pub fn saved_filters_rename(id: String, name: String, db: State<'_, Db>) -> Result { +pub fn saved_filters_rename( + id: String, + name: String, + db: State<'_, Db>, +) -> Result { let conn = db.0.lock().map_err(|e| e.to_string())?; store::rename_saved_filter(&conn, &id, &name).map_err(|e| e.to_string()) } diff --git a/desktop/src-tauri/src/local/derive.rs b/desktop/src-tauri/src/local/derive.rs index db46107..376674f 100644 --- a/desktop/src-tauri/src/local/derive.rs +++ b/desktop/src-tauri/src/local/derive.rs @@ -75,7 +75,10 @@ mod tests { #[test] fn links_basic_and_trim() { - assert_eq!(extract_links("see [[ Alpha ]] and [[Beta]]"), vec!["Alpha", "Beta"]); + assert_eq!( + extract_links("see [[ Alpha ]] and [[Beta]]"), + vec!["Alpha", "Beta"] + ); } #[test] @@ -85,13 +88,19 @@ mod tests { #[test] fn links_ignore_malformed_and_nested_brackets() { - assert_eq!(extract_links("[[a[b]] [[]] [ [x] ] plain"), Vec::::new()); + assert_eq!( + extract_links("[[a[b]] [[]] [ [x] ] plain"), + Vec::::new() + ); assert_eq!(extract_links("[[ok]] [[a]b]]"), vec!["ok"]); } #[test] fn tags_basic() { - assert_eq!(extract_tags("a #todo and #Work-item_2 here"), vec!["todo", "Work-item_2"]); + assert_eq!( + extract_tags("a #todo and #Work-item_2 here"), + vec!["todo", "Work-item_2"] + ); } #[test] diff --git a/desktop/src-tauri/src/local/store.rs b/desktop/src-tauri/src/local/store.rs index b2dce92..5899da7 100644 --- a/desktop/src-tauri/src/local/store.rs +++ b/desktop/src-tauri/src/local/store.rs @@ -31,7 +31,11 @@ fn display_title(title: Option<&str>, body: &str) -> String { return t.to_string(); } } - body.lines().map(str::trim).find(|l| !l.is_empty()).unwrap_or("").to_string() + body.lines() + .map(str::trim) + .find(|l| !l.is_empty()) + .unwrap_or("") + .to_string() } fn normalize_title(raw: &str) -> Option { @@ -44,7 +48,9 @@ fn normalize_title(raw: &str) -> Option { } fn escape_like(s: &str) -> String { - s.replace('\\', "\\\\").replace('%', "\\%").replace('_', "\\_") + s.replace('\\', "\\\\") + .replace('%', "\\%") + .replace('_', "\\_") } // ---- note assembly ---------------------------------------------------------- @@ -154,7 +160,10 @@ fn load_note(conn: &Connection, id: &str) -> rusqlite::Result { } fn touch(conn: &Connection, id: &str) -> rusqlite::Result<()> { - conn.execute("UPDATE notes SET updated_at = ?1, dirty = 1 WHERE id = ?2", params![now(), id])?; + conn.execute( + "UPDATE notes SET updated_at = ?1, dirty = 1 WHERE id = ?2", + params![now(), id], + )?; Ok(()) } @@ -162,7 +171,11 @@ fn touch(conn: &Connection, id: &str) -> rusqlite::Result<()> { fn find_or_create_label(conn: &Connection, name: &str) -> rusqlite::Result { let existing: Option = conn - .query_row("SELECT id FROM labels WHERE lower(name) = lower(?1)", [name], |r| r.get(0)) + .query_row( + "SELECT id FROM labels WHERE lower(name) = lower(?1)", + [name], + |r| r.get(0), + ) .optional()?; if let Some(id) = existing { return Ok(id); @@ -185,7 +198,8 @@ fn sync_tags(conn: &Connection, note_id: &str, body: &str) -> rusqlite::Result<( } let current: Vec = { - let mut stmt = conn.prepare("SELECT label_id FROM note_labels WHERE note_id = ?1 AND via_tag = 1")?; + let mut stmt = + conn.prepare("SELECT label_id FROM note_labels WHERE note_id = ?1 AND via_tag = 1")?; let rows = stmt.query_map([note_id], |r| r.get::<_, String>(0))?; rows.collect::>>()? }; @@ -288,7 +302,8 @@ pub fn reminders(conn: &Connection) -> rusqlite::Result> { let ids: Vec = { let mut stmt = conn.prepare("SELECT id FROM notes WHERE trashed = 0 AND remind_at IS NOT NULL ORDER BY remind_at ASC")?; - stmt.query_map([], |r| r.get::<_, String>(0))?.collect::>>()? + stmt.query_map([], |r| r.get::<_, String>(0))? + .collect::>>()? }; ids.iter().map(|id| load_note(conn, id)).collect() } @@ -312,7 +327,8 @@ pub fn search(conn: &Connection, q: &str) -> rusqlite::Result> { let mut stmt = conn.prepare( "SELECT id FROM notes WHERE trashed = 0 AND (title LIKE ?1 ESCAPE '\\' OR body LIKE ?1 ESCAPE '\\') ORDER BY updated_at DESC", )?; - stmt.query_map([&pat], |r| r.get::<_, String>(0))?.collect::>>()? + stmt.query_map([&pat], |r| r.get::<_, String>(0))? + .collect::>>()? }; ids.iter().map(|id| load_note(conn, id)).collect() } @@ -320,13 +336,16 @@ pub fn search(conn: &Connection, q: &str) -> rusqlite::Result> { pub fn backlinks(conn: &Connection, id: &str) -> rusqlite::Result> { let target: String = { let (t, b): (Option, String) = - conn.query_row("SELECT title, body FROM notes WHERE id = ?1", [id], |r| Ok((r.get(0)?, r.get(1)?)))?; + conn.query_row("SELECT title, body FROM notes WHERE id = ?1", [id], |r| { + Ok((r.get(0)?, r.get(1)?)) + })?; display_title(t.as_deref(), &b) }; if target.is_empty() { return Ok(Vec::new()); } - let mut stmt = conn.prepare("SELECT id, title, body FROM notes WHERE trashed = 0 AND id != ?1")?; + let mut stmt = + conn.prepare("SELECT id, title, body FROM notes WHERE trashed = 0 AND id != ?1")?; let rows = stmt.query_map([id], |r| { let nid: String = r.get(0)?; let t: Option = r.get(1)?; @@ -336,7 +355,10 @@ pub fn backlinks(conn: &Connection, id: &str) -> rusqlite::Result> let mut out = Vec::new(); for row in rows { let (nid, t, b) = row?; - if derive::extract_links(&b).iter().any(|l| l.eq_ignore_ascii_case(&target)) { + if derive::extract_links(&b) + .iter() + .any(|l| l.eq_ignore_ascii_case(&target)) + { out.push(Backlink { id: nid, title: display_title(t.as_deref(), &b), @@ -373,7 +395,11 @@ pub fn create_note(conn: &Connection, input: &NoteCreateInput) -> rusqlite::Resu let ts = now(); let title = normalize_title(&input.title); let kind = input.kind.clone().unwrap_or_else(|| "text".to_string()); - let position: i64 = conn.query_row("SELECT COALESCE(MAX(position), 0) + 1 FROM notes", [], |r| r.get(0))?; + let position: i64 = conn.query_row( + "SELECT COALESCE(MAX(position), 0) + 1 FROM notes", + [], + |r| r.get(0), + )?; conn.execute( "INSERT INTO notes (id, title, body, color, kind, position, created_at, updated_at, dirty) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?7, 1)", @@ -404,7 +430,9 @@ pub fn create_titled(conn: &Connection, title: &str) -> rusqlite::Result { fn snapshot_revision(conn: &Connection, id: &str) -> rusqlite::Result<()> { let (title, body): (Option, String) = - conn.query_row("SELECT title, body FROM notes WHERE id = ?1", [id], |r| Ok((r.get(0)?, r.get(1)?)))?; + conn.query_row("SELECT title, body FROM notes WHERE id = ?1", [id], |r| { + Ok((r.get(0)?, r.get(1)?)) + })?; conn.execute( "INSERT INTO note_revisions (id, note_id, title, body, created_at) VALUES (?1, ?2, ?3, ?4, ?5)", params![new_id(), id, title, body, now()], @@ -427,11 +455,17 @@ pub fn update_note(conn: &Connection, id: &str, changes: &Value) -> rusqlite::Re match k.as_str() { "title" => { let norm = v.as_str().and_then(normalize_title); - conn.execute("UPDATE notes SET title = ?1 WHERE id = ?2", params![norm, id])?; + conn.execute( + "UPDATE notes SET title = ?1 WHERE id = ?2", + params![norm, id], + )?; } "body" => { let body = v.as_str().unwrap_or(""); - conn.execute("UPDATE notes SET body = ?1 WHERE id = ?2", params![body, id])?; + conn.execute( + "UPDATE notes SET body = ?1 WHERE id = ?2", + params![body, id], + )?; sync_tags(conn, id, body)?; } "color" => { @@ -451,16 +485,25 @@ pub fn update_note(conn: &Connection, id: &str, changes: &Value) -> rusqlite::Re } "archived" => { if let Some(b) = v.as_bool() { - conn.execute("UPDATE notes SET archived = ?1 WHERE id = ?2", params![b, id])?; + conn.execute( + "UPDATE notes SET archived = ?1 WHERE id = ?2", + params![b, id], + )?; } } "remind_at" => { let val = v.as_str().map(|s| s.to_string()); - conn.execute("UPDATE notes SET remind_at = ?1 WHERE id = ?2", params![val, id])?; + conn.execute( + "UPDATE notes SET remind_at = ?1 WHERE id = ?2", + params![val, id], + )?; } "recurrence" => { let val = v.as_str().map(|s| s.to_string()); - conn.execute("UPDATE notes SET recurrence = ?1 WHERE id = ?2", params![val, id])?; + conn.execute( + "UPDATE notes SET recurrence = ?1 WHERE id = ?2", + params![val, id], + )?; } _ => {} } @@ -479,14 +522,20 @@ pub fn complete_reminder(conn: &Connection, id: &str) -> rusqlite::Result pub fn snooze_reminder(conn: &Connection, id: &str, minutes: i64) -> rusqlite::Result { let t = (Utc::now() + Duration::minutes(minutes)).to_rfc3339_opts(SecondsFormat::Millis, true); - conn.execute("UPDATE notes SET remind_at = ?1 WHERE id = ?2", params![t, id])?; + conn.execute( + "UPDATE notes SET remind_at = ?1 WHERE id = ?2", + params![t, id], + )?; touch(conn, id)?; load_note(conn, id) } pub fn set_labels(conn: &Connection, id: &str, label_ids: &[String]) -> rusqlite::Result { // Manual labels are replaced wholesale; #tag (via_tag) labels are managed by text. - conn.execute("DELETE FROM note_labels WHERE note_id = ?1 AND via_tag = 0", [id])?; + conn.execute( + "DELETE FROM note_labels WHERE note_id = ?1 AND via_tag = 0", + [id], + )?; for lid in label_ids { conn.execute( "INSERT OR IGNORE INTO note_labels (note_id, label_id, via_tag) VALUES (?1, ?2, 0)", @@ -498,10 +547,11 @@ pub fn set_labels(conn: &Connection, id: &str, label_ids: &[String]) -> rusqlite } pub fn add_item(conn: &Connection, id: &str, text: &str) -> rusqlite::Result { - let pos: i64 = - conn.query_row("SELECT COALESCE(MAX(position), -1) + 1 FROM checklist_items WHERE note_id = ?1", [id], |r| { - r.get(0) - })?; + let pos: i64 = conn.query_row( + "SELECT COALESCE(MAX(position), -1) + 1 FROM checklist_items WHERE note_id = ?1", + [id], + |r| r.get(0), + )?; conn.execute( "INSERT INTO checklist_items (id, note_id, text, position) VALUES (?1, ?2, ?3, ?4)", params![new_id(), id, text, pos], @@ -510,7 +560,12 @@ pub fn add_item(conn: &Connection, id: &str, text: &str) -> rusqlite::Result rusqlite::Result { +pub fn update_item( + conn: &Connection, + id: &str, + item_id: &str, + changes: &Value, +) -> rusqlite::Result { if let Some(text) = changes.get("text").and_then(Value::as_str) { conn.execute( "UPDATE checklist_items SET text = ?1 WHERE id = ?2 AND note_id = ?3", @@ -528,19 +583,28 @@ pub fn update_item(conn: &Connection, id: &str, item_id: &str, changes: &Value) } pub fn delete_item(conn: &Connection, id: &str, item_id: &str) -> rusqlite::Result { - conn.execute("DELETE FROM checklist_items WHERE id = ?1 AND note_id = ?2", params![item_id, id])?; + conn.execute( + "DELETE FROM checklist_items WHERE id = ?1 AND note_id = ?2", + params![item_id, id], + )?; touch(conn, id)?; load_note(conn, id) } pub fn delete_attachment(conn: &Connection, id: &str, att_id: &str) -> rusqlite::Result { - conn.execute("DELETE FROM attachments WHERE id = ?1 AND note_id = ?2", params![att_id, id])?; + conn.execute( + "DELETE FROM attachments WHERE id = ?1 AND note_id = ?2", + params![att_id, id], + )?; touch(conn, id)?; load_note(conn, id) } pub fn delete_preview(conn: &Connection, id: &str, preview_id: &str) -> rusqlite::Result { - conn.execute("DELETE FROM link_previews WHERE id = ?1 AND note_id = ?2", params![preview_id, id])?; + conn.execute( + "DELETE FROM link_previews WHERE id = ?1 AND note_id = ?2", + params![preview_id, id], + )?; touch(conn, id)?; load_note(conn, id) } @@ -548,7 +612,10 @@ pub fn delete_preview(conn: &Connection, id: &str, preview_id: &str) -> rusqlite pub fn reorder(conn: &Connection, ordered_ids: &[String]) -> rusqlite::Result<()> { let total = ordered_ids.len() as i64; for (i, id) in ordered_ids.iter().enumerate() { - conn.execute("UPDATE notes SET position = ?1, dirty = 1 WHERE id = ?2", params![total - i as i64, id])?; + conn.execute( + "UPDATE notes SET position = ?1, dirty = 1 WHERE id = ?2", + params![total - i as i64, id], + )?; } Ok(()) } @@ -591,7 +658,10 @@ pub fn restore_revision(conn: &Connection, id: &str, rev_id: &str) -> rusqlite:: |r| Ok((r.get(0)?, r.get(1)?)), )?; snapshot_revision(conn, id)?; - conn.execute("UPDATE notes SET title = ?1, body = ?2 WHERE id = ?3", params![title, body, id])?; + conn.execute( + "UPDATE notes SET title = ?1, body = ?2 WHERE id = ?3", + params![title, body, id], + )?; sync_tags(conn, id, &body)?; touch(conn, id)?; load_note(conn, id) @@ -641,12 +711,18 @@ pub fn create_label(conn: &Connection, name: &str) -> rusqlite::Result