Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty title in Recent Projects #21952

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/recent_projects/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ file_finder.workspace = true
futures.workspace = true
fuzzy.workspace = true
gpui.workspace = true
itertools.workspace = true
log.workspace = true
language.workspace = true
markdown.workspace = true
Expand Down
39 changes: 9 additions & 30 deletions crates/recent_projects/src/recent_projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use gpui::{
Action, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView,
Subscription, Task, View, ViewContext, WeakView,
};
use itertools::Itertools;
use ordered_float::OrderedFloat;
use picker::{
highlighted_match_with_paths::{HighlightedMatchWithPaths, HighlightedText},
Expand Down Expand Up @@ -211,22 +210,12 @@ impl PickerDelegate for RecentProjectsDelegate {
.enumerate()
.filter(|(_, (id, _))| !self.is_current_workspace(*id, cx))
.map(|(id, (_, location))| {
let combined_string = match location {
SerializedWorkspaceLocation::Local(paths, order) => order
.order()
.iter()
.zip(paths.paths().iter())
.sorted_by_key(|(i, _)| *i)
.map(|(_, path)| path.compact().to_string_lossy().into_owned())
.collect::<Vec<_>>()
.join(""),
SerializedWorkspaceLocation::Ssh(ssh_project) => ssh_project
.ssh_urls()
.iter()
.map(|path| path.to_string_lossy().to_string())
.collect::<Vec<_>>()
.join(""),
};
let combined_string = location
.sorted_paths()
.iter()
.map(|path| path.compact().to_string_lossy().into_owned())
.collect::<Vec<_>>()
.join("");

StringMatchCandidate::new(id, combined_string)
})
Expand Down Expand Up @@ -364,21 +353,11 @@ impl PickerDelegate for RecentProjectsDelegate {
let (_, location) = self.workspaces.get(hit.candidate_id)?;

let mut path_start_offset = 0;
let paths = match location {
SerializedWorkspaceLocation::Local(paths, order) => Arc::new(
order
.order()
.iter()
.zip(paths.paths().iter())
.sorted_by_key(|(i, _)| **i)
.map(|(_, path)| path.compact())
.collect(),
),
SerializedWorkspaceLocation::Ssh(ssh_project) => Arc::new(ssh_project.ssh_urls()),
};

let (match_labels, paths): (Vec<_>, Vec<_>) = paths
let (match_labels, paths): (Vec<_>, Vec<_>) = location
.sorted_paths()
.iter()
.map(|p| p.compact())
.map(|path| {
let highlighted_text =
highlights_for_path(path.as_ref(), &hit.positions, path_start_offset);
Expand Down
81 changes: 81 additions & 0 deletions crates/workspace/src/persistence/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use db::sqlez::{
statement::Statement,
};
use gpui::{AsyncWindowContext, Model, View, WeakView};
use itertools::Itertools as _;
use project::Project;
use remote::ssh_session::SshProjectId;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -228,6 +229,28 @@ impl SerializedWorkspaceLocation {

Self::Local(LocalPaths::new(sorted_paths), LocalPathsOrder::new(order))
}

/// Get sorted paths
pub fn sorted_paths(&self) -> Arc<Vec<PathBuf>> {
match self {
SerializedWorkspaceLocation::Local(paths, order) => {
if order.order().len() == 0 {
paths.paths().clone()
} else {
Arc::new(
order
.order()
.iter()
.zip(paths.paths().iter())
.sorted_by_key(|(i, _)| **i)
.map(|(_, p)| p.clone())
.collect(),
)
}
}
SerializedWorkspaceLocation::Ssh(ssh_project) => Arc::new(ssh_project.ssh_urls()),
}
}
}

#[derive(Debug, PartialEq, Clone)]
Expand Down Expand Up @@ -564,4 +587,62 @@ mod tests {
)
);
}

#[test]
fn test_sorted_paths() {
let paths = vec!["b", "a", "c"];
let serialized = SerializedWorkspaceLocation::from_local_paths(paths);
assert_eq!(
serialized.sorted_paths(),
Arc::new(vec![
PathBuf::from("b"),
PathBuf::from("a"),
PathBuf::from("c"),
])
);

let paths = Arc::new(vec![
PathBuf::from("a"),
PathBuf::from("b"),
PathBuf::from("c"),
]);
let order = vec![2, 0, 1];
let serialized =
SerializedWorkspaceLocation::Local(LocalPaths(paths.clone()), LocalPathsOrder(order));
assert_eq!(
serialized.sorted_paths(),
Arc::new(vec![
PathBuf::from("b"),
PathBuf::from("c"),
PathBuf::from("a"),
])
);

let paths = Arc::new(vec![
PathBuf::from("a"),
PathBuf::from("b"),
PathBuf::from("c"),
]);
let order = vec![];
let serialized =
SerializedWorkspaceLocation::Local(LocalPaths(paths.clone()), LocalPathsOrder(order));
assert_eq!(serialized.sorted_paths(), paths);

let urls = ["/a", "/b", "/c"];
let serialized = SerializedWorkspaceLocation::Ssh(SerializedSshProject {
id: SshProjectId(0),
host: "host".to_string(),
port: Some(22),
paths: urls.iter().map(|s| s.to_string()).collect(),
user: Some("user".to_string()),
});
assert_eq!(
serialized.sorted_paths(),
Arc::new(
urls.iter()
.map(|p| PathBuf::from(format!("user@host:22{}", p)))
.collect()
)
);
}
}
14 changes: 3 additions & 11 deletions crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,22 +1109,14 @@ impl Workspace {
.as_ref()
.map(|ws| &ws.location)
.and_then(|loc| match loc {
SerializedWorkspaceLocation::Local(paths, order) => {
Some((paths.paths(), order.order()))
SerializedWorkspaceLocation::Local(_, order) => {
Some((loc.sorted_paths(), order.order()))
}
_ => None,
});

if let Some((paths, order)) = workspace_location {
// todo: should probably move this logic to a method on the SerializedWorkspaceLocation
// it's only valid for Local and would be more clear there and be able to be tested
// and reused elsewhere
paths_to_open = order
.iter()
.zip(paths.iter())
.sorted_by_key(|(i, _)| *i)
.map(|(_, path)| path.clone())
.collect();
paths_to_open = paths.iter().cloned().collect();

if order.iter().enumerate().any(|(i, &j)| i != j) {
project_handle
Expand Down
Loading