Skip to content

Commit

Permalink
zzz
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneToIgnore committed Sep 25, 2024
1 parent 59dc398 commit 3b45bf6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 97 deletions.
108 changes: 15 additions & 93 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,29 +2060,22 @@ impl Project {
}
}
cx.observe(worktree, |_, _, cx| cx.notify()).detach();
cx.subscribe(worktree, |this, worktree, event, cx| {
let is_local = worktree.read(cx).is_local();
match event {
worktree::Event::UpdatedEntries(changes) => {
if is_local {
this.update_local_worktree_settings(&worktree, changes, cx);
}

cx.emit(Event::WorktreeUpdatedEntries(
worktree.read(cx).id(),
changes.clone(),
));

let worktree_id = worktree.update(cx, |worktree, _| worktree.id());
this.client()
.telemetry()
.report_discovered_project_events(worktree_id, changes);
}
worktree::Event::UpdatedGitRepositories(_) => {
cx.emit(Event::WorktreeUpdatedGitRepositories);
}
worktree::Event::DeletedEntry(id) => cx.emit(Event::DeletedEntry(*id)),
cx.subscribe(worktree, |this, worktree, event, cx| match event {
worktree::Event::UpdatedEntries(changes) => {
cx.emit(Event::WorktreeUpdatedEntries(
worktree.read(cx).id(),
changes.clone(),
));

let worktree_id = worktree.update(cx, |worktree, _| worktree.id());
this.client()
.telemetry()
.report_discovered_project_events(worktree_id, changes);
}
worktree::Event::UpdatedGitRepositories(_) => {
cx.emit(Event::WorktreeUpdatedGitRepositories);
}
worktree::Event::DeletedEntry(id) => cx.emit(Event::DeletedEntry(*id)),
})
.detach();
cx.notify();
Expand Down Expand Up @@ -3089,77 +3082,6 @@ impl Project {
});
}

fn update_local_worktree_settings(
&mut self,
worktree: &Model<Worktree>,
changes: &UpdatedEntriesSet,
cx: &mut ModelContext<Self>,
) {
if worktree.read(cx).is_remote() {
return;
}
let remote_worktree_id = worktree.read(cx).id();

for (path, _, change) in changes.iter() {
let removed = change == &PathChange::Removed;
let abs_path = match worktree.read(cx).absolutize(path) {
Ok(abs_path) => abs_path,
Err(e) => {
log::warn!("Cannot absolutize {path:?} received as {change:?} FS change: {e}");
continue;
}
};

if path.ends_with(local_tasks_file_relative_path()) {
self.task_inventory().update(cx, |task_inventory, cx| {
if removed {
task_inventory.remove_local_static_source(&abs_path);
} else {
let fs = self.fs.clone();
let task_abs_path = abs_path.clone();
let tasks_file_rx =
watch_config_file(cx.background_executor(), fs, task_abs_path);
task_inventory.add_source(
TaskSourceKind::Worktree {
id: remote_worktree_id,
abs_path,
id_base: "local_tasks_for_worktree".into(),
},
|tx, cx| StaticSource::new(TrackedFile::new(tasks_file_rx, tx, cx)),
cx,
);
}
})
} else if path.ends_with(local_vscode_tasks_file_relative_path()) {
self.task_inventory().update(cx, |task_inventory, cx| {
if removed {
task_inventory.remove_local_static_source(&abs_path);
} else {
let fs = self.fs.clone();
let task_abs_path = abs_path.clone();
let tasks_file_rx =
watch_config_file(cx.background_executor(), fs, task_abs_path);
task_inventory.add_source(
TaskSourceKind::Worktree {
id: remote_worktree_id,
abs_path,
id_base: "local_vscode_tasks_for_worktree".into(),
},
|tx, cx| {
StaticSource::new(TrackedFile::new_convertible::<
task::VsCodeTaskFile,
>(
tasks_file_rx, tx, cx
))
},
cx,
);
}
})
}
}
}

pub fn set_active_path(&mut self, entry: Option<ProjectPath>, cx: &mut ModelContext<Self>) {
let new_active_entry = entry.and_then(|project_path| {
let worktree = self.worktree_for_id(project_path.worktree_id, cx)?;
Expand Down
53 changes: 51 additions & 2 deletions crates/project/src/project_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use collections::HashMap;
use fs::Fs;
use gpui::{AppContext, AsyncAppContext, BorrowAppContext, EventEmitter, Model, ModelContext};
use language::LanguageServerName;
use paths::local_settings_file_relative_path;
use paths::{
local_settings_file_relative_path, local_tasks_file_relative_path,
local_vscode_tasks_file_relative_path,
};
use rpc::{proto, AnyProtoClient, TypedEnvelope};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -407,6 +410,52 @@ impl SettingsObserver {
},
)
});
} else if path.ends_with(local_tasks_file_relative_path()) {
self.task_inventory().update(cx, |task_inventory, cx| {
if removed {
task_inventory.remove_local_static_source(&abs_path);
} else {
let fs = self.fs.clone();
let task_abs_path = abs_path.clone();
let tasks_file_rx =
watch_config_file(cx.background_executor(), fs, task_abs_path);
task_inventory.add_source(
TaskSourceKind::Worktree {
id: remote_worktree_id,
abs_path,
id_base: "local_tasks_for_worktree".into(),
},
|tx, cx| StaticSource::new(TrackedFile::new(tasks_file_rx, tx, cx)),
cx,
);
}
})
} else if path.ends_with(local_vscode_tasks_file_relative_path()) {
self.task_inventory().update(cx, |task_inventory, cx| {
if removed {
task_inventory.remove_local_static_source(&abs_path);
} else {
let fs = self.fs.clone();
let task_abs_path = abs_path.clone();
let tasks_file_rx =
watch_config_file(cx.background_executor(), fs, task_abs_path);
task_inventory.add_source(
TaskSourceKind::Worktree {
id: remote_worktree_id,
abs_path,
id_base: "local_vscode_tasks_for_worktree".into(),
},
|tx, cx| {
StaticSource::new(TrackedFile::new_convertible::<
task::VsCodeTaskFile,
>(
tasks_file_rx, tx, cx
))
},
cx,
);
}
})
}
}

Expand Down Expand Up @@ -436,7 +485,7 @@ impl SettingsObserver {
fn update_settings(
&mut self,
worktree: Model<Worktree>,
settings_contents: impl IntoIterator<Item = (Arc<Path>, Option<String>)>,
settings_contents: impl IntoIterator<Item = (Arc<Path>, Option<String>, Kind)>,
cx: &mut ModelContext<Self>,
) {
let worktree_id = worktree.read(cx).id();
Expand Down
1 change: 1 addition & 0 deletions crates/remote_server/src/headless_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct HeadlessProject {
pub worktree_store: Model<WorktreeStore>,
pub buffer_store: Model<BufferStore>,
pub lsp_store: Model<LspStore>,
pub task_inventory: Model<TaskInventory>,
pub settings_observer: Model<SettingsObserver>,
pub next_entry_id: Arc<AtomicUsize>,
pub languages: Arc<LanguageRegistry>,
Expand Down
3 changes: 2 additions & 1 deletion crates/settings/src/settings_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ pub struct SettingsStore {
raw_user_settings: serde_json::Value,
raw_extension_settings: serde_json::Value,
raw_local_settings: BTreeMap<(WorktreeId, Arc<Path>), serde_json::Value>,
tab_size_callback: Option<(
raw_local_settings: BTreeMap<(WorktreeId, Arc<Path>), String>,
tab_size_c_editrallback: Option<(
TypeId,
Box<dyn Fn(&dyn Any) -> Option<usize> + Send + Sync + 'static>,
)>,
Expand Down
4 changes: 3 additions & 1 deletion crates/tasks_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ 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() || project.ssh_connection_string(cx).is_some()
project.is_local()
|| project.is_via_ssh()
|| project.ssh_connection_string(cx).is_some()
}) {
workspace.toggle_modal(cx, |cx| {
TasksModal::new(project, task_context, workspace_handle, cx)
Expand Down

0 comments on commit 3b45bf6

Please sign in to comment.