From ce48b32979b007c35130321ed0f91d8ffdb6d593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 10 May 2021 18:16:39 +0200 Subject: 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. --- cli/lsp/config.rs | 2 +- cli/lsp/language_server.rs | 24 +++++++----------------- cli/lsp/tsc.rs | 2 +- 3 files changed, 9 insertions(+), 19 deletions(-) (limited to 'cli/lsp') diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index 7aca52a9b..8cf4a67ef 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -102,7 +102,7 @@ pub struct WorkspaceSettings { /// A flag that indicates if Deno is enabled for the workspace. pub enable: bool, - /// An option that points to a path string of the tsconfig file to apply to + /// An option that points to a path string of the config file to apply to /// code within the workspace. pub config: Option, 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 { diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 869a61838..d5cedfd51 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -11,11 +11,11 @@ use super::semantic_tokens::TsTokenEncodingConsts; use super::text; use super::text::LineIndex; +use crate::config_file::TsConfig; use crate::media_type::MediaType; use crate::tokio_util::create_basic_runtime; use crate::tsc; use crate::tsc::ResolveArgs; -use crate::tsc_config::TsConfig; use deno_core::error::anyhow; use deno_core::error::custom_error; -- cgit v1.2.3