Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/search/display/glob_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(super) fn format_glob_result(
label: &str,
) -> Result<String, SrcwalkError> {
let header = format!(
"# {label}: \"{}\" in {} — {} of {} files (offset {})",
"# {label}: \"{}\" in {} — {} of {} files (offset {}, sizes ~= tokens)",
result.pattern,
crate::format::display_path(scope),
result.files.len(),
Expand Down
10 changes: 5 additions & 5 deletions src/search/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,18 @@ pub fn search_with_scope_glob(
})
}

/// Quick preview: token estimate plus a one-line summary for code/text files.
/// For code files, the summary is the first non-empty doc/comment or code line
/// (truncated to ~80 chars). For other files, only the token estimate is shown.
/// Quick preview: approximate token count plus a one-line summary for code/text files.
/// The unit is declared once in the result header, so per-file rows keep only the
/// compact `~N` size marker.
fn file_preview(path: &Path) -> Option<String> {
let meta = std::fs::metadata(path).ok()?;
let tokens = estimate_tokens(meta.len());

let summary = first_meaningful_line(path).unwrap_or_default();
if summary.is_empty() {
Some(format!("~{tokens} tokens"))
Some(format!("~{tokens}"))
} else {
Some(format!("~{tokens} tokens · {summary}"))
Some(format!("~{tokens} · {summary}"))
}
}

Expand Down
22 changes: 21 additions & 1 deletion tests/files_and_symbol_glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ fn files_action_lists_file_globs() {
&dir.join("controllers/front/ProductController.php"),
"<?php\nclass ProductController {}\n",
);
write_file(
&dir.join("controllers/front/EmptyController.php"),
"////\n---\n",
);
write_file(
&dir.join("controllers/admin/AdminController.php"),
"<?php\nclass AdminController {}\n",
Expand Down Expand Up @@ -233,7 +237,15 @@ fn files_action_lists_file_globs() {
"bad header:\n{stdout}"
);
assert!(
normalized.contains("controllers/front/ (2)"),
normalized.contains("sizes ~= tokens"),
"file result header should declare token unit once:\n{stdout}"
);
assert!(
!normalized.contains("tokens ·"),
"file rows should not repeat the token unit:\n{stdout}"
);
assert!(
normalized.contains("controllers/front/ (3)"),
"missing grouped directory:\n{stdout}"
);
assert!(
Expand All @@ -244,6 +256,14 @@ fn files_action_lists_file_globs() {
stdout.contains(" ProductController.php"),
"missing product:\n{stdout}"
);
let empty_line = normalized
.lines()
.find(|line| line.contains("EmptyController.php"))
.expect("missing empty-summary file row");
assert!(
!empty_line.contains("tokens"),
"empty-summary file row should not repeat the token unit:\n{stdout}"
);
assert!(
!normalized.contains("controllers/admin/AdminController.php"),
"scope leaked:\n{stdout}"
Expand Down
Loading