Watch for prettier file changes
This commit is contained in:
parent
f4667cbc33
commit
b109075bf2
1 changed files with 53 additions and 7 deletions
|
@ -6377,15 +6377,58 @@ impl Project {
|
||||||
.iter()
|
.iter()
|
||||||
.map(Path::new)
|
.map(Path::new)
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
let prettier_config_changes = changes
|
|
||||||
|
let prettier_config_file_changed = changes
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(path, _, _)| prettier_config_files.contains(path.as_ref()))
|
.filter(|(_, _, change)| !matches!(change, PathChange::Loaded))
|
||||||
|
.filter(|(path, _, _)| {
|
||||||
|
!path
|
||||||
|
.components()
|
||||||
|
.any(|component| component.as_os_str().to_str() == Some("node_modules"))
|
||||||
|
})
|
||||||
|
.find(|(path, _, _)| prettier_config_files.contains(path.as_ref()));
|
||||||
|
let current_worktree_id = worktree.read(cx).id();
|
||||||
|
if let Some((config_path, _, _)) = prettier_config_file_changed {
|
||||||
|
log::info!(
|
||||||
|
"Prettier config file {config_path:?} changed, reloading prettier instances for worktree {current_worktree_id}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let prettiers_to_reload = self
|
||||||
|
.prettier_instances
|
||||||
|
.iter()
|
||||||
|
.filter_map(|((worktree_id, prettier_path), prettier_task)| {
|
||||||
|
if worktree_id.is_none() || worktree_id == &Some(current_worktree_id) {
|
||||||
|
Some((*worktree_id, prettier_path.clone(), prettier_task.clone()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
dbg!(prettier_config_changes);
|
|
||||||
dbg!(changes.len());
|
cx.background()
|
||||||
// TODO kb: reset caches for all worktree-related prettiers (including the default one) on prettier config file _changes_
|
.spawn(async move {
|
||||||
// prepare node + prettier + plugins + prettier_server on files with Languages that have prettier formatter. Do not start it yet.
|
for task_result in future::join_all(prettiers_to_reload.into_iter().map(|(worktree_id, prettier_path, prettier_task)| {
|
||||||
// !! Ignore **/node_modules/** files in both checks above.
|
async move {
|
||||||
|
prettier_task.await?
|
||||||
|
.clear_cache()
|
||||||
|
.await
|
||||||
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"clearing prettier {prettier_path:?} cache for worktree {worktree_id:?}"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.map_err(Arc::new)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
if let Err(e) = task_result {
|
||||||
|
log::error!("Failed to clear cache for prettier: {e:#}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_active_path(&mut self, entry: Option<ProjectPath>, cx: &mut ModelContext<Self>) {
|
pub fn set_active_path(&mut self, entry: Option<ProjectPath>, cx: &mut ModelContext<Self>) {
|
||||||
|
@ -8305,6 +8348,7 @@ impl Project {
|
||||||
return existing_prettier;
|
return existing_prettier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log::info!("Found prettier at {prettier_dir:?}, starting.");
|
||||||
let task_prettier_dir = prettier_dir.clone();
|
let task_prettier_dir = prettier_dir.clone();
|
||||||
let weak_project = this.downgrade();
|
let weak_project = this.downgrade();
|
||||||
let new_server_id =
|
let new_server_id =
|
||||||
|
@ -8321,6 +8365,8 @@ impl Project {
|
||||||
.await
|
.await
|
||||||
.context("prettier start")
|
.context("prettier start")
|
||||||
.map_err(Arc::new)?;
|
.map_err(Arc::new)?;
|
||||||
|
log::info!("Had started prettier in {:?}", prettier.prettier_dir());
|
||||||
|
|
||||||
if let Some(project) = weak_project.upgrade(&mut cx) {
|
if let Some(project) = weak_project.upgrade(&mut cx) {
|
||||||
project.update(&mut cx, |project, cx| {
|
project.update(&mut cx, |project, cx| {
|
||||||
let name = if prettier.is_default() {
|
let name = if prettier.is_default() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue