Do not attempt to install prettier if the language change is unrelated (#19283)

Kirill Bulatov created

Release Notes:

- Fix prettier install being attempted too much

Change summary

crates/project/src/lsp_store.rs      | 23 +++++++++++++----------
crates/project/src/prettier_store.rs | 12 +++++++-----
2 files changed, 20 insertions(+), 15 deletions(-)

Detailed changes

crates/project/src/lsp_store.rs 🔗

@@ -1237,16 +1237,19 @@ impl LspStore {
             None
         };
 
-        if let Some(prettier_plugins) = prettier_store::prettier_plugins_for_language(&settings) {
-            let prettier_store = self.as_local().map(|s| s.prettier_store.clone());
-            if let Some(prettier_store) = prettier_store {
-                prettier_store.update(cx, |prettier_store, cx| {
-                    prettier_store.install_default_prettier(
-                        worktree_id,
-                        prettier_plugins.iter().map(|s| Arc::from(s.as_str())),
-                        cx,
-                    )
-                })
+        if settings.prettier.allowed {
+            if let Some(prettier_plugins) = prettier_store::prettier_plugins_for_language(&settings)
+            {
+                let prettier_store = self.as_local().map(|s| s.prettier_store.clone());
+                if let Some(prettier_store) = prettier_store {
+                    prettier_store.update(cx, |prettier_store, cx| {
+                        prettier_store.install_default_prettier(
+                            worktree_id,
+                            prettier_plugins.iter().map(|s| Arc::from(s.as_str())),
+                            cx,
+                        )
+                    })
+                }
             }
         }
 

crates/project/src/prettier_store.rs 🔗

@@ -610,11 +610,13 @@ impl PrettierStore {
     ) {
         let mut prettier_plugins_by_worktree = HashMap::default();
         for (worktree, language_settings) in language_formatters_to_check {
-            if let Some(plugins) = prettier_plugins_for_language(&language_settings) {
-                prettier_plugins_by_worktree
-                    .entry(worktree)
-                    .or_insert_with(HashSet::default)
-                    .extend(plugins.iter().cloned());
+            if language_settings.prettier.allowed {
+                if let Some(plugins) = prettier_plugins_for_language(&language_settings) {
+                    prettier_plugins_by_worktree
+                        .entry(worktree)
+                        .or_insert_with(HashSet::default)
+                        .extend(plugins.iter().cloned());
+                }
             }
         }
         for (worktree, prettier_plugins) in prettier_plugins_by_worktree {