From 8e0ca2056e97045af3693b649fde41c26b07ee4d Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 21 Apr 2021 12:05:34 -0700 Subject: [PATCH] Store paths as strings on PathMatch structs Co-Authored-By: Nathan Sobo --- zed/src/file_finder.rs | 11 ++++------- zed/src/worktree/fuzzy.rs | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/zed/src/file_finder.rs b/zed/src/file_finder.rs index eac0b3d5fb..d959cae312 100644 --- a/zed/src/file_finder.rs +++ b/zed/src/file_finder.rs @@ -14,7 +14,7 @@ use gpui::{ AppContext, Axis, Border, Entity, ModelHandle, MutableAppContext, View, ViewContext, ViewHandle, WeakViewHandle, }; -use std::cmp; +use std::{cmp, path::Path}; pub struct FileFinder { handle: WeakViewHandle, @@ -139,17 +139,14 @@ impl FileFinder { let tree_id = path_match.tree_id; let entry_id = path_match.entry_id; - self.worktree(tree_id, app).map(|tree| { - let path = tree - .path_for_inode(entry_id, path_match.include_root) - .unwrap(); - let file_name = path + self.worktree(tree_id, app).map(|_| { + let path = &path_match.path; + let file_name = Path::new(path) .file_name() .unwrap_or_default() .to_string_lossy() .to_string(); - let path = path.to_string_lossy().to_string(); let path_positions = path_match.positions.clone(); let file_name_start = path.chars().count() - file_name.chars().count(); let mut file_name_positions = Vec::new(); diff --git a/zed/src/worktree/fuzzy.rs b/zed/src/worktree/fuzzy.rs index 55efdfe737..dbb2985fac 100644 --- a/zed/src/worktree/fuzzy.rs +++ b/zed/src/worktree/fuzzy.rs @@ -45,9 +45,9 @@ impl PathEntry { pub struct PathMatch { pub score: f64, pub positions: Vec, + pub path: String, pub tree_id: usize, pub entry_id: u64, - pub include_root: bool, } impl PartialEq for PathMatch { @@ -234,9 +234,9 @@ fn match_single_tree_paths<'a>( results.push(Reverse(PathMatch { tree_id, entry_id: path_entry.ino, + path: path_entry.path.iter().skip(skipped_prefix_len).collect(), score, positions: match_positions.clone(), - include_root: skipped_prefix_len == 0, })); if results.len() == max_results { *min_score = results.peek().unwrap().0.score;