Rename RemoteProject -> DevServerProject (#11301)

Co-Authored-By: Mikayla <mikayla@zed.dev>

In a fit of ill-advisedness I called these things remote projects;
forgetting that remote project is also what we call collaboratively
shared projects.

Release Notes:

- N/A

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
Co-authored-by: Bennet <bennetbo@gmx.de>
This commit is contained in:
Conrad Irwin 2024-05-02 11:00:08 -06:00 committed by GitHub
parent d61c47d2a9
commit 9bac64a9c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 834 additions and 771 deletions

View file

@ -20,7 +20,7 @@ gpui.workspace = true
menu.workspace = true
ordered-float.workspace = true
picker.workspace = true
remote_projects.workspace = true
dev_server_projects.workspace = true
rpc.workspace = true
serde.workspace = true
settings.workspace = true

View file

@ -1,12 +1,12 @@
use std::time::Duration;
use dev_server_projects::{DevServer, DevServerId, DevServerProject, DevServerProjectId};
use feature_flags::FeatureFlagViewExt;
use gpui::{
percentage, Action, Animation, AnimationExt, AppContext, ClipboardItem, DismissEvent,
EventEmitter, FocusHandle, FocusableView, Model, ScrollHandle, Transformation, View,
ViewContext,
};
use remote_projects::{DevServer, DevServerId, RemoteProject, RemoteProjectId};
use rpc::{
proto::{self, CreateDevServerResponse, DevServerStatus},
ErrorCode, ErrorExt,
@ -20,12 +20,12 @@ use workspace::{notifications::DetachAndPromptErr, AppState, ModalView, Workspac
use crate::OpenRemote;
pub struct RemoteProjects {
pub struct DevServerProjects {
mode: Mode,
focus_handle: FocusHandle,
scroll_handle: ScrollHandle,
remote_project_store: Model<remote_projects::Store>,
remote_project_path_input: View<TextField>,
dev_server_store: Model<dev_server_projects::Store>,
project_path_input: View<TextField>,
dev_server_name_input: View<TextField>,
_subscription: gpui::Subscription,
}
@ -36,19 +36,19 @@ struct CreateDevServer {
dev_server: Option<CreateDevServerResponse>,
}
struct CreateRemoteProject {
struct CreateDevServerProject {
dev_server_id: DevServerId,
creating: bool,
remote_project: Option<proto::RemoteProject>,
dev_server_project: Option<proto::DevServerProject>,
}
enum Mode {
Default,
CreateRemoteProject(CreateRemoteProject),
CreateDevServerProject(CreateDevServerProject),
CreateDevServer(CreateDevServer),
}
impl RemoteProjects {
impl DevServerProjects {
pub fn register(_: &mut Workspace, cx: &mut ViewContext<Workspace>) {
cx.observe_flag::<feature_flags::Remoting, _>(|enabled, workspace, _| {
if enabled {
@ -67,14 +67,14 @@ impl RemoteProjects {
}
pub fn new(cx: &mut ViewContext<Self>) -> Self {
let remote_project_path_input = cx.new_view(|cx| TextField::new(cx, "", "Project path"));
let project_path_input = cx.new_view(|cx| TextField::new(cx, "", "Project path"));
let dev_server_name_input =
cx.new_view(|cx| TextField::new(cx, "Name", "").with_label(FieldLabelLayout::Stacked));
let focus_handle = cx.focus_handle();
let remote_project_store = remote_projects::Store::global(cx);
let dev_server_store = dev_server_projects::Store::global(cx);
let subscription = cx.observe(&remote_project_store, |_, _, cx| {
let subscription = cx.observe(&dev_server_store, |_, _, cx| {
cx.notify();
});
@ -82,20 +82,20 @@ impl RemoteProjects {
mode: Mode::Default,
focus_handle,
scroll_handle: ScrollHandle::new(),
remote_project_store,
remote_project_path_input,
dev_server_store,
project_path_input,
dev_server_name_input,
_subscription: subscription,
}
}
pub fn create_remote_project(
pub fn create_dev_server_project(
&mut self,
dev_server_id: DevServerId,
cx: &mut ViewContext<Self>,
) {
let path = self
.remote_project_path_input
.project_path_input
.read(cx)
.editor()
.read(cx)
@ -108,9 +108,9 @@ impl RemoteProjects {
}
if self
.remote_project_store
.dev_server_store
.read(cx)
.remote_projects_for_server(dev_server_id)
.projects_for_server(dev_server_id)
.iter()
.any(|p| p.path == path)
{
@ -132,19 +132,22 @@ impl RemoteProjects {
let create = {
let path = path.clone();
self.remote_project_store.update(cx, |store, cx| {
store.create_remote_project(dev_server_id, path, cx)
self.dev_server_store.update(cx, |store, cx| {
store.create_dev_server_project(dev_server_id, path, cx)
})
};
cx.spawn(|this, mut cx| async move {
let result = create.await;
let remote_project = result.as_ref().ok().and_then(|r| r.remote_project.clone());
let dev_server_project = result
.as_ref()
.ok()
.and_then(|r| r.dev_server_project.clone());
this.update(&mut cx, |this, _| {
this.mode = Mode::CreateRemoteProject(CreateRemoteProject {
this.mode = Mode::CreateDevServerProject(CreateDevServerProject {
dev_server_id,
creating: false,
remote_project,
dev_server_project,
});
})
.log_err();
@ -156,23 +159,23 @@ impl RemoteProjects {
"The dev server is offline. Please log in and check it is connected."
.to_string(),
),
ErrorCode::RemoteProjectPathDoesNotExist => {
ErrorCode::DevServerProjectPathDoesNotExist => {
Some(format!("The path `{}` does not exist on the server.", path))
}
_ => None,
}
});
self.remote_project_path_input.update(cx, |input, cx| {
self.project_path_input.update(cx, |input, cx| {
input.editor().update(cx, |editor, cx| {
editor.set_text("", cx);
});
});
self.mode = Mode::CreateRemoteProject(CreateRemoteProject {
self.mode = Mode::CreateDevServerProject(CreateDevServerProject {
dev_server_id,
creating: true,
remote_project: None,
dev_server_project: None,
});
}
@ -191,7 +194,7 @@ impl RemoteProjects {
}
let dev_server = self
.remote_project_store
.dev_server_store
.update(cx, |store, cx| store.create_dev_server(name.clone(), cx));
cx.spawn(|this, mut cx| async move {
@ -236,7 +239,7 @@ impl RemoteProjects {
}
this.update(&mut cx, |this, cx| {
this.remote_project_store
this.dev_server_store
.update(cx, |store, cx| store.delete_dev_server(id, cx))
})?
.await
@ -247,8 +250,8 @@ impl RemoteProjects {
fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
match self.mode {
Mode::Default => {}
Mode::CreateRemoteProject(CreateRemoteProject { dev_server_id, .. }) => {
self.create_remote_project(dev_server_id, cx);
Mode::CreateDevServerProject(CreateDevServerProject { dev_server_id, .. }) => {
self.create_dev_server_project(dev_server_id, cx);
}
Mode::CreateDevServer(_) => {
self.create_dev_server(cx);
@ -259,7 +262,7 @@ impl RemoteProjects {
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
match self.mode {
Mode::Default => cx.emit(DismissEvent),
Mode::CreateRemoteProject(_) | Mode::CreateDevServer(_) => {
Mode::CreateDevServerProject(_) | Mode::CreateDevServer(_) => {
self.mode = Mode::Default;
self.focus_handle(cx).focus(cx);
cx.notify();
@ -338,15 +341,13 @@ impl RemoteProjects {
.tooltip(|cx| Tooltip::text("Add a remote project", cx))
.on_click(cx.listener(
move |this, _, cx| {
this.mode = Mode::CreateRemoteProject(CreateRemoteProject {
dev_server_id,
creating: false,
remote_project: None,
});
this.remote_project_path_input
.read(cx)
.focus_handle(cx)
.focus(cx);
this.mode =
Mode::CreateDevServerProject(CreateDevServerProject {
dev_server_id,
creating: false,
dev_server_project: None,
});
this.project_path_input.read(cx).focus_handle(cx).focus(cx);
cx.notify();
},
)),
@ -365,26 +366,26 @@ impl RemoteProjects {
.px_3()
.child(
List::new().empty_message("No projects.").children(
self.remote_project_store
self.dev_server_store
.read(cx)
.remote_projects_for_server(dev_server.id)
.projects_for_server(dev_server.id)
.iter()
.map(|p| self.render_remote_project(p, cx)),
.map(|p| self.render_dev_server_project(p, cx)),
),
),
)
}
fn render_remote_project(
fn render_dev_server_project(
&mut self,
project: &RemoteProject,
project: &DevServerProject,
cx: &mut ViewContext<Self>,
) -> impl IntoElement {
let remote_project_id = project.id;
let dev_server_project_id = project.id;
let project_id = project.project_id;
let is_online = project_id.is_some();
ListItem::new(("remote-project", remote_project_id.0))
ListItem::new(("remote-project", dev_server_project_id.0))
.start_slot(Icon::new(IconName::FileTree).when(!is_online, |icon| icon.color(Color::Muted)))
.child(
Label::new(project.path.clone())
@ -392,7 +393,7 @@ impl RemoteProjects {
.on_click(cx.listener(move |_, _, cx| {
if let Some(project_id) = project_id {
if let Some(app_state) = AppState::global(cx).upgrade() {
workspace::join_remote_project(project_id, app_state, None, cx)
workspace::join_dev_server_project(project_id, app_state, None, cx)
.detach_and_prompt_err("Could not join project", cx, |_, _| None)
}
} else {
@ -471,7 +472,7 @@ impl RemoteProjects {
})
.when_some(dev_server.clone(), |div, dev_server| {
let status = self
.remote_project_store
.dev_server_store
.read(cx)
.dev_server_status(DevServerId(dev_server.dev_server_id));
@ -556,7 +557,7 @@ impl RemoteProjects {
}
fn render_default(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let dev_servers = self.remote_project_store.read(cx).dev_servers();
let dev_servers = self.dev_server_store.read(cx).dev_servers();
v_flex()
.id("scroll-container")
@ -602,18 +603,18 @@ impl RemoteProjects {
)
}
fn render_create_remote_project(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let Mode::CreateRemoteProject(CreateRemoteProject {
fn render_create_dev_server_project(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let Mode::CreateDevServerProject(CreateDevServerProject {
dev_server_id,
creating,
remote_project,
dev_server_project,
}) = &self.mode
else {
unreachable!()
};
let dev_server = self
.remote_project_store
.dev_server_store
.read(cx)
.dev_server(*dev_server_id)
.cloned();
@ -672,12 +673,12 @@ impl RemoteProjects {
h_flex()
.ml_5()
.gap_2()
.child(self.remote_project_path_input.clone())
.when(!*creating && remote_project.is_none(), |div| {
.child(self.project_path_input.clone())
.when(!*creating && dev_server_project.is_none(), |div| {
div.child(Button::new("create-remote-server", "Create").on_click({
let dev_server_id = *dev_server_id;
cx.listener(move |this, _, cx| {
this.create_remote_project(dev_server_id, cx)
this.create_dev_server_project(dev_server_id, cx)
})
}))
})
@ -685,11 +686,11 @@ impl RemoteProjects {
div.child(Button::new("create-dev-server", "Creating...").disabled(true))
}),
)
.when_some(remote_project.clone(), |div, remote_project| {
.when_some(dev_server_project.clone(), |div, dev_server_project| {
let status = self
.remote_project_store
.dev_server_store
.read(cx)
.remote_project(RemoteProjectId(remote_project.id))
.dev_server_project(DevServerProjectId(dev_server_project.id))
.map(|project| {
if project.project_id.is_some() {
DevServerStatus::Online
@ -717,17 +718,17 @@ impl RemoteProjects {
})
}
}
impl ModalView for RemoteProjects {}
impl ModalView for DevServerProjects {}
impl FocusableView for RemoteProjects {
impl FocusableView for DevServerProjects {
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
self.focus_handle.clone()
}
}
impl EventEmitter<DismissEvent> for RemoteProjects {}
impl EventEmitter<DismissEvent> for DevServerProjects {}
impl Render for RemoteProjects {
impl Render for DevServerProjects {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
div()
.track_focus(&self.focus_handle)
@ -746,8 +747,8 @@ impl Render for RemoteProjects {
.max_h(rems(40.))
.child(match &self.mode {
Mode::Default => self.render_default(cx).into_any_element(),
Mode::CreateRemoteProject(_) => {
self.render_create_remote_project(cx).into_any_element()
Mode::CreateDevServerProject(_) => {
self.render_create_dev_server_project(cx).into_any_element()
}
Mode::CreateDevServer(_) => self.render_create_dev_server(cx).into_any_element(),
})

View file

@ -1,5 +1,6 @@
mod remote_projects;
mod dev_servers;
pub use dev_servers::DevServerProjects;
use feature_flags::FeatureFlagAppExt;
use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{
@ -11,7 +12,6 @@ use picker::{
highlighted_match_with_paths::{HighlightedMatchWithPaths, HighlightedText},
Picker, PickerDelegate,
};
pub use remote_projects::RemoteProjects;
use rpc::proto::DevServerStatus;
use serde::Deserialize;
use std::{
@ -42,8 +42,7 @@ gpui::actions!(projects, [OpenRemote]);
pub fn init(cx: &mut AppContext) {
cx.observe_new_views(RecentProjects::register).detach();
cx.observe_new_views(remote_projects::RemoteProjects::register)
.detach();
cx.observe_new_views(DevServerProjects::register).detach();
}
pub struct RecentProjects {
@ -158,7 +157,7 @@ pub struct RecentProjectsDelegate {
create_new_window: bool,
// Flag to reset index when there is a new query vs not reset index when user delete an item
reset_selected_match_index: bool,
has_any_remote_projects: bool,
has_any_dev_server_projects: bool,
}
impl RecentProjectsDelegate {
@ -171,16 +170,16 @@ impl RecentProjectsDelegate {
create_new_window,
render_paths,
reset_selected_match_index: true,
has_any_remote_projects: false,
has_any_dev_server_projects: false,
}
}
pub fn set_workspaces(&mut self, workspaces: Vec<(WorkspaceId, SerializedWorkspaceLocation)>) {
self.workspaces = workspaces;
self.has_any_remote_projects = self
self.has_any_dev_server_projects = self
.workspaces
.iter()
.any(|(_, location)| matches!(location, SerializedWorkspaceLocation::Remote(_)));
.any(|(_, location)| matches!(location, SerializedWorkspaceLocation::DevServer(_)));
}
}
impl EventEmitter<DismissEvent> for RecentProjectsDelegate {}
@ -235,8 +234,11 @@ impl PickerDelegate for RecentProjectsDelegate {
.map(|path| path.compact().to_string_lossy().into_owned())
.collect::<Vec<_>>()
.join(""),
SerializedWorkspaceLocation::Remote(remote_project) => {
format!("{}{}", remote_project.dev_server_name, remote_project.path)
SerializedWorkspaceLocation::DevServer(dev_server_project) => {
format!(
"{}{}",
dev_server_project.dev_server_name, dev_server_project.path
)
}
};
@ -310,13 +312,13 @@ impl PickerDelegate for RecentProjectsDelegate {
workspace.open_workspace_for_paths(false, paths, cx)
}
}
SerializedWorkspaceLocation::Remote(remote_project) => {
let store = ::remote_projects::Store::global(cx).read(cx);
SerializedWorkspaceLocation::DevServer(dev_server_project) => {
let store = dev_server_projects::Store::global(cx).read(cx);
let Some(project_id) = store
.remote_project(remote_project.id)
.dev_server_project(dev_server_project.id)
.and_then(|p| p.project_id)
else {
let dev_server_name = remote_project.dev_server_name.clone();
let dev_server_name = dev_server_project.dev_server_name.clone();
return cx.spawn(|workspace, mut cx| async move {
let response =
cx.prompt(gpui::PromptLevel::Warning,
@ -326,7 +328,7 @@ impl PickerDelegate for RecentProjectsDelegate {
).await?;
if response == 1 {
workspace.update(&mut cx, |workspace, cx| {
workspace.toggle_modal(cx, |cx| RemoteProjects::new(cx))
workspace.toggle_modal(cx, |cx| DevServerProjects::new(cx))
})?;
} else {
workspace.update(&mut cx, |workspace, cx| {
@ -354,7 +356,7 @@ impl PickerDelegate for RecentProjectsDelegate {
if continue_replacing {
workspace
.update(&mut cx, |_workspace, cx| {
workspace::join_remote_project(project_id, app_state, Some(handle), cx)
workspace::join_dev_server_project(project_id, app_state, Some(handle), cx)
})?
.await?;
}
@ -363,7 +365,7 @@ impl PickerDelegate for RecentProjectsDelegate {
}
else {
let task =
workspace::join_remote_project(project_id, app_state, None, cx);
workspace::join_dev_server_project(project_id, app_state, None, cx);
cx.spawn(|_, _| async move {
task.await?;
Ok(())
@ -404,13 +406,13 @@ impl PickerDelegate for RecentProjectsDelegate {
let (workspace_id, location) = &self.workspaces[hit.candidate_id];
let is_current_workspace = self.is_current_workspace(*workspace_id, cx);
let is_remote = matches!(location, SerializedWorkspaceLocation::Remote(_));
let is_remote = matches!(location, SerializedWorkspaceLocation::DevServer(_));
let dev_server_status =
if let SerializedWorkspaceLocation::Remote(remote_project) = location {
let store = ::remote_projects::Store::global(cx).read(cx);
if let SerializedWorkspaceLocation::DevServer(dev_server_project) = location {
let store = dev_server_projects::Store::global(cx).read(cx);
Some(
store
.remote_project(remote_project.id)
.dev_server_project(dev_server_project.id)
.and_then(|p| store.dev_server(p.dev_server_id))
.map(|s| s.status)
.unwrap_or_default(),
@ -422,9 +424,12 @@ impl PickerDelegate for RecentProjectsDelegate {
let mut path_start_offset = 0;
let paths = match location {
SerializedWorkspaceLocation::Local(paths) => paths.paths(),
SerializedWorkspaceLocation::Remote(remote_project) => Arc::new(vec![PathBuf::from(
format!("{}:{}", remote_project.dev_server_name, remote_project.path),
)]),
SerializedWorkspaceLocation::DevServer(dev_server_project) => {
Arc::new(vec![PathBuf::from(format!(
"{}:{}",
dev_server_project.dev_server_name, dev_server_project.path
))])
}
};
let (match_labels, paths): (Vec<_>, Vec<_>) = paths
@ -459,7 +464,7 @@ impl PickerDelegate for RecentProjectsDelegate {
h_flex()
.flex_grow()
.gap_3()
.when(self.has_any_remote_projects, |this| {
.when(self.has_any_dev_server_projects, |this| {
this.child(if is_remote {
// if disabled, Color::Disabled
let indicator_color = match dev_server_status {
@ -540,7 +545,7 @@ impl PickerDelegate for RecentProjectsDelegate {
.when_some(KeyBinding::for_action(&OpenRemote, cx), |button, key| {
button.child(key)
})
.child(Label::new("Connect remote").color(Color::Muted))
.child(Label::new("Connect").color(Color::Muted))
.on_click(|_, cx| cx.dispatch_action(OpenRemote.boxed_clone())),
)
.child(