Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
lsp: Update root_path for compatibility with language servers (#48587)
Shaz Ravenswood641c58d04ced
diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rsindex e211eb1d444..e2ad995b0f9 100644--- a/crates/lsp/src/lsp.rs+++ b/crates/lsp/src/lsp.rs@@ -738,7 +738,12 @@ impl LanguageServer {#[allow(deprecated)]InitializeParams {process_id: Some(std::process::id()),- root_path: None,+ root_path: Some(+ self.root_uri+ .to_file_path()+ .map(|path| path.to_string_lossy().into_owned())+ .unwrap_or_else(|_| self.root_uri.path().to_string()),+ ),root_uri: Some(self.root_uri.clone()),initialization_options: None,capabilities: ClientCapabilities {@@ -2104,4 +2109,38 @@ mod tests {"{\"jsonrpc\":\"\",\"id\":0,\"error\":null}");}++ #[gpui::test]+ async fn test_initialize_params_has_root_path_and_root_uri(cx: &mut TestAppContext) {+ cx.update(|cx| {+ release_channel::init(semver::Version::new(0, 0, 0), cx);+ });+ let (server, _fake) = FakeLanguageServer::new(+ LanguageServerId(0),+ LanguageServerBinary {+ path: "path/to/language-server".into(),+ arguments: vec![],+ env: None,+ },+ "test-lsp".to_string(),+ Default::default(),+ &mut cx.to_async(),+ );++ let params = cx.update(|cx| server.default_initialize_params(false, false, cx));++ #[allow(deprecated)]+ let root_uri = params.root_uri.expect("root_uri should be set");+ #[allow(deprecated)]+ let root_path = params.root_path.expect("root_path should be set");++ let expected_path = root_uri+ .to_file_path()+ .expect("root_uri should be a valid file path");+ assert_eq!(+ root_path,+ expected_path.to_string_lossy(),+ "root_path should be derived from root_uri"+ );+ }}