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:
parent
1dda039f38
commit
f944ebc4cb
44 changed files with 804 additions and 218 deletions
|
@ -27,7 +27,7 @@ use gpui::{
|
|||
AppContext, AsyncAppContext, Context, Entity, EventEmitter, Model, ModelContext, PromptLevel,
|
||||
Task, WeakModel,
|
||||
};
|
||||
use http_client::{BlockedHttpClient, HttpClient};
|
||||
use http_client::HttpClient;
|
||||
use language::{
|
||||
language_settings::{
|
||||
all_language_settings, language_settings, AllLanguageSettings, FormatOnSave, Formatter,
|
||||
|
@ -116,7 +116,7 @@ impl FormatTrigger {
|
|||
}
|
||||
|
||||
pub struct LocalLspStore {
|
||||
http_client: Option<Arc<dyn HttpClient>>,
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
environment: Model<ProjectEnvironment>,
|
||||
fs: Arc<dyn Fs>,
|
||||
yarn: Model<YarnPathStore>,
|
||||
|
@ -839,7 +839,7 @@ impl LspStore {
|
|||
prettier_store: Model<PrettierStore>,
|
||||
environment: Model<ProjectEnvironment>,
|
||||
languages: Arc<LanguageRegistry>,
|
||||
http_client: Option<Arc<dyn HttpClient>>,
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
fs: Arc<dyn Fs>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Self {
|
||||
|
@ -7579,10 +7579,7 @@ impl LocalLspAdapterDelegate {
|
|||
.as_local()
|
||||
.expect("LocalLspAdapterDelegate cannot be constructed on a remote");
|
||||
|
||||
let http_client = local
|
||||
.http_client
|
||||
.clone()
|
||||
.unwrap_or_else(|| Arc::new(BlockedHttpClient));
|
||||
let http_client = local.http_client.clone();
|
||||
|
||||
Self::new(lsp_store, worktree, http_client, local.fs.clone(), cx)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -538,26 +538,47 @@ impl SettingsObserver {
|
|||
let task_store = self.task_store.clone();
|
||||
|
||||
for (directory, kind, file_content) in settings_contents {
|
||||
let result = match kind {
|
||||
match kind {
|
||||
LocalSettingsKind::Settings | LocalSettingsKind::Editorconfig => cx
|
||||
.update_global::<SettingsStore, anyhow::Result<()>>(|store, cx| {
|
||||
store.set_local_settings(
|
||||
.update_global::<SettingsStore, _>(|store, cx| {
|
||||
let result = store.set_local_settings(
|
||||
worktree_id,
|
||||
directory.clone(),
|
||||
kind,
|
||||
file_content.as_deref(),
|
||||
cx,
|
||||
)
|
||||
);
|
||||
|
||||
match result {
|
||||
Err(InvalidSettingsError::LocalSettings { path, message }) => {
|
||||
log::error!(
|
||||
"Failed to set local settings in {:?}: {:?}",
|
||||
path,
|
||||
message
|
||||
);
|
||||
cx.emit(SettingsObserverEvent::LocalSettingsUpdated(Err(
|
||||
InvalidSettingsError::LocalSettings { path, message },
|
||||
)));
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to set local settings: {e}");
|
||||
}
|
||||
Ok(_) => {
|
||||
cx.emit(SettingsObserverEvent::LocalSettingsUpdated(Ok(())));
|
||||
}
|
||||
}
|
||||
}),
|
||||
LocalSettingsKind::Tasks => task_store.update(cx, |task_store, cx| {
|
||||
task_store.update_user_tasks(
|
||||
Some(SettingsLocation {
|
||||
worktree_id,
|
||||
path: directory.as_ref(),
|
||||
}),
|
||||
file_content.as_deref(),
|
||||
cx,
|
||||
)
|
||||
task_store
|
||||
.update_user_tasks(
|
||||
Some(SettingsLocation {
|
||||
worktree_id,
|
||||
path: directory.as_ref(),
|
||||
}),
|
||||
file_content.as_deref(),
|
||||
cx,
|
||||
)
|
||||
.log_err();
|
||||
}),
|
||||
};
|
||||
|
||||
|
@ -572,28 +593,6 @@ impl SettingsObserver {
|
|||
})
|
||||
.log_err();
|
||||
}
|
||||
|
||||
match result {
|
||||
Err(error) => {
|
||||
if let Ok(error) = error.downcast::<InvalidSettingsError>() {
|
||||
if let InvalidSettingsError::LocalSettings {
|
||||
ref path,
|
||||
ref message,
|
||||
} = error
|
||||
{
|
||||
log::error!(
|
||||
"Failed to set local settings in {:?}: {:?}",
|
||||
path,
|
||||
message
|
||||
);
|
||||
cx.emit(SettingsObserverEvent::LocalSettingsUpdated(Err(error)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(()) => {
|
||||
cx.emit(SettingsObserverEvent::LocalSettingsUpdated(Ok(())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -298,9 +298,10 @@ impl TaskStore {
|
|||
let result = task_store.update_user_tasks(None, Some(&user_tasks_content), cx);
|
||||
if let Err(err) = &result {
|
||||
log::error!("Failed to load user tasks: {err}");
|
||||
cx.emit(crate::Event::Notification(format!(
|
||||
"Invalid global tasks file\n{err}"
|
||||
)));
|
||||
cx.emit(crate::Event::Toast {
|
||||
notification_id: "load-user-tasks".into(),
|
||||
message: format!("Invalid global tasks file\n{err}"),
|
||||
});
|
||||
}
|
||||
cx.refresh();
|
||||
}) else {
|
||||
|
|
|
@ -367,7 +367,11 @@ pub fn wrap_for_ssh(
|
|||
// replace ith with something that works
|
||||
let tilde_prefix = "~/";
|
||||
if path.starts_with(tilde_prefix) {
|
||||
let trimmed_path = &path_string[tilde_prefix.len()..];
|
||||
let trimmed_path = path_string
|
||||
.trim_start_matches("/")
|
||||
.trim_start_matches("~")
|
||||
.trim_start_matches("/");
|
||||
|
||||
format!("cd \"$HOME/{trimmed_path}\"; {env_changes} {to_run}")
|
||||
} else {
|
||||
format!("cd {path:?}; {env_changes} {to_run}")
|
||||
|
|
|
@ -153,6 +153,22 @@ impl WorktreeStore {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn find_or_create_worktree(
|
||||
&mut self,
|
||||
abs_path: impl AsRef<Path>,
|
||||
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())) })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn entry_for_id<'a>(
|
||||
&'a self,
|
||||
entry_id: ProjectEntryId,
|
||||
|
@ -957,7 +973,7 @@ impl WorktreeStore {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
enum WorktreeHandle {
|
||||
Strong(Model<Worktree>),
|
||||
Weak(WeakModel<Worktree>),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue