From 608c7d68e26abbc685f97901e6bfa3be910eec10 Mon Sep 17 00:00:00 2001 From: Niclas Overby Date: Thu, 13 May 2021 23:56:30 +0200 Subject: fix(lsp): remove duplicate cwd in config path (#10620) --- cli/config_file.rs | 23 +++++++++++++++++++---- cli/lsp/language_server.rs | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'cli') diff --git a/cli/config_file.rs b/cli/config_file.rs index fcc702ad5..41d9bbbec 100644 --- a/cli/config_file.rs +++ b/cli/config_file.rs @@ -270,9 +270,14 @@ pub struct ConfigFile { } impl ConfigFile { - pub fn read(path: &str) -> Result { - let cwd = std::env::current_dir()?; - let config_file = cwd.join(path); + pub fn read(path_str: &str) -> Result { + let path = Path::new(path_str); + let config_file = if path.is_absolute() { + path.to_path_buf() + } else { + std::env::current_dir()?.join(path_str) + }; + let config_path = canonicalize_path(&config_file).map_err(|_| { std::io::Error::new( std::io::ErrorKind::InvalidInput, @@ -318,12 +323,22 @@ mod tests { use deno_core::serde_json::json; #[test] - fn read_config_file() { + fn read_config_file_relative() { let config_file = ConfigFile::read("tests/module_graph/tsconfig.json") .expect("Failed to load config file"); assert!(config_file.json.compiler_options.is_some()); } + #[test] + fn read_config_file_absolute() { + let path = std::env::current_dir() + .unwrap() + .join("tests/module_graph/tsconfig.json"); + let config_file = ConfigFile::read(path.to_str().unwrap()) + .expect("Failed to load config file"); + assert!(config_file.json.compiler_options.is_some()); + } + #[test] fn test_json_merge() { let mut value_a = json!({ diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 2f090938c..2de0ef394 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -431,7 +431,7 @@ impl Inner { )) }?; - let config_file = ConfigFile::read(config_url.as_str()) + let config_file = ConfigFile::read(config_url.path()) .context("Failed to load configuration file")?; let (value, maybe_ignored_options) = config_file.as_compiler_options()?; tsconfig.merge(&value); -- cgit v1.2.3