diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 5dab624a95..89eb2863fc 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4871,14 +4871,11 @@ impl Editor { } fn restart_language_server(&mut self, _: &RestartLanguageServer, cx: &mut ViewContext) { - let project = self.project.clone(); - if let Some(project) = project { + if let Some(project) = self.project.clone() { self.buffer.update(cx, |multi_buffer, cx| { - for buffer in multi_buffer.all_buffers() { - project.update(cx, |project, cx| { - project.restart_language_server_for_buffer(&buffer, cx); - }); - } + project.update(cx, |project, cx| { + project.restart_language_servers_for_buffers(multi_buffer.all_buffers(), cx); + }); }) } } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index c271477dd6..42982fd9c5 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1508,18 +1508,26 @@ impl Project { }); } - pub fn restart_language_server_for_buffer( + pub fn restart_language_servers_for_buffers( &mut self, - buffer: &ModelHandle, + buffers: impl IntoIterator>, cx: &mut ModelContext, ) -> Option<()> { - let file = File::from_dyn(buffer.read(cx).file())?; - let worktree = file.worktree.read(cx).as_local()?; - let worktree_id = worktree.id(); - let worktree_abs_path = worktree.abs_path().clone(); - let full_path = buffer.read(cx).file()?.full_path(cx); - let language = self.languages.select_language(&full_path)?; - self.restart_language_server(worktree_id, worktree_abs_path, language, cx); + let language_server_lookup_info: HashSet<(WorktreeId, Arc, PathBuf)> = buffers + .into_iter() + .filter_map(|buffer| { + let file = File::from_dyn(buffer.read(cx).file())?; + let worktree = file.worktree.read(cx).as_local()?; + let worktree_id = worktree.id(); + let worktree_abs_path = worktree.abs_path().clone(); + let full_path = file.full_path(cx); + Some((worktree_id, worktree_abs_path, full_path)) + }) + .collect(); + for (worktree_id, worktree_abs_path, full_path) in language_server_lookup_info { + let language = self.languages.select_language(&full_path)?; + self.restart_language_server(worktree_id, worktree_abs_path, language, cx); + } None } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index ccf52df672..17b0c4b518 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -80,7 +80,6 @@ action!(Save); action!(DebugElements); action!(ActivatePreviousPane); action!(ActivateNextPane); -action!(RestartLanguageServer); pub fn init(client: &Arc, cx: &mut MutableAppContext) { pane::init(cx); @@ -120,9 +119,6 @@ pub fn init(client: &Arc, cx: &mut MutableAppContext) { cx.add_action(|workspace: &mut Workspace, _: &ActivateNextPane, cx| { workspace.activate_next_pane(cx) }); - cx.add_action(|workspace: &mut Workspace, _: &RestartLanguageServer, cx| { - workspace.restart_language_server(cx) - }); cx.add_bindings(vec![ Binding::new("ctrl-alt-cmd-f", FollowNextCollaborator, None), Binding::new("cmd-s", Save, None), @@ -1423,8 +1419,6 @@ impl Workspace { None } - fn restart_language_server(&mut self, cx: &mut ViewContext) {} - fn render_connection_status(&self, cx: &mut RenderContext) -> Option { let theme = &cx.global::().theme; match &*self.client.status().borrow() {