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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FRgehjoz7Yv8LkUfADxACm
This commit is contained in:
2026-07-24 23:05:04 -04:00
co-authored by Claude Opus 4.8
parent ed1b3aa814
commit dbe1425bd2
3 changed files with 194 additions and 56 deletions
+36 -7
View File
@@ -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<String>, db: State<'_, Db>) -> Result<Note, String> {
pub fn notes_set_labels(
id: String,
label_ids: Vec<String>,
db: State<'_, Db>,
) -> Result<Note, String> {
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<Not
}
#[tauri::command]
pub fn notes_update_item(id: String, item_id: String, changes: Value, db: State<'_, Db>) -> Result<Note, String> {
pub fn notes_update_item(
id: String,
item_id: String,
changes: Value,
db: State<'_, Db>,
) -> Result<Note, String> {
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<Note, String> {
pub fn notes_delete_attachment(
id: String,
att_id: String,
db: State<'_, Db>,
) -> Result<Note, String> {
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<Note, String> {
pub fn notes_delete_preview(
id: String,
preview_id: String,
db: State<'_, Db>,
) -> Result<Note, String> {
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<Vec<NoteRevision
}
#[tauri::command]
pub fn notes_restore_revision(id: String, rev_id: String, db: State<'_, Db>) -> Result<Note, String> {
pub fn notes_restore_revision(
id: String,
rev_id: String,
db: State<'_, Db>,
) -> Result<Note, String> {
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<Vec<SavedFilter>, String>
}
#[tauri::command]
pub fn saved_filters_create(name: String, params: Value, db: State<'_, Db>) -> Result<SavedFilter, String> {
pub fn saved_filters_create(
name: String,
params: Value,
db: State<'_, Db>,
) -> Result<SavedFilter, String> {
let conn = db.0.lock().map_err(|e| e.to_string())?;
store::create_saved_filter(&conn, &name, &params).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<SavedFilter, String> {
pub fn saved_filters_rename(
id: String,
name: String,
db: State<'_, Db>,
) -> Result<SavedFilter, String> {
let conn = db.0.lock().map_err(|e| e.to_string())?;
store::rename_saved_filter(&conn, &id, &name).map_err(|e| e.to_string())
}
+12 -3
View File
@@ -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::<String>::new());
assert_eq!(
extract_links("[[a[b]] [[]] [ [x] ] plain"),
Vec::<String>::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]
+146 -46
View File
@@ -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<String> {
@@ -44,7 +48,9 @@ fn normalize_title(raw: &str) -> Option<String> {
}
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<Note> {
}
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<String> {
let existing: Option<String> = 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<String> = {
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::<rusqlite::Result<Vec<String>>>()?
};
@@ -288,7 +302,8 @@ pub fn reminders(conn: &Connection) -> rusqlite::Result<Vec<Note>> {
let ids: Vec<String> = {
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::<rusqlite::Result<Vec<String>>>()?
stmt.query_map([], |r| r.get::<_, String>(0))?
.collect::<rusqlite::Result<Vec<String>>>()?
};
ids.iter().map(|id| load_note(conn, id)).collect()
}
@@ -312,7 +327,8 @@ pub fn search(conn: &Connection, q: &str) -> rusqlite::Result<Vec<Note>> {
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::<rusqlite::Result<Vec<String>>>()?
stmt.query_map([&pat], |r| r.get::<_, String>(0))?
.collect::<rusqlite::Result<Vec<String>>>()?
};
ids.iter().map(|id| load_note(conn, id)).collect()
}
@@ -320,13 +336,16 @@ pub fn search(conn: &Connection, q: &str) -> rusqlite::Result<Vec<Note>> {
pub fn backlinks(conn: &Connection, id: &str) -> rusqlite::Result<Vec<Backlink>> {
let target: String = {
let (t, b): (Option<String>, 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<String> = r.get(1)?;
@@ -336,7 +355,10 @@ pub fn backlinks(conn: &Connection, id: &str) -> rusqlite::Result<Vec<Backlink>>
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<Note> {
fn snapshot_revision(conn: &Connection, id: &str) -> rusqlite::Result<()> {
let (title, body): (Option<String>, 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<Note>
pub fn snooze_reminder(conn: &Connection, id: &str, minutes: i64) -> rusqlite::Result<Note> {
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<Note> {
// 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<Note> {
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<Not
load_note(conn, id)
}
pub fn update_item(conn: &Connection, id: &str, item_id: &str, changes: &Value) -> rusqlite::Result<Note> {
pub fn update_item(
conn: &Connection,
id: &str,
item_id: &str,
changes: &Value,
) -> rusqlite::Result<Note> {
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<Note> {
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<Note> {
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<Note> {
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<Label> {
}
pub fn rename_label(conn: &Connection, id: &str, name: &str) -> rusqlite::Result<Label> {
conn.execute("UPDATE labels SET name = ?1, updated_at = ?2, dirty = 1 WHERE id = ?3", params![name, now(), id])?;
conn.execute(
"UPDATE labels SET name = ?1, updated_at = ?2, dirty = 1 WHERE id = ?3",
params![name, now(), id],
)?;
load_label(conn, id)
}
pub fn set_label_color(conn: &Connection, id: &str, color: &str) -> rusqlite::Result<Label> {
conn.execute("UPDATE labels SET color = ?1, updated_at = ?2, dirty = 1 WHERE id = ?3", params![color, now(), id])?;
conn.execute(
"UPDATE labels SET color = ?1, updated_at = ?2, dirty = 1 WHERE id = ?3",
params![color, now(), id],
)?;
load_label(conn, id)
}
@@ -655,7 +731,11 @@ pub fn remove_label(conn: &Connection, id: &str) -> rusqlite::Result<()> {
Ok(())
}
pub fn merge_labels(conn: &Connection, source_id: &str, target_id: &str) -> rusqlite::Result<Label> {
pub fn merge_labels(
conn: &Connection,
source_id: &str,
target_id: &str,
) -> rusqlite::Result<Label> {
conn.execute(
"INSERT OR IGNORE INTO note_labels (note_id, label_id, via_tag)
SELECT note_id, ?2, 0 FROM note_labels WHERE label_id = ?1",
@@ -683,9 +763,17 @@ pub fn list_saved_filters(conn: &Connection) -> rusqlite::Result<Vec<SavedFilter
rows.collect()
}
pub fn create_saved_filter(conn: &Connection, name: &str, params: &Value) -> rusqlite::Result<SavedFilter> {
pub fn create_saved_filter(
conn: &Connection,
name: &str,
params: &Value,
) -> rusqlite::Result<SavedFilter> {
let id = new_id();
let position: i64 = conn.query_row("SELECT COALESCE(MAX(position), 0) + 1 FROM saved_filters", [], |r| r.get(0))?;
let position: i64 = conn.query_row(
"SELECT COALESCE(MAX(position), 0) + 1 FROM saved_filters",
[],
|r| r.get(0),
)?;
let params_str = serde_json::to_string(params).unwrap_or_else(|_| "{}".to_string());
conn.execute(
"INSERT INTO saved_filters (id, name, params, position, created_at) VALUES (?1, ?2, ?3, ?4, ?5)",
@@ -704,16 +792,28 @@ pub fn remove_saved_filter(conn: &Connection, id: &str) -> rusqlite::Result<()>
Ok(())
}
pub fn rename_saved_filter(conn: &Connection, id: &str, name: &str) -> rusqlite::Result<SavedFilter> {
conn.execute("UPDATE saved_filters SET name = ?1 WHERE id = ?2", params![name, id])?;
conn.query_row("SELECT id, name, params, position FROM saved_filters WHERE id = ?1", [id], |r| {
let params_str: String = r.get(2)?;
let params = serde_json::from_str(&params_str).unwrap_or_else(|_| serde_json::json!({}));
Ok(SavedFilter {
id: r.get(0)?,
name: r.get(1)?,
params,
position: r.get(3)?,
})
})
pub fn rename_saved_filter(
conn: &Connection,
id: &str,
name: &str,
) -> rusqlite::Result<SavedFilter> {
conn.execute(
"UPDATE saved_filters SET name = ?1 WHERE id = ?2",
params![name, id],
)?;
conn.query_row(
"SELECT id, name, params, position FROM saved_filters WHERE id = ?1",
[id],
|r| {
let params_str: String = r.get(2)?;
let params =
serde_json::from_str(&params_str).unwrap_or_else(|_| serde_json::json!({}));
Ok(SavedFilter {
id: r.get(0)?,
name: r.get(1)?,
params,
position: r.get(3)?,
})
},
)
}