Skip to content

Commit 5ff6e9d

Browse files
author
Yogthos
committed
gate the /memory review editor path to unix; collapse a nested if
collect/render/parse/apply and PendingEntry/list_pending/clear_pending are only reached from /memory review, which needs $EDITOR, so windows flagged them dead. notify_if_queued and add_pending stay cross-platform: the queue itself is written and counted everywhere. clippy wanted the indent-continuation if collapsed.
1 parent ecd5aa6 commit 5ff6e9d

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/extras/memory_db.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ pub struct BrowseEntry {
333333
/// re-inserts through `add_entry` and lets those be derived fresh.
334334
#[cfg(unix)]
335335
#[derive(Debug, Clone, PartialEq, Eq)]
336+
#[cfg(unix)]
336337
pub struct PendingEntry {
337338
pub id: i64,
338339
/// `"memory"` or `"pitfalls"`.
@@ -1225,6 +1226,7 @@ impl SqliteMemoryStore {
12251226
}
12261227

12271228
/// Every queued entry across both targets, oldest first.
1229+
#[cfg(unix)]
12281230
pub fn list_pending(&self) -> Result<Vec<PendingEntry>, String> {
12291231
let conn = self.conn.lock_ignore_poison();
12301232
let mut stmt = conn
@@ -1262,6 +1264,7 @@ impl SqliteMemoryStore {
12621264
/// Drop the whole queue. Called after a review has been applied — the
12631265
/// reviewed set is re-inserted through `add_entry`, so the queue rows
12641266
/// have served their purpose whether accepted, edited or rejected.
1267+
#[cfg(unix)]
12651268
pub fn clear_pending(&self) -> Result<usize, String> {
12661269
let conn = self.conn.lock_ignore_poison();
12671270
conn.execute("DELETE FROM memories WHERE status = 'pending'", [])

src/ui/memory_review.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
//! queue untouched. Half-applying a mangled review would lose memories with
1818
//! no way to tell which.
1919
20-
use crate::extras::memory_db::{PendingEntry, SqliteMemoryStore};
20+
#[cfg(unix)]
21+
use crate::extras::memory_db::PendingEntry;
22+
use crate::extras::memory_db::SqliteMemoryStore;
2123

24+
#[cfg(unix)]
2225
const HEADER: &str = "\
2326
# Memory review
2427
#
@@ -34,12 +37,14 @@ const HEADER: &str = "\
3437

3538
/// Where an entry lives: which store, which target within it.
3639
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40+
#[cfg(unix)]
3741
pub struct Section {
3842
pub global: bool,
3943
/// `"memory"` or `"pitfalls"`.
4044
pub target: &'static str,
4145
}
4246

47+
#[cfg(unix)]
4348
impl Section {
4449
fn heading(&self) -> String {
4550
format!(
@@ -70,13 +75,15 @@ impl Section {
7075

7176
/// One reviewed entry, as parsed back out of the document.
7277
#[derive(Debug, Clone, PartialEq, Eq)]
78+
#[cfg(unix)]
7379
pub struct ReviewedEntry {
7480
pub section: Section,
7581
pub kind: Option<String>,
7682
pub content: String,
7783
}
7884

7985
/// Render the queue for editing. `entries` is `(section, pending)` pairs.
86+
#[cfg(unix)]
8087
pub fn render(entries: &[(Section, PendingEntry)]) -> String {
8188
let mut out = String::from(HEADER);
8289
let mut current: Option<Section> = None;
@@ -95,6 +102,7 @@ pub fn render(entries: &[(Section, PendingEntry)]) -> String {
95102
/// Errors rather than guessing: a block that appears before any heading has
96103
/// no home, and an unrecognized heading would silently swallow everything
97104
/// under it.
105+
#[cfg(unix)]
98106
pub fn parse(text: &str) -> Result<Vec<ReviewedEntry>, String> {
99107
let mut out: Vec<ReviewedEntry> = Vec::new();
100108
let mut section: Option<Section> = None;
@@ -151,11 +159,11 @@ pub fn parse(text: &str) -> Result<Vec<ReviewedEntry>, String> {
151159
continue;
152160
}
153161
// An indented line continues the block above it.
154-
if line.starts_with(' ') || line.starts_with('\t') {
155-
if let Some((_, lines)) = pending.as_mut() {
156-
lines.push(trimmed.trim().to_string());
157-
continue;
158-
}
162+
if (line.starts_with(' ') || line.starts_with('\t'))
163+
&& let Some((_, lines)) = pending.as_mut()
164+
{
165+
lines.push(trimmed.trim().to_string());
166+
continue;
159167
}
160168
flush(&mut out, section, pending.take())?;
161169
let (kind, rest) = split_kind(trimmed.trim());
@@ -168,6 +176,7 @@ pub fn parse(text: &str) -> Result<Vec<ReviewedEntry>, String> {
168176
/// Split a leading `[kind]` marker off a block's first line. A block with no
169177
/// marker is accepted with `kind = None` so a human can type a bare line and
170178
/// let the store pick the default.
179+
#[cfg(unix)]
171180
fn split_kind(line: &str) -> (Option<String>, &str) {
172181
if let Some(rest) = line.strip_prefix('[')
173182
&& let Some((kind, tail)) = rest.split_once(']')
@@ -179,6 +188,7 @@ fn split_kind(line: &str) -> (Option<String>, &str) {
179188

180189
/// What an applied review did.
181190
#[derive(Debug, Default, PartialEq, Eq)]
191+
#[cfg(unix)]
182192
pub struct ApplyReport {
183193
pub stored: usize,
184194
pub rejected: usize,
@@ -187,6 +197,7 @@ pub struct ApplyReport {
187197
pub failures: Vec<String>,
188198
}
189199

200+
#[cfg(unix)]
190201
impl ApplyReport {
191202
pub fn summary(&self) -> String {
192203
let mut s = format!("{} stored, {} rejected", self.stored, self.rejected);
@@ -203,6 +214,7 @@ impl ApplyReport {
203214
/// defaults, threat scanning and FTS indexing behave exactly as they do for
204215
/// an unreviewed write — an entry the human typed is indistinguishable from
205216
/// one the model proposed, which is the point.
217+
#[cfg(unix)]
206218
pub fn apply(
207219
project: &SqliteMemoryStore,
208220
global: Option<&SqliteMemoryStore>,
@@ -247,6 +259,7 @@ pub fn apply(
247259
report
248260
}
249261

262+
#[cfg(unix)]
250263
fn truncate(s: &str) -> String {
251264
if s.chars().count() <= 48 {
252265
return s.to_string();
@@ -275,6 +288,7 @@ pub fn notify_if_queued(paths: &crate::extras::dirge_paths::ProjectPaths) {
275288
}
276289

277290
/// Collect the queue from both stores, in a stable order.
291+
#[cfg(unix)]
278292
pub fn collect(
279293
project: &SqliteMemoryStore,
280294
global: Option<&SqliteMemoryStore>,
@@ -304,7 +318,7 @@ pub fn collect(
304318
out
305319
}
306320

307-
#[cfg(test)]
321+
#[cfg(all(test, unix))]
308322
mod tests {
309323
use super::*;
310324

0 commit comments

Comments
 (0)