refactor(core): extract path_resolver module, deduplicate escape_like

Extract path resolution logic into a new `src/core/path_resolver.rs`
module to enable reuse across the codebase. Previously, `escape_like`,
`normalize_repo_path`, `PathQuery`, `build_path_query`, `SuffixResult`,
and `suffix_probe` were private to `who.rs`, making them inaccessible
to other modules that needed the same path-matching logic.

Key changes:
- New `path_resolver.rs` with all path resolution functions made `pub`
- New `path_resolver_tests.rs` with 15 tests covering: escape_like,
  normalize_repo_path, build_path_query heuristics, DB probes (exact,
  prefix, suffix), project scoping, and cross-source deduplication
- Remove duplicate `escape_like` from `list.rs` (was `note_escape_like`)
  and `search/filters.rs` — both now import from `path_resolver`
- `project.rs` imports `escape_like` from the new module

The path resolution strategy (exact > prefix > suffix > heuristic
fallback) and all DB probe logic are preserved exactly as extracted.
`suffix_probe` checks both `new_path` and `old_path` columns to
support querying renamed files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Taylor Eernisse
2026-02-13 12:36:49 -05:00
parent 437bacdda4
commit 1799842b59
6 changed files with 538 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
use rusqlite::Connection;
use super::error::{LoreError, Result};
use super::path_resolver::escape_like;
pub fn resolve_project(conn: &Connection, project_str: &str) -> Result<i64> {
let exact = conn.query_row(
@@ -106,13 +107,6 @@ pub fn resolve_project(conn: &Connection, project_str: &str) -> Result<i64> {
/// Escape LIKE metacharacters so `%` and `_` in user input are treated as
/// literals. All queries using this must include `ESCAPE '\'`.
fn escape_like(input: &str) -> String {
input
.replace('\\', "\\\\")
.replace('%', "\\%")
.replace('_', "\\_")
}
#[cfg(test)]
#[path = "project_tests.rs"]
mod tests;