Skip to content

Commit be36952

Browse files
Merge pull request #483 from HashemKhalifa/fix/grep-scan-cancellation
fix(grep): bound filesystem scans
2 parents 861c9b7 + bac90ab commit be36952

4 files changed

Lines changed: 448 additions & 22 deletions

File tree

src/mcp/tools/handlers/ast_grep_search.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,13 @@ use crate::tracedecay::TraceDecay;
1818

1919
use super::super::ToolResult;
2020
use super::super::render::{self, Md};
21-
use super::support::unique_file_paths;
21+
use super::support::{CancelSearchOnDrop, unique_file_paths};
2222

2323
/// Hard cap on `max_results` regardless of what the caller requests.
2424
const MAX_RESULTS_CAP: usize = 200;
2525
/// Default `max_results` when the caller omits it.
2626
const DEFAULT_MAX_RESULTS: usize = 50;
2727

28-
struct CancelSearchOnDrop(Arc<AtomicBool>);
29-
30-
impl Drop for CancelSearchOnDrop {
31-
fn drop(&mut self) {
32-
self.0.store(true, Ordering::Release);
33-
}
34-
}
35-
3628
async fn search_tree_off_thread(
3729
project_root: std::path::PathBuf,
3830
pattern: String,
@@ -43,7 +35,7 @@ async fn search_tree_off_thread(
4335
) -> Result<crate::ast_grep_search::AstGrepSearchResult> {
4436
let query = pattern.clone();
4537
let cancelled = Arc::new(AtomicBool::new(false));
46-
let cancel_on_drop = CancelSearchOnDrop(cancelled.clone());
38+
let cancel_on_drop = CancelSearchOnDrop::new(cancelled.clone());
4739
let result = tokio::task::spawn_blocking(move || {
4840
search_tree_scoped_with_cancel(
4941
&project_root,
@@ -224,7 +216,7 @@ mod tests {
224216
fn cancellation_guard_signals_worker_on_drop() {
225217
let cancelled = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
226218
{
227-
let _guard = CancelSearchOnDrop(cancelled.clone());
219+
let _guard = CancelSearchOnDrop::new(cancelled.clone());
228220
}
229221
assert!(cancelled.load(std::sync::atomic::Ordering::Acquire));
230222
}

0 commit comments

Comments
 (0)