Add settings to remote servers, use XDG paths on remote, and enable node LSPs (#19176)

Supersedes https://github.com/zed-industries/zed/pull/19166

TODO:
- [x] Update basic zed paths
- [x] update create_state_directory
- [x] Use this with `NodeRuntime`
- [x] Add server settings
- [x] Add an 'open server settings command'
- [x] Make sure it all works


Release Notes:

- Updated the actions `zed::OpenLocalSettings` and `zed::OpenLocalTasks`
to `zed::OpenProjectSettings` and `zed::OpenProjectTasks`.

---------

Co-authored-by: Conrad <conrad@zed.dev>
Co-authored-by: Richard <richard@zed.dev>
This commit is contained in:
Mikayla Maki 2024-10-15 23:32:44 -07:00 committed by GitHub
parent 1dda039f38
commit f944ebc4cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 804 additions and 218 deletions

View file

@ -222,8 +222,13 @@ pub enum Event {
LanguageServerAdded(LanguageServerId, LanguageServerName, Option<WorktreeId>),
LanguageServerRemoved(LanguageServerId),
LanguageServerLog(LanguageServerId, LanguageServerLogType, String),
Notification(String),
LocalSettingsUpdated(Result<(), InvalidSettingsError>),
Toast {
notification_id: SharedString,
message: String,
},
HideToast {
notification_id: SharedString,
},
LanguageServerPrompt(LanguageServerPromptRequest),
LanguageNotFound(Model<Buffer>),
ActiveEntryChanged(Option<ProjectEntryId>),
@ -633,7 +638,7 @@ impl Project {
prettier_store.clone(),
environment.clone(),
languages.clone(),
Some(client.http_client()),
client.http_client(),
fs.clone(),
cx,
)
@ -694,7 +699,7 @@ impl Project {
let snippets =
SnippetProvider::new(fs.clone(), BTreeSet::from_iter([global_snippets_dir]), cx);
let ssh_proto = ssh.read(cx).to_proto_client();
let ssh_proto = ssh.read(cx).proto_client();
let worktree_store =
cx.new_model(|_| WorktreeStore::remote(false, ssh_proto.clone(), 0, None));
cx.subscribe(&worktree_store, Self::on_worktree_store_event)
@ -703,7 +708,7 @@ impl Project {
let buffer_store = cx.new_model(|cx| {
BufferStore::remote(
worktree_store.clone(),
ssh.read(cx).to_proto_client(),
ssh.read(cx).proto_client(),
SSH_PROJECT_ID,
cx,
)
@ -716,7 +721,7 @@ impl Project {
fs.clone(),
buffer_store.downgrade(),
worktree_store.clone(),
ssh.read(cx).to_proto_client(),
ssh.read(cx).proto_client(),
SSH_PROJECT_ID,
cx,
)
@ -809,6 +814,8 @@ impl Project {
ssh_proto.add_model_message_handler(Self::handle_create_buffer_for_peer);
ssh_proto.add_model_message_handler(Self::handle_update_worktree);
ssh_proto.add_model_message_handler(Self::handle_update_project);
ssh_proto.add_model_message_handler(Self::handle_toast);
ssh_proto.add_model_message_handler(Self::handle_hide_toast);
ssh_proto.add_model_request_handler(BufferStore::handle_update_buffer);
BufferStore::init(&ssh_proto);
LspStore::init(&ssh_proto);
@ -2065,7 +2072,7 @@ impl Project {
if let Some(ref ssh_client) = self.ssh_client {
ssh_client
.read(cx)
.to_proto_client()
.proto_client()
.send(proto::CloseBuffer {
project_id: 0,
buffer_id: buffer_id.to_proto(),
@ -2136,7 +2143,10 @@ impl Project {
.ok();
}
}
LspStoreEvent::Notification(message) => cx.emit(Event::Notification(message.clone())),
LspStoreEvent::Notification(message) => cx.emit(Event::Toast {
notification_id: "lsp".into(),
message: message.clone(),
}),
LspStoreEvent::SnippetEdit {
buffer_id,
edits,
@ -2180,9 +2190,20 @@ impl Project {
cx: &mut ModelContext<Self>,
) {
match event {
SettingsObserverEvent::LocalSettingsUpdated(error) => {
cx.emit(Event::LocalSettingsUpdated(error.clone()))
}
SettingsObserverEvent::LocalSettingsUpdated(result) => match result {
Err(InvalidSettingsError::LocalSettings { message, path }) => {
let message =
format!("Failed to set local settings in {:?}:\n{}", path, message);
cx.emit(Event::Toast {
notification_id: "local-settings".into(),
message,
});
}
Ok(_) => cx.emit(Event::HideToast {
notification_id: "local-settings".into(),
}),
Err(_) => {}
},
}
}
@ -2262,7 +2283,7 @@ impl Project {
if let Some(ssh) = &self.ssh_client {
ssh.read(cx)
.to_proto_client()
.proto_client()
.send(proto::RemoveWorktree {
worktree_id: id_to_remove.to_proto(),
})
@ -2295,7 +2316,7 @@ impl Project {
if let Some(ssh) = &self.ssh_client {
ssh.read(cx)
.to_proto_client()
.proto_client()
.send(proto::UpdateBuffer {
project_id: 0,
buffer_id: buffer_id.to_proto(),
@ -2632,6 +2653,35 @@ impl Project {
})
}
pub fn open_server_settings(
&mut self,
cx: &mut ModelContext<Self>,
) -> Task<Result<Model<Buffer>>> {
let guard = self.retain_remotely_created_models(cx);
let Some(ssh_client) = self.ssh_client.as_ref() else {
return Task::ready(Err(anyhow!("not an ssh project")));
};
let proto_client = ssh_client.read(cx).proto_client();
cx.spawn(|this, mut cx| async move {
let buffer = proto_client
.request(proto::OpenServerSettings {
project_id: SSH_PROJECT_ID,
})
.await?;
let buffer = this
.update(&mut cx, |this, cx| {
anyhow::Ok(this.wait_for_remote_buffer(BufferId::new(buffer.buffer_id)?, cx))
})??
.await;
drop(guard);
buffer
})
}
pub fn open_local_buffer_via_lsp(
&mut self,
abs_path: lsp::Url,
@ -2982,7 +3032,7 @@ impl Project {
let (tx, rx) = smol::channel::unbounded();
let (client, remote_id): (AnyProtoClient, _) = if let Some(ssh_client) = &self.ssh_client {
(ssh_client.read(cx).to_proto_client(), 0)
(ssh_client.read(cx).proto_client(), 0)
} else if let Some(remote_id) = self.remote_id() {
(self.client.clone().into(), remote_id)
} else {
@ -3069,14 +3119,9 @@ impl Project {
visible: bool,
cx: &mut ModelContext<Self>,
) -> Task<Result<(Model<Worktree>, PathBuf)>> {
let abs_path = abs_path.as_ref();
if let Some((tree, relative_path)) = self.find_worktree(abs_path, cx) {
Task::ready(Ok((tree, relative_path)))
} else {
let worktree = self.create_worktree(abs_path, visible, cx);
cx.background_executor()
.spawn(async move { Ok((worktree.await?, PathBuf::new())) })
}
self.worktree_store.update(cx, |worktree_store, cx| {
worktree_store.find_or_create_worktree(abs_path, visible, cx)
})
}
pub fn find_worktree(
@ -3138,7 +3183,7 @@ impl Project {
} else if let Some(ssh_client) = self.ssh_client.as_ref() {
let request = ssh_client
.read(cx)
.to_proto_client()
.proto_client()
.request(proto::CheckFileExists {
project_id: SSH_PROJECT_ID,
path: path.to_string(),
@ -3215,7 +3260,7 @@ impl Project {
path: query,
};
let response = session.read(cx).to_proto_client().request(request);
let response = session.read(cx).proto_client().request(request);
cx.background_executor().spawn(async move {
let response = response.await?;
Ok(response.entries.into_iter().map(PathBuf::from).collect())
@ -3239,7 +3284,7 @@ impl Project {
}
}
fn create_worktree(
pub fn create_worktree(
&mut self,
abs_path: impl AsRef<Path>,
visible: bool,
@ -3544,6 +3589,33 @@ impl Project {
})?
}
async fn handle_toast(
this: Model<Self>,
envelope: TypedEnvelope<proto::Toast>,
mut cx: AsyncAppContext,
) -> Result<()> {
this.update(&mut cx, |_, cx| {
cx.emit(Event::Toast {
notification_id: envelope.payload.notification_id.into(),
message: envelope.payload.message,
});
Ok(())
})?
}
async fn handle_hide_toast(
this: Model<Self>,
envelope: TypedEnvelope<proto::HideToast>,
mut cx: AsyncAppContext,
) -> Result<()> {
this.update(&mut cx, |_, cx| {
cx.emit(Event::HideToast {
notification_id: envelope.payload.notification_id.into(),
});
Ok(())
})?
}
// Collab sends UpdateWorktree protos as messages
async fn handle_update_worktree(
this: Model<Self>,
@ -3572,7 +3644,7 @@ impl Project {
let mut payload = envelope.payload.clone();
payload.project_id = SSH_PROJECT_ID;
cx.background_executor()
.spawn(ssh.read(cx).to_proto_client().request(payload))
.spawn(ssh.read(cx).proto_client().request(payload))
.detach_and_log_err(cx);
}
this.buffer_store.clone()