diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-05-10 18:16:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-10 18:16:39 +0200 |
commit | ce48b32979b007c35130321ed0f91d8ffdb6d593 (patch) | |
tree | 6cab6a1349fb9541eac0324efbfc563625d5e656 /cli/lsp/language_server.rs | |
parent | 7fc211e62752dddd4f70f8feef24dbcea795c1eb (diff) |
refactor(cli): replace loading file for --config flag with generic structure (#10481)
Currently file passed to --config file is parsed using TsConfig structure
that does multiple things when loading the file. Instead of relying on that
structure I've introduced ConfigFile structure that can be updated to
sniff out more fields from the config file in the future.
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r-- | cli/lsp/language_server.rs | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 2fbc41b03..c14617e5a 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -2,6 +2,7 @@ use deno_core::error::anyhow; use deno_core::error::AnyError; +use deno_core::error::Context; use deno_core::resolve_url; use deno_core::serde::Deserialize; use deno_core::serde::Serialize; @@ -28,11 +29,11 @@ use std::rc::Rc; use std::sync::Arc; use tokio::fs; +use crate::config_file::ConfigFile; +use crate::config_file::TsConfig; use crate::deno_dir; use crate::import_map::ImportMap; use crate::media_type::MediaType; -use crate::tsc_config::parse_config; -use crate::tsc_config::TsConfig; use super::analysis; use super::analysis::ts_changes_to_edit; @@ -408,21 +409,10 @@ impl Inner { config_str )) }?; - let config_path = config_url - .to_file_path() - .map_err(|_| anyhow!("Bad file path."))?; - let config_text = - fs::read_to_string(config_path.clone()) - .await - .map_err(|err| { - anyhow!( - "Failed to load the configuration file at: {}. [{}]", - config_url, - err - ) - })?; - let (value, maybe_ignored_options) = - parse_config(&config_text, &config_path)?; + + let config_file = ConfigFile::read(config_url.as_str()) + .context("Failed to load configuration file")?; + let (value, maybe_ignored_options) = config_file.as_compiler_options()?; tsconfig.merge(&value); self.maybe_config_uri = Some(config_url); if let Some(ignored_options) = maybe_ignored_options { |