M2.3: find in files backend

crates/search: parallel ignore walk + grep-searcher with the project's
ignore rules (vendor searched as library, node_modules and .git skipped),
literal or regex, case, whole word, include/exclude globs, binary and
> 8 MiB skips, match cap, cancel token, buffer overlay.

Engine: search.find returns {searchId} at once and runs off the lock;
pump_vfs drains results into searchResults (one per file, at most 500
per pump) and searchDone; search.cancel. Testkit: generated search tree.
Tests: library unit and property tests, engine tests, TCP control test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-16 22:03:17 +02:00
parent a6b2fd1300
commit 172693c8dd
21 changed files with 2231 additions and 5 deletions

View file

@ -144,6 +144,49 @@ pub enum Event {
/// Project-relative paths with `/`, sorted.
paths: Vec<String>,
},
/// Matches of a running search (`search.find`) in one file. A file is
/// reported once per search; files arrive in no particular order.
SearchResults {
/// The search, as `search.find` returned it.
search_id: u64,
/// Project-relative path of the file.
path: String,
/// The matches in line order; never empty.
matches: Vec<SearchMatch>,
},
/// A search ended; no `searchResults` for it follow.
SearchDone {
/// The search.
search_id: u64,
/// Files with reported matches.
files: usize,
/// Matches reported.
matches: usize,
/// The match cap stopped the search; more matches exist.
truncated: bool,
/// `search.cancel` (or closing the project) stopped the search.
cancelled: bool,
/// Wall time of the search in milliseconds.
elapsed_ms: u64,
},
}
/// One match of [`Event::SearchResults`]. Positions are 0-based; columns
/// and lengths count UTF-16 code units.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SearchMatch {
/// Line of the match.
pub line: usize,
/// Start of the match in the line.
pub column: usize,
/// Length of the match; never 0.
pub length: usize,
/// The line without its line break, or a window of at most 300
/// characters around the match for longer lines.
pub preview: String,
/// Start of the match inside `preview`.
pub preview_column: usize,
}
/// Severity of an [`Event::Notification`].
@ -224,6 +267,39 @@ mod tests {
);
}
#[test]
fn search_shapes() {
let e = Event::SearchResults {
search_id: 2,
path: "src/a.php".into(),
matches: vec![super::SearchMatch {
line: 0,
column: 6,
length: 4,
preview: "<?php echo".into(),
preview_column: 6,
}],
};
assert_eq!(
serde_json::to_value(e).unwrap(),
json!({"kind": "searchResults", "searchId": 2, "path": "src/a.php", "matches": [
{"line": 0, "column": 6, "length": 4, "preview": "<?php echo", "previewColumn": 6}
]})
);
let e = Event::SearchDone {
search_id: 2,
files: 1,
matches: 1,
truncated: false,
cancelled: false,
elapsed_ms: 12,
};
assert_eq!(
serde_json::to_value(e).unwrap(),
json!({"kind": "searchDone", "searchId": 2, "files": 1, "matches": 1, "truncated": false, "cancelled": false, "elapsedMs": 12})
);
}
#[test]
fn ui_command_shape() {
let e = Event::UiCommand {