Use nucleo-matcher for VSCode-style file search#12446
Draft
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR replaces the skim-based fuzzy matcher with nucleo-matcher to provide VSCode-style file search with better path-aware matching. The implementation improves the file search experience by adding intelligent bonuses for matches that occur after path separators, word boundaries, and camelCase transitions.
Changes:
- Replaced
fuzzy-matcherdependency withnucleo-matcherin Cargo.toml - Refactored
compute_match_scoreto use nucleo's path-aware scoring with configurable bonuses - Updated scoring from i64 to u32 with saturating arithmetic and adjusted depth penalty from 50 to 10
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/gitbutler-repo/Cargo.toml | Swaps fuzzy-matcher dependency for nucleo-matcher 0.3 |
| crates/gitbutler-repo/src/commands.rs | Implements new scoring algorithm using nucleo-matcher with path-aware bonuses, removes separate filename bonus function, and updates find_files implementation with new matcher configuration |
Comments suppressed due to low confidence (1)
crates/gitbutler-repo/src/commands.rs:333
- The
find_filesfunction lacks test coverage despite this being a significant change in matching algorithm (from skim to nucleo-matcher). Consider adding tests that verify:
- Empty query behavior (should return all files)
- Basic fuzzy matching (e.g., "test" matches "src/test.rs")
- Path-aware matching (e.g., "s/t" matches "src/test.rs" due to path separator bonuses)
- CamelCase matching (e.g., "TC" matches "TestClass.rs")
- Result ordering based on match quality
- Depth penalty working correctly
This is especially important given that other functions in this crate (like create_wd_tree, hooks, etc.) have comprehensive test coverage in the tests/ directory.
fn find_files(&self, query: &str, limit: usize) -> Result<Vec<String>> {
static FAIR_QUEUE: Mutex<()> = Mutex::new(());
let _one_at_a_time_to_prevent_races = FAIR_QUEUE.lock().unwrap();
let workdir = self.workdir_or_fail()?;
// Matcher configured for path matching: bonuses after '/', at word
// boundaries, and camelCase transitions.
let mut matcher = Matcher::new(Config::DEFAULT.match_paths());
// Pattern::parse supports multi-word matching (space-separated) and
// smart case (lowercase = case-insensitive, any uppercase = case-sensitive).
let pattern = Pattern::parse(query, CaseMatching::Smart, Normalization::Smart);
let pattern_is_empty = pattern.atoms.is_empty();
// Reusable buffer for Utf32Str conversion.
let mut buf = Vec::new();
let scored_files = WalkBuilder::new(&workdir)
.git_exclude(true)
.git_global(true)
.git_ignore(true)
.build()
.filter_map(Result::ok)
.filter(|entry| entry.file_type().is_some_and(|ft| ft.is_file()))
.filter_map(|entry| {
let relative_path = entry.path().strip_prefix(&workdir).ok()?;
let path_str = relative_path.to_string_lossy();
if pattern_is_empty {
return Some((0u32, path_str.to_string()));
}
let score = compute_match_score(
&pattern,
&mut matcher,
&path_str,
relative_path,
&mut buf,
)?;
Some((score, path_str.to_string()))
})
.sorted_by(|a, b| b.0.cmp(&a.0))
.take(limit)
.map(|(_, path)| path)
.collect();
Ok(scored_files)
}
c6af82e to
1cf273e
Compare
1cf273e to
40b70ca
Compare
Replace the previous skim-based fuzzy matcher with nucleo-matcher to provide path-aware matching similar to VSCode's Cmd+P. The new implementation: - swaps fuzzy-matcher for nucleo-matcher in Cargo.toml - bonuses for matches after '/', word boundaries and camelCase transitions - updates compute_match_score to combine nucleo's path score with a filename bonus and a mild depth penalty
40b70ca to
3449232
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the previous skim-based fuzzy matcher with nucleo-matcher to
provide path-aware matching similar to VSCode's Cmd+P. The new
implementation:
transitions
filename bonus and a mild depth penalty