summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiclas Overby <niclas@overby.me>2021-05-13 23:56:30 +0200
committerGitHub <noreply@github.com>2021-05-13 23:56:30 +0200
commit608c7d68e26abbc685f97901e6bfa3be910eec10 (patch)
tree6af4d268c7e7fd94d47a0a1fb7498527de41e6c3
parent62c752211c982ee6eb297cf49a076464471407f7 (diff)
fix(lsp): remove duplicate cwd in config path (#10620)
-rw-r--r--cli/config_file.rs23
-rw-r--r--cli/lsp/language_server.rs2
2 files changed, 20 insertions, 5 deletions
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<Self, AnyError> {
- let cwd = std::env::current_dir()?;
- let config_file = cwd.join(path);
+ pub fn read(path_str: &str) -> Result<Self, AnyError> {
+ 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,13 +323,23 @@ 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!({
"a": true,
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);