Skip to content

Commit 1c93941

Browse files
refactor/cleanup
1 parent 875644e commit 1c93941

22 files changed

Lines changed: 89 additions & 471 deletions

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
[workspace]
2-
members = [
3-
"diagnostic-parser",
4-
"diagnostic-tui",
5-
]
2+
members = ["diagnostic-parser", "diagnostic-tui"]
63
resolver = "3"
74

85
[workspace.dependencies]

diagnostic-parser/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

diagnostic-parser/src/log_entry.rs

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
use chrono::{DateTime, FixedOffset};
3939
use std::{borrow::Cow, collections::HashSet, fmt, sync::Arc};
4040

41+
#[cfg(test)]
42+
mod tests;
43+
4144
// ---------------------------------------------------------------------------
4245
// Log level
4346
// ---------------------------------------------------------------------------
@@ -138,10 +141,10 @@ impl fmt::Display for LogSource {
138141
}
139142

140143
// ---------------------------------------------------------------------------
141-
// Log source (borrowed)
144+
// Log source
142145
// ---------------------------------------------------------------------------
143146

144-
/// Zero-copy version of [`LogSource`]. Borrows slices from the original log line.
147+
/// String slices from the original log line.
145148
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
146149
pub struct LogSourceRef<'a> {
147150
/// The component prefix, e.g. `"1P"`, `"client"`, `"status"`.
@@ -202,10 +205,6 @@ impl fmt::Display for LogSourceRef<'_> {
202205
}
203206
}
204207

205-
// ---------------------------------------------------------------------------
206-
// Shared helpers for LogSource / LogSourceRef
207-
// ---------------------------------------------------------------------------
208-
209208
/// Extract the file path portion from a detail string like `"crate/path/file.rs:42"`.
210209
fn extract_file_path(detail: &str) -> Option<&str> {
211210
let colon_pos = detail.rfind(':')?;
@@ -275,11 +274,18 @@ impl<'a> LogEntry<'a> {
275274
cache: &mut StringCache,
276275
) -> Vec<Self> {
277276
let title_arc = cache.cached(log_file_title);
278-
parse_log_lines(
279-
content,
280-
|line| Self::parse_line(&title_arc, line, cache),
281-
|entry, line| entry.continuation.push(line),
282-
)
277+
let mut entries = Vec::with_capacity(content.lines().count());
278+
for line in content.lines().filter(|line| !line.trim_start().is_empty()) {
279+
match Self::parse_line(&title_arc, line, cache) {
280+
Some(entry) => entries.push(entry),
281+
None => {
282+
if let Some(last) = entries.last_mut() {
283+
last.continuation.push(line);
284+
}
285+
}
286+
}
287+
}
288+
entries
283289
}
284290

285291
/// Attempt to parse a single log line into a zero-copy [`LogEntry`].
@@ -351,10 +357,6 @@ impl fmt::Display for LogEntry<'_> {
351357
}
352358
}
353359

354-
// ---------------------------------------------------------------------------
355-
// String Cache
356-
// ---------------------------------------------------------------------------
357-
358360
/// A simple string cache backed by a [`HashMap`]. Converts `&str` values
359361
/// into `Arc<str>`, returning the same `Arc` for duplicate strings.
360362
///
@@ -397,34 +399,6 @@ impl StringCache {
397399
}
398400
}
399401

400-
// ---------------------------------------------------------------------------
401-
// Shared line-parsing logic
402-
// ---------------------------------------------------------------------------
403-
404-
/// Generic log content parser shared by owned and zero-copy paths.
405-
///
406-
/// Iterates lines, calling `try_parse` on each. If it returns `Some(entry)`,
407-
/// the entry is collected. Otherwise the line is a continuation and is
408-
/// attached to the last entry via `push_continuation`.
409-
fn parse_log_lines<'a, T>(
410-
content: &'a str,
411-
mut try_parse: impl FnMut(&'a str) -> Option<T>,
412-
mut push_continuation: impl FnMut(&mut T, &'a str),
413-
) -> Vec<T> {
414-
let mut entries = Vec::with_capacity(content.lines().count());
415-
for line in content.lines().filter(|line| !line.trim_start().is_empty()) {
416-
match try_parse(line) {
417-
Some(entry) => entries.push(entry),
418-
None => {
419-
if let Some(last) = entries.last_mut() {
420-
push_continuation(last, line);
421-
}
422-
}
423-
}
424-
}
425-
entries
426-
}
427-
428402
struct LogLineFields<'a> {
429403
level: LogLevel,
430404
timestamp: DateTime<FixedOffset>,
@@ -565,10 +539,3 @@ fn parse_bracketed(s: &str) -> Option<(&str, &str)> {
565539
let close = s.find(']')?;
566540
Some((&s[1..close], &s[close + 1..]))
567541
}
568-
569-
// ---------------------------------------------------------------------------
570-
// Tests
571-
// ---------------------------------------------------------------------------
572-
573-
#[cfg(test)]
574-
mod tests;

diagnostic-parser/src/log_entry/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn log_level_display() {
2222
assert_eq!(LogLevel::Error.to_string(), "ERROR");
2323
}
2424

25-
// ── Zero-copy LogEntry tests ──────────────────────────────────
25+
// ── LogEntry tests ──────────────────────────────────
2626

2727
#[test]
2828
fn ref_parse_info_line() {

diagnostic-parser/src/main.rs

Lines changed: 0 additions & 158 deletions
This file was deleted.

0 commit comments

Comments
 (0)