Skip to content

Commit

Permalink
Return candidate without further checks if only one has an exact name…
Browse files Browse the repository at this point in the history
… match
  • Loading branch information
boxbeam committed Apr 18, 2024
1 parent 3177399 commit 1be88b2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/tabby/src/services/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,20 @@ fn closest_match<'a>(
search_input: impl IntoIterator<Item = &'a RepositoryConfig>,
) -> Option<String> {
let git_search = GitUrl::parse(search_term).ok()?;
search_input

let candidates: Vec<_> = search_input
.into_iter()
// Name is scored the highest, an exact match is required.
.filter(|elem| GitUrl::parse(&elem.git_url).is_ok_and(|url| url.name == git_search.name))
.collect();

// If we only have a single repository with an exact name match, return that with no further checks
if let [candidate] = &*candidates {
return Some(candidate.git_url.clone());
}

candidates
.into_iter()
.filter_map(|elem| {
let git_url = GitUrl::parse(&elem.git_url).ok()?;
let mut score = 0;

Check warning on line 176 in crates/tabby/src/services/code.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/services/code.rs#L175-L176

Added lines #L175 - L176 were not covered by tests
Expand Down

0 comments on commit 1be88b2

Please sign in to comment.