mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(lsp): remove duplicate cwd in config path (#10620)
This commit is contained in:
parent
62c752211c
commit
608c7d68e2
2 changed files with 20 additions and 5 deletions
|
@ -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,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!({
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue