Skip to main content

lean_ctx/core/
search_walk.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Walk limits and file filters shared by `ctx_search` and the search index,
3//! so both see the same searchable universe. Moved down from
4//! `tools/ctx_search/implementation.rs`.
5
6use std::path::Path;
7
8/// Size cap for a file met during a directory walk.
9pub const MAX_FILE_SIZE: u64 = 512_000;
10/// Maximum directory depth of a search walk.
11pub const MAX_WALK_DEPTH: usize = 20;
12
13pub fn is_binary_ext(path: &Path) -> bool {
14    let ext = path.extension().and_then(|e| e.to_str()).unwrap_or("");
15    matches!(
16        ext,
17        "png"
18            | "jpg"
19            | "jpeg"
20            | "gif"
21            | "webp"
22            | "ico"
23            | "svg"
24            | "woff"
25            | "woff2"
26            | "ttf"
27            | "eot"
28            | "pdf"
29            | "zip"
30            | "tar"
31            | "gz"
32            | "br"
33            | "zst"
34            | "bz2"
35            | "xz"
36            | "mp3"
37            | "mp4"
38            | "webm"
39            | "ogg"
40            | "wasm"
41            | "so"
42            | "dylib"
43            | "dll"
44            | "exe"
45            | "lock"
46            | "map"
47            | "snap"
48            | "patch"
49            | "db"
50            | "sqlite"
51            | "parquet"
52            | "arrow"
53            | "bin"
54            | "o"
55            | "a"
56            | "class"
57            | "pyc"
58            | "pyo"
59    )
60}
61
62pub fn is_generated_file(path: &Path) -> bool {
63    let name = path.file_name().and_then(|n| n.to_str()).unwrap_or("");
64    name.ends_with(".min.js")
65        || name.ends_with(".min.css")
66        || name.ends_with(".bundle.js")
67        || name.ends_with(".chunk.js")
68        || name.ends_with(".d.ts")
69        || name.ends_with(".js.map")
70        || name.ends_with(".css.map")
71}