Merge branch 'main' of github.com:zed-industries/zed into vector_store

KCaverly created

Change summary

crates/command_palette/src/command_palette.rs |  1 
crates/language/src/language.rs               | 28 ------------
crates/project/src/project.rs                 | 45 +++++++++++++++-----
crates/terminal_view/src/terminal_panel.rs    |  8 +++
crates/terminal_view/src/terminal_view.rs     |  3 
crates/workspace/src/item.rs                  |  2 
crates/workspace/src/pane.rs                  |  1 
7 files changed, 47 insertions(+), 41 deletions(-)

Detailed changes

crates/language/src/language.rs 🔗

@@ -90,8 +90,7 @@ pub struct LanguageServerName(pub Arc<str>);
 /// once at startup, and caches the results.
 pub struct CachedLspAdapter {
     pub name: LanguageServerName,
-    initialization_options: Option<Value>,
-    initialization_overrides: Mutex<Option<Value>>,
+    pub initialization_options: Option<Value>,
     pub disk_based_diagnostic_sources: Vec<String>,
     pub disk_based_diagnostics_progress_token: Option<String>,
     pub language_ids: HashMap<String, String>,
@@ -110,7 +109,6 @@ impl CachedLspAdapter {
         Arc::new(CachedLspAdapter {
             name,
             initialization_options,
-            initialization_overrides: Mutex::new(None),
             disk_based_diagnostic_sources,
             disk_based_diagnostics_progress_token,
             language_ids,
@@ -210,30 +208,6 @@ impl CachedLspAdapter {
     ) -> Option<CodeLabel> {
         self.adapter.label_for_symbol(name, kind, language).await
     }
-
-    pub fn update_initialization_overrides(&self, new: Option<&Value>) -> bool {
-        let mut current = self.initialization_overrides.lock();
-        if current.as_ref() != new {
-            *current = new.cloned();
-            true
-        } else {
-            false
-        }
-    }
-
-    pub fn initialization_options(&self) -> Option<Value> {
-        let initialization_options = self.initialization_options.as_ref();
-        let override_options = self.initialization_overrides.lock().clone();
-        match (initialization_options, override_options) {
-            (None, override_options) => override_options,
-            (initialization_options, None) => initialization_options.cloned(),
-            (Some(initialization_options), Some(override_options)) => {
-                let mut initialization_options = initialization_options.clone();
-                merge_json_value_into(override_options, &mut initialization_options);
-                Some(initialization_options)
-            }
-        }
-    }
 }
 
 pub trait LspAdapterDelegate: Send + Sync {

crates/project/src/project.rs 🔗

@@ -50,7 +50,7 @@ use lsp::{
 };
 use lsp_command::*;
 use postage::watch;
-use project_settings::ProjectSettings;
+use project_settings::{LspSettings, ProjectSettings};
 use rand::prelude::*;
 use search::SearchQuery;
 use serde::Serialize;
@@ -78,8 +78,8 @@ use std::{
 use terminals::Terminals;
 use text::Anchor;
 use util::{
-    debug_panic, defer, http::HttpClient, paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt,
-    TryFutureExt as _,
+    debug_panic, defer, http::HttpClient, merge_json_value_into,
+    paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt, TryFutureExt as _,
 };
 
 pub use fs::*;
@@ -149,6 +149,7 @@ pub struct Project {
     _maintain_workspace_config: Task<()>,
     terminals: Terminals,
     copilot_enabled: bool,
+    current_lsp_settings: HashMap<Arc<str>, LspSettings>,
 }
 
 struct DelayedDebounced {
@@ -615,6 +616,7 @@ impl Project {
                     local_handles: Vec::new(),
                 },
                 copilot_enabled: Copilot::global(cx).is_some(),
+                current_lsp_settings: settings::get::<ProjectSettings>(cx).lsp.clone(),
             }
         })
     }
@@ -707,6 +709,7 @@ impl Project {
                     local_handles: Vec::new(),
                 },
                 copilot_enabled: Copilot::global(cx).is_some(),
+                current_lsp_settings: settings::get::<ProjectSettings>(cx).lsp.clone(),
             };
             for worktree in worktrees {
                 let _ = this.add_worktree(&worktree, cx);
@@ -780,7 +783,9 @@ impl Project {
         let mut language_servers_to_stop = Vec::new();
         let mut language_servers_to_restart = Vec::new();
         let languages = self.languages.to_vec();
-        let project_settings = settings::get::<ProjectSettings>(cx).clone();
+
+        let new_lsp_settings = settings::get::<ProjectSettings>(cx).lsp.clone();
+        let current_lsp_settings = &self.current_lsp_settings;
         for (worktree_id, started_lsp_name) in self.language_server_ids.keys() {
             let language = languages.iter().find_map(|l| {
                 let adapter = l
@@ -797,16 +802,25 @@ impl Project {
                 if !language_settings(Some(language), file.as_ref(), cx).enable_language_server {
                     language_servers_to_stop.push((*worktree_id, started_lsp_name.clone()));
                 } else if let Some(worktree) = worktree {
-                    let new_lsp_settings = project_settings
-                        .lsp
-                        .get(&adapter.name.0)
-                        .and_then(|s| s.initialization_options.as_ref());
-                    if adapter.update_initialization_overrides(new_lsp_settings) {
-                        language_servers_to_restart.push((worktree, Arc::clone(language)));
+                    let server_name = &adapter.name.0;
+                    match (
+                        current_lsp_settings.get(server_name),
+                        new_lsp_settings.get(server_name),
+                    ) {
+                        (None, None) => {}
+                        (Some(_), None) | (None, Some(_)) => {
+                            language_servers_to_restart.push((worktree, Arc::clone(language)));
+                        }
+                        (Some(current_lsp_settings), Some(new_lsp_settings)) => {
+                            if current_lsp_settings != new_lsp_settings {
+                                language_servers_to_restart.push((worktree, Arc::clone(language)));
+                            }
+                        }
                     }
                 }
             }
         }
+        self.current_lsp_settings = new_lsp_settings;
 
         // Stop all newly-disabled language servers.
         for (worktree_id, adapter_name) in language_servers_to_stop {
@@ -2546,13 +2560,20 @@ impl Project {
         let project_settings = settings::get::<ProjectSettings>(cx);
         let lsp = project_settings.lsp.get(&adapter.name.0);
         let override_options = lsp.map(|s| s.initialization_options.clone()).flatten();
-        adapter.update_initialization_overrides(override_options.as_ref());
+
+        let mut initialization_options = adapter.initialization_options.clone();
+        match (&mut initialization_options, override_options) {
+            (Some(initialization_options), Some(override_options)) => {
+                merge_json_value_into(override_options, initialization_options);
+            }
+            (None, override_options) => initialization_options = override_options,
+            _ => {}
+        }
 
         let server_id = pending_server.server_id;
         let container_dir = pending_server.container_dir.clone();
         let state = LanguageServerState::Starting({
             let adapter = adapter.clone();
-            let initialization_options = adapter.initialization_options();
             let server_name = adapter.name.0.clone();
             let languages = self.languages.clone();
             let language = language.clone();

crates/terminal_view/src/terminal_panel.rs 🔗

@@ -221,6 +221,14 @@ impl TerminalPanel {
             pane::Event::ZoomIn => cx.emit(Event::ZoomIn),
             pane::Event::ZoomOut => cx.emit(Event::ZoomOut),
             pane::Event::Focus => cx.emit(Event::Focus),
+
+            pane::Event::AddItem { item } => {
+                if let Some(workspace) = self.workspace.upgrade(cx) {
+                    let pane = self.pane.clone();
+                    workspace.update(cx, |workspace, cx| item.added_to_pane(workspace, pane, cx))
+                }
+            }
+
             _ => {}
         }
     }

crates/terminal_view/src/terminal_view.rs 🔗

@@ -275,7 +275,7 @@ impl TerminalView {
         cx.spawn(|this, mut cx| async move {
             Timer::after(CURSOR_BLINK_INTERVAL).await;
             this.update(&mut cx, |this, cx| this.resume_cursor_blinking(epoch, cx))
-                .log_err();
+                .ok();
         })
         .detach();
     }
@@ -907,6 +907,7 @@ mod tests {
         let params = cx.update(AppState::test);
         cx.update(|cx| {
             theme::init((), cx);
+            Project::init_settings(cx);
             language::init(cx);
         });
 

crates/workspace/src/item.rs 🔗

@@ -27,7 +27,7 @@ use std::{
 };
 use theme::Theme;
 
-#[derive(Eq, PartialEq, Hash)]
+#[derive(Eq, PartialEq, Hash, Debug)]
 pub enum ItemEvent {
     CloseItem,
     UpdateTab,

crates/workspace/src/pane.rs 🔗

@@ -2316,6 +2316,7 @@ mod tests {
             cx.set_global(SettingsStore::test(cx));
             theme::init((), cx);
             crate::init_settings(cx);
+            Project::init_settings(cx);
         });
     }