From 8cc9a9350b8a8c8fb883a93fc78471ccdd545481 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 5 Feb 2022 17:41:15 -0500 Subject: [PATCH] fix(lsp): do not panic getting root_uri to auto discover configuration file (#13603) --- cli/lsp/language_server.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 1d91a4b37a..bf7be3ea79 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -309,14 +309,13 @@ impl Inner { /// If there's no config file specified in settings returns `None`. fn get_config_file(&self) -> Result, AnyError> { let workspace_settings = self.config.get_workspace_settings(); - let maybe_root_uri = self.root_uri.clone(); let maybe_config = workspace_settings.config; if let Some(config_str) = &maybe_config { if !config_str.is_empty() { lsp_log!("Setting TypeScript configuration from: \"{}\"", config_str); let config_url = if let Ok(url) = Url::from_file_path(config_str) { Ok(url) - } else if let Some(root_uri) = maybe_root_uri { + } else if let Some(root_uri) = &self.root_uri { root_uri.join(config_str).map_err(|_| { anyhow!("Bad file path for configuration file: \"{}\"", config_str) }) @@ -338,8 +337,8 @@ impl Inner { // It is possible that root_uri is not set, for example when having a single // file open and not a workspace. In those situations we can't // automatically discover the configuration - if let Some(root_uri) = maybe_root_uri { - let root_path = root_uri.to_file_path().unwrap(); + if let Some(root_uri) = &self.root_uri { + let root_path = fs_util::specifier_to_file_path(root_uri)?; let mut checked = std::collections::HashSet::new(); let maybe_config = crate::config_file::discover_from(&root_path, &mut checked)?;