vtcode-file-search
Fast, parallel fuzzy file search library for VT Code.
Overview
vtcode-file-search is a dedicated file discovery and fuzzy matching crate that provides:
- Parallel directory traversal using the
ignorecrate (same library as ripgrep) - Fuzzy matching with
nucleo-matcherfor relevance scoring - Lock-free result collection per worker thread
- Configurable exclusion patterns for .gitignore, .ignore, and custom globs
- Standalone CLI for testing and integration
- Library API for embedding in VT Code tools, extensions, and MCP servers
Features
- Parallel traversal with configurable thread count
- Automatic .gitignore, .ignore, and .git/info/exclude support
- Custom exclusion patterns (glob-style)
- Fuzzy matching with scoring
- Cancellation support via
Arc<AtomicBool> - Optional character indices for UI highlighting
- JSON output format
- Top-K results collection (configurable limit)
Quick Start
As a Library
use NonZero;
use Path;
use Arc;
use AtomicBool;
use run;
As a CLI
# Search for files matching "main" pattern
# With options
# JSON output
# Exclude patterns
# Show help
API
run()
Parameters:
pattern_text: Fuzzy search pattern (e.g., "main.rs", "test")limit: Maximum number of results to returnsearch_directory: Root directory to searchexclude: Glob patterns to exclude (e.g.,["target/**", "node_modules/**"])threads: Number of worker threadscancel_flag:Arc<AtomicBool>for early terminationcompute_indices: Whether to compute character indices for highlightingrespect_gitignore: Whether to respect .gitignore files
Returns:
file_name_from_path()
Extract filename from a path:
use file_name_from_path;
assert_eq!;
assert_eq!;
Examples
Basic Search
use NonZero;
use Path;
use Arc;
use AtomicBool;
use run;
let results = run?;
for m in results.matches
With Exclusions
let results = run?;
With Cancellation
use Arc;
use AtomicBool;
use Ordering;
let cancel_flag = new;
let cancel_clone = cancel_flag.clone;
// Spawn a task that cancels after 100ms
spawn;
let results = run?;
Performance
On a modern machine (M4 Apple Silicon, 8 cores):
- 5,000 files: ~50ms
- 100,000 files: ~200ms
- 1,000,000 files: ~500ms
Parallel efficiency is ~90% with 8 threads.
Architecture
Input Pattern
↓
[Parallel Directory Traversal]
├─ Worker 1: [Fuzzy Match] → [Per-Worker Results]
├─ Worker 2: [Fuzzy Match] → [Per-Worker Results]
└─ Worker N: [Fuzzy Match] → [Per-Worker Results]
↓
[Merge & Sort by Score]
↓
[Top-K Results]
Key Design:
- Each worker thread has its own
BestMatchesList(no locking during traversal) - Per-match fuzzy matching using
nucleo-matcher - Automatic .gitignore support from the
ignorecrate - Early termination via
Arc<AtomicBool>cancellation flag
Dependencies
ignore– Parallel directory traversal (ripgrep's choice)nucleo-matcher– Fuzzy matching and scoring (Neovim's choice)tokio– Async runtimeserde/serde_json– Serializationclap– CLI argument parsing
Testing
# Unit tests
# Integration tests
# With output
# Specific test
Building
# Development build
# Release build
CLI Usage
# Show help
# Search in current directory
# Search in specific directory
# JSON output
# Exclude patterns
# Limit results
# Custom thread count
Integration with VT Code
This crate will be integrated into VT Code for:
- File Browser – Fuzzy filename search
- Grep Tool – Efficient file discovery (no ripgrep subprocess)
- Code Intelligence – Workspace-wide symbol search
- Zed Extension – File picker integration
- VS Code Extension – Similar integration
- MCP Server – Expose as MCP resource/tool
Contributing
This crate follows VT Code's standard conventions:
- Use
cargo testfor testing - Use
cargo clippyfor linting - Use
cargo fmtfor formatting - Error handling with
anyhow::Result<T> - No
unwrap()orexpect()calls
License
MIT