From aa539fc347b746d4d8c365b0b27c97fddf638ecf Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 22 May 2024 16:32:06 +0200 Subject: [PATCH] lsp: Fix wrong WorkspaceFolder when opening only file (#12129) This fixes #11361 and #8764 by making sure we pass a directory as `WorkspaceFolder` to the language server. We already compute the `working_dir` correctly when `self.root_path.is_file()`, but we didn't use it. Release Notes: - Fixed language servers (such as `gopls`) not starting up correctly when opening a single file in Zed. ([#11361](https://github.com/zed-industries/zed/issues/11361) and [#8764](https://github.com/zed-industries/zed/issues/8764)). --- crates/lsp/src/lsp.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index ce90a5c068..2d789b976b 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -79,6 +79,7 @@ pub struct LanguageServer { io_tasks: Mutex>, Task>)>>, output_done_rx: Mutex>, root_path: PathBuf, + working_dir: PathBuf, server: Arc>>, } @@ -288,6 +289,7 @@ impl LanguageServer { stderr_capture, Some(server), root_path, + working_dir, code_action_kinds, cx, move |notification| { @@ -322,6 +324,7 @@ impl LanguageServer { stderr_capture: Arc>>, server: Option, root_path: &Path, + working_dir: &Path, code_action_kinds: Option>, cx: AsyncAppContext, on_unhandled_notification: F, @@ -393,6 +396,7 @@ impl LanguageServer { io_tasks: Mutex::new(Some((input_task, output_task))), output_done_rx: Mutex::new(Some(output_done_rx)), root_path: root_path.to_path_buf(), + working_dir: working_dir.to_path_buf(), server: Arc::new(Mutex::new(server)), } } @@ -566,7 +570,7 @@ impl LanguageServer { options: Option, cx: &AppContext, ) -> Task>> { - let root_uri = Url::from_file_path(&self.root_path).unwrap(); + let root_uri = Url::from_file_path(&self.working_dir).unwrap(); #[allow(deprecated)] let params = InitializeParams { process_id: None, @@ -1171,6 +1175,7 @@ impl FakeLanguageServer { Arc::new(Mutex::new(None)), None, Path::new("/"), + Path::new("/"), None, cx.clone(), |_| {}, @@ -1187,6 +1192,7 @@ impl FakeLanguageServer { Arc::new(Mutex::new(None)), None, Path::new("/"), + Path::new("/"), None, cx, move |msg| {