Skip to content

Commit

Permalink
ssh remoting: Fix cmd-o (#18308)
Browse files Browse the repository at this point in the history
Release Notes:

- ssh-remoting: Cmd-O now correctly opens files on the remote host

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
  • Loading branch information
ConradIrwin and mikayla-maki authored Sep 24, 2024
1 parent fdb03d3 commit d336005
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 91 deletions.
6 changes: 0 additions & 6 deletions crates/assistant/src/context_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,6 @@ impl ContextStore {
let Some(project_id) = project.remote_id() else {
return Task::ready(Err(anyhow!("project was not remote")));
};
if project.is_local_or_ssh() {
return Task::ready(Err(anyhow!("cannot create remote contexts as the host")));
}

let replica_id = project.replica_id();
let capability = project.capability();
Expand Down Expand Up @@ -488,9 +485,6 @@ impl ContextStore {
let Some(project_id) = project.remote_id() else {
return Task::ready(Err(anyhow!("project was not remote")));
};
if project.is_local_or_ssh() {
return Task::ready(Err(anyhow!("cannot open remote contexts as the host")));
}

if let Some(context) = self.loaded_context_for_id(&context_id, cx) {
return Task::ready(Ok(context));
Expand Down
11 changes: 4 additions & 7 deletions crates/collab/src/tests/random_project_collaboration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ impl RandomizedTest for ProjectCollaborationTest {
continue;
};
let project_root_name = root_name_for_project(&project, cx);
let is_local =
project.read_with(cx, |project, _| project.is_local_or_ssh());
let is_local = project.read_with(cx, |project, _| project.is_local());
let worktree = project.read_with(cx, |project, cx| {
project
.worktrees(cx)
Expand Down Expand Up @@ -335,7 +334,7 @@ impl RandomizedTest for ProjectCollaborationTest {
continue;
};
let project_root_name = root_name_for_project(&project, cx);
let is_local = project.read_with(cx, |project, _| project.is_local_or_ssh());
let is_local = project.read_with(cx, |project, _| project.is_local());

match rng.gen_range(0..100_u32) {
// Manipulate an existing buffer
Expand Down Expand Up @@ -1256,7 +1255,7 @@ impl RandomizedTest for ProjectCollaborationTest {
let buffers = client.buffers().clone();
for (guest_project, guest_buffers) in &buffers {
let project_id = if guest_project.read_with(client_cx, |project, _| {
project.is_local_or_ssh() || project.is_disconnected()
project.is_local() || project.is_disconnected()
}) {
continue;
} else {
Expand Down Expand Up @@ -1560,9 +1559,7 @@ async fn ensure_project_shared(
let first_root_name = root_name_for_project(project, cx);
let active_call = cx.read(ActiveCall::global);
if active_call.read_with(cx, |call, _| call.room().is_some())
&& project.read_with(cx, |project, _| {
project.is_local_or_ssh() && !project.is_shared()
})
&& project.read_with(cx, |project, _| project.is_local() && !project.is_shared())
{
match active_call
.update(cx, |call, cx| call.share_project(project.clone(), cx))
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11819,7 +11819,7 @@ impl Editor {
.filter_map(|buffer| {
let buffer = buffer.read(cx);
let language = buffer.language()?;
if project.is_local_or_ssh()
if project.is_local()
&& project.language_servers_for_buffer(buffer, cx).count() == 0
{
None
Expand Down
69 changes: 29 additions & 40 deletions crates/feedback/src/feedback_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use regex::Regex;
use serde_derive::Serialize;
use ui::{prelude::*, Button, ButtonStyle, IconPosition, Tooltip};
use util::ResultExt;
use workspace::notifications::NotificationId;
use workspace::{DismissDecision, ModalView, Toast, Workspace};
use workspace::{DismissDecision, ModalView, Workspace};

use crate::{system_specs::SystemSpecs, GiveFeedback, OpenZedRepo};

Expand Down Expand Up @@ -120,44 +119,34 @@ impl FeedbackModal {
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
let _handle = cx.view().downgrade();
workspace.register_action(move |workspace, _: &GiveFeedback, cx| {
let markdown = workspace
.app_state()
.languages
.language_for_name("Markdown");

let project = workspace.project().clone();
let is_local_project = project.read(cx).is_local_or_ssh();

if !is_local_project {
struct FeedbackInRemoteProject;

workspace.show_toast(
Toast::new(
NotificationId::unique::<FeedbackInRemoteProject>(),
"You can only submit feedback in your own project.",
),
cx,
);
return;
}

let system_specs = SystemSpecs::new(cx);
cx.spawn(|workspace, mut cx| async move {
let markdown = markdown.await.log_err();
let buffer = project.update(&mut cx, |project, cx| {
project.create_local_buffer("", markdown, cx)
})?;
let system_specs = system_specs.await;

workspace.update(&mut cx, |workspace, cx| {
workspace.toggle_modal(cx, move |cx| {
FeedbackModal::new(system_specs, project, buffer, cx)
});
})?;

anyhow::Ok(())
})
.detach_and_log_err(cx);
workspace
.with_local_workspace(cx, |workspace, cx| {
let markdown = workspace
.app_state()
.languages
.language_for_name("Markdown");

let project = workspace.project().clone();

let system_specs = SystemSpecs::new(cx);
cx.spawn(|workspace, mut cx| async move {
let markdown = markdown.await.log_err();
let buffer = project.update(&mut cx, |project, cx| {
project.create_local_buffer("", markdown, cx)
})?;
let system_specs = system_specs.await;

workspace.update(&mut cx, |workspace, cx| {
workspace.toggle_modal(cx, move |cx| {
FeedbackModal::new(system_specs, project, buffer, cx)
});
})?;

anyhow::Ok(())
})
.detach_and_log_err(cx);
})
.detach_and_log_err(cx);
});
}

Expand Down
2 changes: 1 addition & 1 deletion crates/file_finder/src/file_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ impl PickerDelegate for FileFinderDelegate {
project
.worktree_for_id(history_item.project.worktree_id, cx)
.is_some()
|| (project.is_local_or_ssh() && history_item.absolute.is_some())
|| (project.is_local() && history_item.absolute.is_some())
}),
self.currently_opened_path.as_ref(),
None,
Expand Down
4 changes: 2 additions & 2 deletions crates/language_tools/src/lsp_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub fn init(cx: &mut AppContext) {

cx.observe_new_views(move |workspace: &mut Workspace, cx| {
let project = workspace.project();
if project.read(cx).is_local_or_ssh() {
if project.read(cx).is_local() {
log_store.update(cx, |store, cx| {
store.add_project(project, cx);
});
Expand All @@ -193,7 +193,7 @@ pub fn init(cx: &mut AppContext) {
let log_store = log_store.clone();
workspace.register_action(move |workspace, _: &OpenLanguageServerLogs, cx| {
let project = workspace.project().read(cx);
if project.is_local_or_ssh() {
if project.is_local() {
workspace.add_item_to_active_pane(
Box::new(cx.new_view(|cx| {
LspLogView::new(workspace.project().clone(), log_store.clone(), cx)
Expand Down
2 changes: 1 addition & 1 deletion crates/outline_panel/src/outline_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3909,7 +3909,7 @@ impl Render for OutlinePanel {
.when(project.is_local(), |el| {
el.on_action(cx.listener(Self::reveal_in_finder))
})
.when(project.is_local_or_ssh(), |el| {
.when(project.is_local() || project.is_via_ssh(), |el| {
el.on_action(cx.listener(Self::open_in_terminal))
})
.on_mouse_down(
Expand Down
46 changes: 26 additions & 20 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl DirectoryLister {
pub fn is_local(&self, cx: &AppContext) -> bool {
match self {
DirectoryLister::Local(_) => true,
DirectoryLister::Project(project) => project.read(cx).is_local_or_ssh(),
DirectoryLister::Project(project) => project.read(cx).is_local(),
}
}

Expand Down Expand Up @@ -1199,7 +1199,13 @@ impl Project {
self.dev_server_project_id
}

pub fn supports_remote_terminal(&self, cx: &AppContext) -> bool {
pub fn supports_terminal(&self, cx: &AppContext) -> bool {
if self.is_local() {
return true;
}
if self.is_via_ssh() {
return true;
}
let Some(id) = self.dev_server_project_id else {
return false;
};
Expand All @@ -1213,10 +1219,6 @@ impl Project {
}

pub fn ssh_connection_string(&self, cx: &ModelContext<Self>) -> Option<SharedString> {
if self.is_local_or_ssh() {
return None;
}

let dev_server_id = self.dev_server_project_id()?;
dev_server_projects::Store::global(cx)
.read(cx)
Expand Down Expand Up @@ -1643,13 +1645,6 @@ impl Project {
}
}

pub fn is_local_or_ssh(&self) -> bool {
match &self.client_state {
ProjectClientState::Local | ProjectClientState::Shared { .. } => true,
ProjectClientState::Remote { .. } => false,
}
}

pub fn is_via_ssh(&self) -> bool {
match &self.client_state {
ProjectClientState::Local | ProjectClientState::Shared { .. } => {
Expand Down Expand Up @@ -1735,7 +1730,7 @@ impl Project {
) -> Task<Result<Model<Buffer>>> {
if let Some(buffer) = self.buffer_for_id(id, cx) {
Task::ready(Ok(buffer))
} else if self.is_local_or_ssh() {
} else if self.is_local() || self.is_via_ssh() {
Task::ready(Err(anyhow!("buffer {} does not exist", id)))
} else if let Some(project_id) = self.remote_id() {
let request = self.client.request(proto::OpenBufferById {
Expand Down Expand Up @@ -1857,7 +1852,7 @@ impl Project {
let mut changes = rx.ready_chunks(MAX_BATCH_SIZE);

while let Some(changes) = changes.next().await {
let is_local = this.update(&mut cx, |this, _| this.is_local_or_ssh())?;
let is_local = this.update(&mut cx, |this, _| this.is_local())?;

for change in changes {
match change {
Expand Down Expand Up @@ -2001,7 +1996,7 @@ impl Project {
language_server_id,
message,
} => {
if self.is_local_or_ssh() {
if self.is_local() {
self.enqueue_buffer_ordered_message(
BufferOrderedMessage::LanguageServerUpdate {
language_server_id: *language_server_id,
Expand Down Expand Up @@ -3039,8 +3034,19 @@ impl Project {
query: String,
cx: &mut ModelContext<Self>,
) -> Task<Result<Vec<PathBuf>>> {
if self.is_local_or_ssh() {
if self.is_local() {
DirectoryLister::Local(self.fs.clone()).list_directory(query, cx)
} else if let Some(session) = self.ssh_session.as_ref() {
let request = proto::ListRemoteDirectory {
dev_server_id: SSH_PROJECT_ID,
path: query,
};

let response = session.request(request);
cx.background_executor().spawn(async move {
let response = response.await?;
Ok(response.entries.into_iter().map(PathBuf::from).collect())
})
} else if let Some(dev_server) = self.dev_server_project_id().and_then(|id| {
dev_server_projects::Store::global(cx)
.read(cx)
Expand Down Expand Up @@ -3317,7 +3323,7 @@ impl Project {
mut cx: AsyncAppContext,
) -> Result<()> {
this.update(&mut cx, |this, cx| {
if this.is_local_or_ssh() {
if this.is_local() || this.is_via_ssh() {
this.unshare(cx)?;
} else {
this.disconnected_from_host(cx);
Expand Down Expand Up @@ -3995,7 +4001,7 @@ impl Project {
location: Location,
cx: &mut ModelContext<'_, Project>,
) -> Task<Option<TaskContext>> {
if self.is_local_or_ssh() {
if self.is_local() {
let (worktree_id, worktree_abs_path) = if let Some(worktree) = self.task_worktree(cx) {
(
Some(worktree.read(cx).id()),
Expand Down Expand Up @@ -4081,7 +4087,7 @@ impl Project {
location: Option<Location>,
cx: &mut ModelContext<Self>,
) -> Task<Result<Vec<(TaskSourceKind, TaskTemplate)>>> {
if self.is_local_or_ssh() {
if self.is_local() {
let (file, language) = location
.map(|location| {
let buffer = location.buffer.read(cx);
Expand Down
5 changes: 4 additions & 1 deletion crates/project_panel/src/project_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2722,11 +2722,14 @@ impl Render for ProjectPanel {
}
}))
})
.when(project.is_local_or_ssh(), |el| {
.when(project.is_local(), |el| {
el.on_action(cx.listener(Self::reveal_in_finder))
.on_action(cx.listener(Self::open_system))
.on_action(cx.listener(Self::open_in_terminal))
})
.when(project.is_via_ssh(), |el| {
el.on_action(cx.listener(Self::open_in_terminal))
})
.on_mouse_down(
MouseButton::Right,
cx.listener(move |this, event: &MouseDownEvent, cx| {
Expand Down
2 changes: 1 addition & 1 deletion crates/tasks_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn toggle_modal(workspace: &mut Workspace, cx: &mut ViewContext<'_, Workspace>)
workspace
.update(&mut cx, |workspace, cx| {
if workspace.project().update(cx, |project, cx| {
project.is_local_or_ssh() || project.ssh_connection_string(cx).is_some()
project.is_local() || project.ssh_connection_string(cx).is_some()
}) {
workspace.toggle_modal(cx, |cx| {
TasksModal::new(project, task_context, workspace_handle, cx)
Expand Down
2 changes: 1 addition & 1 deletion crates/tasks_ui/src/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl PickerDelegate for TasksModalDelegate {
if project.is_via_collab() && ssh_connection_string.is_none() {
Task::ready((Vec::new(), Vec::new()))
} else {
let remote_templates = if project.is_local_or_ssh() {
let remote_templates = if project.is_local() {
None
} else {
project
Expand Down
2 changes: 1 addition & 1 deletion crates/terminal_view/src/terminal_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl TerminalPanel {
cx.subscribe(&pane, Self::handle_pane_event),
];
let project = workspace.project().read(cx);
let enabled = project.is_local_or_ssh() || project.supports_remote_terminal(cx);
let enabled = project.supports_terminal(cx);
let this = Self {
pane,
fs: workspace.app_state().fs.clone(),
Expand Down
8 changes: 4 additions & 4 deletions crates/title_bar/src/collab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,22 +284,22 @@ impl TitleBar {

let room = room.read(cx);
let project = self.project.read(cx);
let is_local = project.is_local_or_ssh();
let is_dev_server_project = project.dev_server_project_id().is_some();
let is_shared = (is_local || is_dev_server_project) && project.is_shared();
let is_shared = project.is_shared();
let is_muted = room.is_muted();
let is_deafened = room.is_deafened().unwrap_or(false);
let is_screen_sharing = room.is_screen_sharing();
let can_use_microphone = room.can_use_microphone();
let can_share_projects = room.can_share_projects();
let can_share_projects = room.can_share_projects()
&& (is_dev_server_project || project.is_local() || project.is_via_ssh());
let platform_supported = match self.platform_style {
PlatformStyle::Mac => true,
PlatformStyle::Linux | PlatformStyle::Windows => false,
};

let mut children = Vec::new();

if (is_local || is_dev_server_project) && can_share_projects {
if can_share_projects {
children.push(
Button::new(
"toggle_sharing",
Expand Down
Loading

0 comments on commit d336005

Please sign in to comment.