Resolve prettier config on server init

This commit is contained in:
Kirill Bulatov 2023-09-22 15:52:34 +03:00
parent d021842fa1
commit f4667cbc33
3 changed files with 39 additions and 6 deletions

View file

@ -911,7 +911,7 @@ impl Project {
.detach();
}
// TODO kb restart all formatters if settings change
// TODO kb restart all default formatters if Zed prettier settings change
for (worktree, language, settings) in language_formatters_to_check {
self.maybe_start_default_formatters(worktree, &language, &settings, cx);
}
@ -5987,6 +5987,7 @@ impl Project {
this.update_local_worktree_buffers(&worktree, changes, cx);
this.update_local_worktree_language_servers(&worktree, changes, cx);
this.update_local_worktree_settings(&worktree, changes, cx);
this.update_prettier_settings(&worktree, changes, cx);
cx.emit(Event::WorktreeUpdatedEntries(
worktree.read(cx).id(),
changes.clone(),
@ -6366,6 +6367,27 @@ impl Project {
.detach();
}
fn update_prettier_settings(
&self,
worktree: &ModelHandle<Worktree>,
changes: &[(Arc<Path>, ProjectEntryId, PathChange)],
cx: &mut ModelContext<'_, Project>,
) {
let prettier_config_files = Prettier::CONFIG_FILE_NAMES
.iter()
.map(Path::new)
.collect::<HashSet<_>>();
let prettier_config_changes = changes
.iter()
.filter(|(path, _, _)| prettier_config_files.contains(path.as_ref()))
.collect::<Vec<_>>();
dbg!(prettier_config_changes);
dbg!(changes.len());
// TODO kb: reset caches for all worktree-related prettiers (including the default one) on prettier config file _changes_
// prepare node + prettier + plugins + prettier_server on files with Languages that have prettier formatter. Do not start it yet.
// !! Ignore **/node_modules/** files in both checks above.
}
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)?;