Skip to main content

vtcode_core/tools/
outline_search.rs

1//! Bounded, read-only declaration discovery for `code_search`.
2//!
3//! This replaces the external `ast-grep` binary that VT Code used to
4//! download and spawn for declaration outlines. Declarations are recognised
5//! with per-language regular expressions over the source text, which keeps the
6//! tool self-contained without giving up the `definition` result category.
7//!
8//! A declaration is a line that *declares* a name — a function, type, class,
9//! or constant definition — as opposed to merely mentioning one. The patterns
10//! are deliberately conservative: they match declaration keywords rather than
11//! any occurrence of the name, so a call site is never reported as a
12//! definition.
13
14use std::collections::HashMap;
15use std::path::{Path, PathBuf};
16use std::sync::{LazyLock, Mutex};
17
18use anyhow::Result;
19use regex::Regex;
20use vtcode_commons::canonicalize;
21use vtcode_commons::exclusions::is_sensitive_file;
22use vtcode_commons::walk::{build_walker_single_threaded, is_excluded_dir};
23
24use super::code_language::CodeLanguage;
25
26/// Maximum number of files scanned for declarations.
27const CODE_SEARCH_OUTLINE_FILE_CAP: usize = 512;
28
29/// Maximum number of declarations collected across all files.
30const CODE_SEARCH_OUTLINE_DECLARATION_CAP: usize = 1024;
31
32/// Maximum size of a file that may be scanned for declarations.
33const CODE_SEARCH_OUTLINE_MAX_FILE_SIZE: u64 = 4 * 1024 * 1024;
34
35/// A byte range within a source file.
36#[derive(Debug, Clone, PartialEq, Eq)]
37pub(crate) struct DeclarationRange {
38    /// Byte offset of the range start.
39    pub byte_start: usize,
40    /// Byte offset of the range end.
41    pub byte_end: usize,
42}
43
44/// A recognised declaration.
45#[derive(Debug, Clone, PartialEq, Eq)]
46pub(crate) struct DeclarationRecord {
47    /// The declared name.
48    pub name: String,
49    /// The byte range the declaration covers.
50    pub range: DeclarationRange,
51    /// One-based line the declared name starts on.
52    pub line: usize,
53    /// One-based byte column the declared name starts at.
54    pub column: usize,
55}
56
57/// The declarations recognised in one file.
58#[derive(Debug, Clone, PartialEq, Eq)]
59pub(crate) struct DeclarationFileRecord {
60    /// Path of the file.
61    pub path: PathBuf,
62    /// Language the file was recognised as.
63    pub language: CodeLanguage,
64    /// The declarations found.
65    pub declarations: Vec<DeclarationRecord>,
66    /// Whether the file was scanned completely.
67    pub complete: bool,
68}
69
70/// The outcome of a bounded declaration search.
71#[derive(Debug, Clone, PartialEq, Eq)]
72pub(crate) struct DeclarationSearchOutcome {
73    /// Per-file declaration records.
74    pub files: Vec<DeclarationFileRecord>,
75    /// Whether the scan covered every eligible file.
76    pub stream_complete: bool,
77    /// Whether the scan stopped early.
78    pub truncated: bool,
79}
80
81/// Whether two names match under smart-case rules.
82///
83/// A query with an upper-case character matches exactly; an all-lower-case
84/// query matches case-insensitively.
85fn smart_case_eq(left: &str, query: &str) -> bool {
86    if query.chars().any(char::is_uppercase) {
87        left == query
88    } else {
89        left.to_lowercase() == query.to_lowercase()
90    }
91}
92
93/// The declaration patterns for one language.
94///
95/// Each pattern captures the declared name in group 1. A language without
96/// patterns has no declaration support, which the caller reports as an
97/// unavailable result category rather than fabricating definitions.
98fn declaration_patterns(language: CodeLanguage) -> &'static [&'static str] {
99    match language {
100        CodeLanguage::Rust => &[
101            r#"(?m)^\s*(?:pub(?:\([^)]*\))?\s+)?(?:default\s+)?(?:const\s+)?(?:async\s+)?(?:unsafe\s+)?(?:extern\s+"[^"]*"\s+)?fn\s+([A-Za-z_][A-Za-z0-9_]*)"#,
102            r"(?m)^\s*(?:pub(?:\([^)]*\))?\s+)?(?:struct|enum|trait|union)\s+([A-Za-z_][A-Za-z0-9_]*)",
103            r"(?m)^\s*(?:pub(?:\([^)]*\))?\s+)?(?:type|const|static)\s+([A-Za-z_][A-Za-z0-9_]*)",
104            r"(?m)^\s*(?:pub(?:\([^)]*\))?\s+)?mod\s+([A-Za-z_][A-Za-z0-9_]*)",
105            r"(?m)^\s*impl(?:<[^>]*>)?\s+(?:[A-Za-z_][A-Za-z0-9_:<>, ]*\s+for\s+)?([A-Za-z_][A-Za-z0-9_]*)",
106        ],
107        CodeLanguage::Python => &[
108            r"(?m)^\s*(?:async\s+)?def\s+([A-Za-z_][A-Za-z0-9_]*)",
109            r"(?m)^\s*class\s+([A-Za-z_][A-Za-z0-9_]*)",
110        ],
111        CodeLanguage::JavaScript | CodeLanguage::TypeScript | CodeLanguage::Tsx => &[
112            r"(?m)^\s*(?:export\s+)?(?:default\s+)?(?:async\s+)?function\s*\*?\s+([A-Za-z_$][A-Za-z0-9_$]*)",
113            r"(?m)^\s*(?:export\s+)?(?:abstract\s+)?class\s+([A-Za-z_$][A-Za-z0-9_$]*)",
114            r"(?m)^\s*(?:export\s+)?(?:declare\s+)?(?:const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)",
115            r"(?m)^\s*(?:export\s+)?(?:declare\s+)?interface\s+([A-Za-z_$][A-Za-z0-9_$]*)",
116            r"(?m)^\s*(?:export\s+)?(?:declare\s+)?(?:type|enum|namespace)\s+([A-Za-z_$][A-Za-z0-9_$]*)",
117        ],
118        CodeLanguage::Go => &[
119            r"(?m)^\s*func\s+([A-Za-z_][A-Za-z0-9_]*)",
120            r"(?m)^\s*func\s+\([^)]*\)\s*([A-Za-z_][A-Za-z0-9_]*)",
121            r"(?m)^\s*type\s+([A-Za-z_][A-Za-z0-9_]*)",
122            r"(?m)^\s*(?:const|var)\s+([A-Za-z_][A-Za-z0-9_]*)",
123        ],
124        CodeLanguage::Java => &[
125            r"(?m)^\s*(?:public\s+|private\s+|protected\s+)?(?:static\s+|final\s+|abstract\s+)*class\s+([A-Za-z_][A-Za-z0-9_]*)",
126            r"(?m)^\s*(?:public\s+|private\s+|protected\s+)?(?:static\s+|final\s+|abstract\s+)*interface\s+([A-Za-z_][A-Za-z0-9_]*)",
127            r"(?m)^\s*(?:public\s+|private\s+|protected\s+)?(?:static\s+|final\s+|abstract\s+)*enum\s+([A-Za-z_][A-Za-z0-9_]*)",
128            r"(?m)^\s*(?:public\s+|private\s+|protected\s+)?(?:static\s+|final\s+|abstract\s+|synchronized\s+|native\s+)*[A-Za-z_][A-Za-z0-9_<>\[\], ]*\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(",
129        ],
130        CodeLanguage::C | CodeLanguage::Cpp => &[
131            r"(?m)^\s*(?:struct|union|enum|class)\s+([A-Za-z_][A-Za-z0-9_]*)",
132            r"(?m)^\s*typedef\s+.*\b([A-Za-z_][A-Za-z0-9_]*)\s*;",
133            r"(?m)^\s*(?:static\s+|inline\s+|extern\s+|const\s+|unsigned\s+|signed\s+)*[A-Za-z_][A-Za-z0-9_]*\s*\*?\s*([A-Za-z_][A-Za-z0-9_]*)\s*\([^;]*\)\s*\{",
134        ],
135        CodeLanguage::Csharp => &[
136            r"(?m)^\s*(?:public\s+|private\s+|protected\s+|internal\s+|static\s+|sealed\s+|abstract\s+|partial\s+)*(?:class|interface|struct|enum|record)\s+([A-Za-z_][A-Za-z0-9_]*)",
137        ],
138        CodeLanguage::Ruby => &[
139            r"(?m)^\s*def\s+(?:self\.)?([A-Za-z_][A-Za-z0-9_]*[?!=]?)",
140            r"(?m)^\s*class\s+([A-Za-z_][A-Za-z0-9_:]*)",
141            r"(?m)^\s*module\s+([A-Za-z_][A-Za-z0-9_:]*)",
142        ],
143        CodeLanguage::Php => &[
144            r"(?m)^\s*(?:(?:public|private|protected|static|final|abstract)\s+)*function\s+([A-Za-z_][A-Za-z0-9_]*)",
145            r"(?m)^\s*(?:abstract\s+|final\s+)*class\s+([A-Za-z_][A-Za-z0-9_]*)",
146            r"(?m)^\s*(?:abstract\s+|final\s+)?interface\s+([A-Za-z_][A-Za-z0-9_]*)",
147        ],
148        CodeLanguage::Kotlin => &[
149            r"(?m)^\s*(?:public\s+|private\s+|internal\s+|protected\s+|open\s+|abstract\s+|final\s+|suspend\s+|data\s+|sealed\s+)*(?:class|interface|object|enum)\s+([A-Za-z_][A-Za-z0-9_]*)",
150            r"(?m)^\s*(?:public\s+|private\s+|internal\s+|protected\s+|open\s+|override\s+|suspend\s+)*fun\s+([A-Za-z_][A-Za-z0-9_]*)",
151        ],
152        CodeLanguage::Swift => &[
153            r"(?m)^\s*(?:public\s+|private\s+|internal\s+|fileprivate\s+|open\s+|final\s+)*(?:class|struct|enum|protocol|extension)\s+([A-Za-z_][A-Za-z0-9_]*)",
154            r"(?m)^\s*(?:public\s+|private\s+|internal\s+|fileprivate\s+|open\s+|static\s+|class\s+|override\s+)*func\s+([A-Za-z_][A-Za-z0-9_]*)",
155        ],
156        CodeLanguage::Scala => &[
157            r"(?m)^\s*(?:final\s+|sealed\s+|abstract\s+|case\s+)*(?:class|object|trait)\s+([A-Za-z_][A-Za-z0-9_]*)",
158            r"(?m)^\s*(?:final\s+|implicit\s+|override\s+)*def\s+([A-Za-z_][A-Za-z0-9_]*)",
159        ],
160        CodeLanguage::Elixir => &[
161            r"(?m)^\s*def(?:p)?\s+([A-Za-z_][A-Za-z0-9_]*[?!]?)",
162            r"(?m)^\s*defmodule\s+([A-Za-z_][A-Za-z0-9_.:]*)",
163        ],
164        CodeLanguage::Dart => &[
165            r"(?m)^\s*(?:abstract\s+)?class\s+([A-Za-z_][A-Za-z0-9_]*)",
166            r"(?m)^\s*(?:enum|mixin|extension)\s+([A-Za-z_][A-Za-z0-9_]*)",
167        ],
168        CodeLanguage::Lua => &[r"(?m)^\s*(?:local\s+)?function\s+([A-Za-z_][A-Za-z0-9_.:]*)"],
169        CodeLanguage::Zig => &[r"(?m)^\s*(?:pub\s+)?fn\s+([A-Za-z_][A-Za-z0-9_]*)"],
170        CodeLanguage::Haskell => &[r"(?m)^([A-Za-z_][A-Za-z0-9_']*)\s*::"],
171        CodeLanguage::Solidity => &[
172            r"(?m)^\s*(?:abstract\s+|contract\s+|interface\s+|library\s+)([A-Za-z_][A-Za-z0-9_]*)",
173            r"(?m)^\s*function\s+([A-Za-z_][A-Za-z0-9_]*)",
174        ],
175        CodeLanguage::Bash => &[r"(?m)^\s*(?:function\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*\(\)\s*\{"],
176        CodeLanguage::Markdown
177        | CodeLanguage::Css
178        | CodeLanguage::Html
179        | CodeLanguage::Json
180        | CodeLanguage::Yaml
181        | CodeLanguage::Sql
182        | CodeLanguage::Dockerfile
183        | CodeLanguage::Toml
184        | CodeLanguage::Hcl
185        | CodeLanguage::Nix
186        | CodeLanguage::Protobuf => &[],
187    }
188}
189
190/// The declaration patterns, compiled once per language.
191///
192/// Compiling the patterns costs roughly a quarter of a millisecond, and the
193/// scanner runs once per file in the walk, so recompiling per file dominated
194/// a bounded search. The patterns are static literals, so they are compiled
195/// on first use per language and reused afterwards.
196static COMPILED_PATTERNS: LazyLock<Mutex<HashMap<CodeLanguage, Option<Vec<Regex>>>>> =
197    LazyLock::new(|| Mutex::new(HashMap::new()));
198
199/// Compiles the declaration patterns for a language.
200///
201/// Returns `None` when the language has no declaration patterns, which the
202/// caller treats as "no definition support for this language".
203fn compile_patterns(language: CodeLanguage) -> Option<Vec<Regex>> {
204    // A poisoned cache only means a panicked compilation; the entries that
205    // were written before it stay valid, so the guard is recovered rather
206    // than propagated.
207    let mut cache = COMPILED_PATTERNS.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
208    cache
209        .entry(language)
210        .or_insert_with(|| compile_declaration_patterns(language))
211        .clone()
212}
213
214/// Compiles the static declaration patterns for a language.
215fn compile_declaration_patterns(language: CodeLanguage) -> Option<Vec<Regex>> {
216    let patterns = declaration_patterns(language);
217    if patterns.is_empty() {
218        return None;
219    }
220    let compiled = patterns
221        .iter()
222        .filter_map(|pattern| Regex::new(pattern).ok())
223        .collect::<Vec<_>>();
224    if compiled.is_empty() { None } else { Some(compiled) }
225}
226
227/// Whether a language has declaration support.
228///
229/// A language without declaration patterns (markdown, yaml, plain text) has
230/// no structural anchors, so a semantic anchor falls back to exact text
231/// search.
232pub(crate) fn supports_declarations(language: CodeLanguage) -> bool {
233    !declaration_patterns(language).is_empty()
234}
235
236/// The declaration names an anchor refers to.
237///
238/// The anchor is read with the same grammar that recognises declarations in
239/// source, so `@@ fn deploy` names `deploy` and `@@ impl Trait for Type`
240/// names `Type` — exactly the name the file-side scanner records for that
241/// declaration. An anchor that is not a declaration header names nothing.
242pub(crate) fn declaration_names_in_anchor(anchor: &str, language: CodeLanguage) -> Vec<String> {
243    let Some(patterns) = compile_patterns(language) else {
244        return Vec::new();
245    };
246    let mut names = Vec::new();
247    for pattern in &patterns {
248        for capture in pattern.captures_iter(anchor) {
249            let Some(name) = capture.get(1) else {
250                continue;
251            };
252            names.push(name.as_str().to_string());
253        }
254    }
255    names.sort();
256    names.dedup();
257    names
258}
259
260/// A declaration matched in a source file, before its position is resolved.
261struct RawDeclaration {
262    /// The declared name.
263    name: String,
264    /// The byte range the declared name covers.
265    range: DeclarationRange,
266}
267
268/// Collects every declaration of `language` declared in `source`.
269///
270/// Returns `None` when the language has no declaration patterns, which the
271/// caller reports as "no declaration support" rather than an empty result.
272fn collect_raw_declarations(source: &str, language: CodeLanguage) -> Option<Vec<RawDeclaration>> {
273    let patterns = compile_patterns(language)?;
274
275    let mut declarations = Vec::new();
276    for pattern in &patterns {
277        for capture in pattern.captures_iter(source) {
278            let Some(name_match) = capture.get(1) else {
279                continue;
280            };
281            declarations.push(RawDeclaration {
282                name: name_match.as_str().to_string(),
283                // The range covers the declared name itself, so a literal hit
284                // elsewhere in the file can be told apart from the declaration.
285                range: DeclarationRange {
286                    byte_start: name_match.start(),
287                    byte_end: name_match.end(),
288                },
289            });
290        }
291    }
292
293    declarations.sort_by_key(|declaration| (declaration.range.byte_start, declaration.range.byte_end));
294    declarations.dedup_by(|left, right| left.range == right.range);
295    Some(declarations)
296}
297
298/// Resolves the one-based line and byte column of each declared name.
299///
300/// The scanner is the single place that maps byte offsets to positions, so
301/// every consumer of a declaration agrees on the line and column base.
302fn with_positions(source: &str, declarations: Vec<RawDeclaration>) -> Vec<DeclarationRecord> {
303    let index = LineIndex::new(source);
304    declarations
305        .into_iter()
306        .map(|declaration| {
307            let (line, column) = index.position(declaration.range.byte_start);
308            DeclarationRecord {
309                name: declaration.name,
310                range: declaration.range,
311                line,
312                column,
313            }
314        })
315        .collect()
316}
317
318/// Maps byte offsets in a source file to one-based line and byte column.
319///
320/// Lines are one-based, and the column counts bytes from the start of the
321/// line, matching `rg --column`.
322struct LineIndex {
323    /// Byte offset of the start of each line.
324    starts: Vec<usize>,
325}
326
327impl LineIndex {
328    fn new(source: &str) -> Self {
329        let mut starts = vec![0usize];
330        starts.extend(source.match_indices('\n').map(|(index, _)| index + 1));
331        Self { starts }
332    }
333
334    /// Returns the one-based line and byte column of `offset`.
335    fn position(&self, offset: usize) -> (usize, usize) {
336        // The number of line starts at or before `offset` is the one-based
337        // line number, because `starts[0]` is the first line.
338        let line = self.starts.partition_point(|start| *start <= offset).max(1);
339        let column = offset - self.starts[line - 1] + 1;
340        (line, column)
341    }
342}
343
344/// Recognises the declarations in `source` that match `query`.
345///
346/// Returns the matching declarations and whether the scan covered the whole
347/// file.
348fn scan_declarations(source: &str, language: CodeLanguage, query: &str) -> Option<(Vec<DeclarationRecord>, bool)> {
349    let mut matching: Vec<RawDeclaration> = collect_raw_declarations(source, language)?
350        .into_iter()
351        .filter(|declaration| smart_case_eq(&declaration.name, query))
352        .collect();
353
354    let mut complete = true;
355    if matching.len() > CODE_SEARCH_OUTLINE_DECLARATION_CAP {
356        matching.truncate(CODE_SEARCH_OUTLINE_DECLARATION_CAP);
357        complete = false;
358    }
359
360    Some((with_positions(source, matching), complete))
361}
362
363/// Returns the declarations in `source` whose name matches one of `names`.
364///
365/// Names are matched case-insensitively, so an anchor like `@@ fn deploy`
366/// resolves to a declaration named `deploy` regardless of case.
367pub(crate) fn declarations_named(source: &str, language: CodeLanguage, names: &[String]) -> Vec<DeclarationRecord> {
368    let Some(raw) = collect_raw_declarations(source, language) else {
369        return Vec::new();
370    };
371    let matching: Vec<RawDeclaration> = raw
372        .into_iter()
373        .filter(|declaration| names.iter().any(|name| declaration.name.eq_ignore_ascii_case(name)))
374        .collect();
375    with_positions(source, matching)
376}
377
378/// Finds the declarations matching `query` under `resolved_path`.
379///
380/// The scan is bounded: at most [`CODE_SEARCH_OUTLINE_FILE_CAP`] files are
381/// read and at most [`CODE_SEARCH_OUTLINE_DECLARATION_CAP`] declarations are
382/// collected.
383pub(crate) async fn search_declarations_bounded(
384    workspace_root: &Path,
385    resolved_path: &Path,
386    query: &str,
387    languages: &[CodeLanguage],
388    candidate_cap: usize,
389) -> Result<DeclarationSearchOutcome> {
390    let walk_root = if resolved_path.is_file() {
391        resolved_path.parent().unwrap_or(workspace_root).to_path_buf()
392    } else {
393        resolved_path.to_path_buf()
394    };
395
396    let mut builder = build_walker_single_threaded(&walk_root);
397    builder.filter_entry(|entry| !is_excluded_dir(entry));
398
399    let mut files = Vec::new();
400    let mut scanned = 0usize;
401    let mut truncated = false;
402    let mut stream_complete = true;
403
404    for entry in builder.build().filter_map(std::result::Result::ok) {
405        if !entry.file_type().is_some_and(|kind| kind.is_file()) {
406            continue;
407        }
408        let path = entry.into_path();
409        if path.file_name().and_then(|name| name.to_str()).is_some_and(is_sensitive_file) {
410            continue;
411        }
412        let Some(language) = CodeLanguage::from_path(&path) else {
413            continue;
414        };
415        if !languages.is_empty() && !languages.contains(&language) {
416            continue;
417        }
418        if scanned >= CODE_SEARCH_OUTLINE_FILE_CAP {
419            truncated = true;
420            stream_complete = false;
421            break;
422        }
423        let Ok(metadata) = std::fs::metadata(&path) else {
424            continue;
425        };
426        if metadata.len() > CODE_SEARCH_OUTLINE_MAX_FILE_SIZE {
427            continue;
428        }
429        let Ok(source) = std::fs::read_to_string(&path) else {
430            continue;
431        };
432        let Some((declarations, complete)) = scan_declarations(&source, language, query) else {
433            // The language has no declaration support, so it contributes
434            // nothing but also costs no budget.
435            continue;
436        };
437        scanned += 1;
438        if declarations.len() > candidate_cap {
439            truncated = true;
440            stream_complete = false;
441        }
442        let Ok(canonical) = canonicalize(&path) else {
443            continue;
444        };
445        files.push(DeclarationFileRecord {
446            path: canonical,
447            language,
448            declarations: declarations.into_iter().take(candidate_cap).collect(),
449            complete,
450        });
451        if files.len() >= candidate_cap {
452            truncated = true;
453            stream_complete = false;
454            break;
455        }
456    }
457
458    Ok(DeclarationSearchOutcome { files, stream_complete, truncated })
459}
460
461#[cfg(test)]
462mod tests {
463    use super::{scan_declarations, search_declarations_bounded};
464
465    use std::fs;
466
467    use tempfile::tempdir;
468
469    use crate::tools::code_language::CodeLanguage;
470
471    #[test]
472    fn rust_function_declarations_are_recognised() {
473        let source = "fn Widget() {\n    Widget();\n}\nfn other() {}\n";
474        let (declarations, complete) = scan_declarations(source, CodeLanguage::Rust, "Widget").expect("rust");
475
476        assert!(complete);
477        assert_eq!(declarations.len(), 1, "only the declaration matches, not the call site");
478        assert_eq!(declarations[0].name, "Widget");
479        // The range covers the declared name, not the whole declaration.
480        assert_eq!(declarations[0].range.byte_start, 3);
481        assert_eq!(&source[declarations[0].range.byte_start..declarations[0].range.byte_end], "Widget");
482    }
483
484    #[test]
485    fn smart_case_matching_is_applied_to_declaration_names() {
486        let source = "fn Widget() {}\n";
487        let (declarations, _) = scan_declarations(source, CodeLanguage::Rust, "widget").expect("rust");
488        assert_eq!(declarations.len(), 1, "an all-lower-case query matches case-insensitively");
489
490        let (declarations, _) = scan_declarations(source, CodeLanguage::Rust, "other").expect("rust");
491        assert!(declarations.is_empty(), "a different name does not match");
492    }
493
494    #[test]
495    fn python_and_javascript_declarations_are_recognised() {
496        let (declarations, _) =
497            scan_declarations("class Widget:\n    pass\n", CodeLanguage::Python, "Widget").expect("python");
498        assert_eq!(declarations.len(), 1);
499
500        let (declarations, _) =
501            scan_declarations("export function Widget() {}\n", CodeLanguage::JavaScript, "Widget").expect("js");
502        assert_eq!(declarations.len(), 1);
503    }
504
505    #[test]
506    fn languages_without_declaration_support_report_none() {
507        assert!(scan_declarations("# Widget\n", CodeLanguage::Markdown, "Widget").is_none());
508    }
509
510    #[tokio::test]
511    async fn bounded_search_reports_declarations_per_file() {
512        let dir = tempdir().expect("tempdir");
513        fs::create_dir_all(dir.path().join("src")).expect("src directory");
514        fs::write(dir.path().join("src/widget.rs"), "fn Widget() {}\n").expect("write source");
515
516        let outcome = search_declarations_bounded(dir.path(), dir.path(), "Widget", &[], 20)
517            .await
518            .expect("search runs");
519
520        assert_eq!(outcome.files.len(), 1);
521        assert_eq!(outcome.files[0].declarations.len(), 1);
522        assert_eq!(outcome.files[0].declarations[0].name, "Widget");
523    }
524}